Commit fc4d0c15 authored by Sean Hammond's avatar Sean Hammond

Add fallback when Intl not defined

parent 9942a8a5
......@@ -99,6 +99,27 @@ describe('time', function () {
it('creates correct fuzzy string for fixture ' + i,
testFixture(f));
}
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.
window.Intl = undefined;
var d = new Date();
sandbox.clock.tick(day * 2 * 1000);
assert.equal(time.toFuzzyString(d), 'Thu Jan 01 1970');
});
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.
window.Intl = undefined;
var d = new Date();
sandbox.clock.tick(year * 2 * 1000);
assert.equal(time.toFuzzyString(d), 'Thu Jan 01 1970');
});
});
describe('.decayingInterval', function () {
......
......@@ -56,14 +56,20 @@ var formatters = {};
*
*/
function format(date, options) {
var key = JSON.stringify(options);
var formatter = formatters[key];
if (typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
var key = JSON.stringify(options);
var formatter = formatters[key];
if (!formatter) {
formatter = formatters[key] = new Intl.DateTimeFormat(undefined, options);
}
if (!formatter) {
formatter = formatters[key] = new Intl.DateTimeFormat(undefined,
options);
}
return formatter.format(date);
return formatter.format(date);
} else {
// IE < 11, Safari <= 9.0.
return date.toDateString();
}
}
function dayAndMonth(date) {
......
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