Commit 94b08517 authored by Sean Hammond's avatar Sean Hammond

Fix a crash when rendering annotations

The dates passed in to toFuzzyString() and nextFuzzyUpdate() are
actually date strings and not (as in the tests) Date objects, but the
code expects Date objects, so it crashes in production (but works fine
in the tests).

Fix both the production code and the tests to use date strings.
parent 465511bc
......@@ -76,7 +76,7 @@ describe('time', function () {
var testFixture = function (f) {
return function () {
var t = new Date();
var t = new Date().toISOString();
var expect = f[1];
sandbox.clock.tick(f[0] * 1000);
assert.equal(time.toFuzzyString(t, mockIntl()), expect);
......@@ -92,7 +92,7 @@ describe('time', function () {
it('falls back to simple strings for >24hrs ago', function () {
// If window.Intl is not available then the date formatting for dates
// more than one day ago falls back to a simple date string.
var d = new Date();
var d = new Date().toISOString();
sandbox.clock.tick(day * 2 * 1000);
assert.equal(time.toFuzzyString(d, null), 'Thu Jan 01 1970');
......@@ -101,7 +101,7 @@ describe('time', function () {
it('falls back to simple strings for >1yr ago', function () {
// If window.Intl is not available then the date formatting for dates
// more than one year ago falls back to a simple date string.
var d = new Date();
var d = new Date().toISOString();
sandbox.clock.tick(year * 2 * 1000);
assert.equal(time.toFuzzyString(d, null), 'Thu Jan 01 1970');
......@@ -165,7 +165,7 @@ describe('time', function () {
var testFixture = function (f) {
return function () {
var t = new Date();
var t = new Date().toISOString();
var expect = f[1];
sandbox.clock.tick(f[0] * 1000);
assert.equal(time.nextFuzzyUpdate(t), expect);
......
......@@ -119,6 +119,10 @@ var BREAKPOINTS = [
];
function getBreakpoint(date, now) {
// Turn the given ISO 8601 string into a Date object.
date = new Date(date);
var breakpoint;
for (var i = 0; i < BREAKPOINTS.length; i++) {
breakpoint = BREAKPOINTS[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment