Commit a7c6ee0b authored by Robert Knight's avatar Robert Knight

Use Date.toLocaleString()'s options arg for more control over date formatting

A downside of using the browser intl APIs to avoid the overhead
of Moment.js is that the output is implementation dependent.

Use toLocaleString()'s options argument where supported
(Firefox, Chrome, Edge, IE 11) for more control over formatting
of dates in annotation last-updated tooltips.

Safari is the only modern browser currently lacking support
for this option. For Safari, use toDateString() and toLocaleDateString()
which generates the most similar format.
parent a07d0f77
var DATE_SUPPORTS_LOCALE_OPTS = (function () {
try {
// see http://mzl.la/1YlJJpQ
(new Date).toLocaleDateString('i');
} catch (e) {
if (e instanceof RangeError) {
return true;
}
}
return false;
})();
/**
* Returns a standard human-readable representation
* of a date and time.
*/
function format(date) {
if (DATE_SUPPORTS_LOCALE_OPTS) {
return date.toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: '2-digit',
weekday: 'long',
hour: '2-digit',
minute: '2-digit',
});
} else {
// IE < 11, Safari <= 9.0.
// In English, this generates the string most similar to
// the toLocaleDateString() result above.
return date.toDateString() + ' ' + date.toLocaleTimeString();
}
}
module.exports = {
format: format,
};
/* jshint node: true */
'use strict';
var dateUtil = require('../date-util');
var events = require('../events');
/** Return a domainModel tags array from the given vm tags array.
......@@ -744,7 +745,7 @@ function AnnotationController(
return '';
}
var date = new Date(domainModel.updated);
return date.toDateString() + ', ' + date.toLocaleTimeString();
return dateUtil.format(date);
}
vm.user = function() {
......
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