Commit a7865236 authored by Nick Stenning's avatar Nick Stenning

Merge pull request #2808 from hypothesis/remove-momentjs

Remove Moment.js
parents 8fb652d5 a7c6ee0b
......@@ -121,7 +121,6 @@ module.exports = angular.module('h', [
.directive('topBar', require('./directive/top-bar'))
.filter('converter', require('./filter/converter'))
.filter('moment', require('./filter/moment'))
.filter('persona', require('./filter/persona').filter)
.filter('urlencode', require('./filter/urlencode'))
.filter('documentTitle', require('./filter/document-title'))
......
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.
......@@ -739,6 +740,14 @@ function AnnotationController(
return domainModel.updated;
};
vm.updatedString = function () {
if (!domainModel.updated) {
return '';
}
var date = new Date(domainModel.updated);
return dateUtil.format(date);
}
vm.user = function() {
return domainModel.user;
};
......
......@@ -404,7 +404,8 @@ describe('annotation.js', function() {
},
target: [{}],
uri: 'http://example.com',
user: 'acct:bill@localhost'
user: 'acct:bill@localhost',
updated: '2015-05-10T20:18:56.613388+00:00',
};
}
......@@ -1104,6 +1105,18 @@ describe('annotation.js', function() {
});
});
describe('#updatedString()', function () {
it('returns the current time', function () {
var annotation = defaultAnnotation();
var controller = createDirective(annotation).controller;
var expectedDate = new Date(annotation.updated);
// the exact format of the result will depend on the current locale,
// but check that at least the current year and time are present
assert.match(controller.updatedString(), new RegExp('.*2015.*' +
expectedDate.toLocaleTimeString()));
});
});
describe('share', function() {
it('sets and unsets the open class on the share wrapper', function() {
var parts = createDirective();
......
var moment = require('moment');
module.exports = ['$window', function ($window) {
return function (value, format) {
return moment(value).format(format);
};
}];
......@@ -47,7 +47,7 @@
<!-- Timestamp -->
<a class="annotation-timestamp"
target="_blank"
title="{{vm.updated() | moment:'LLLL'}}"
title="{{vm.updatedString()}}"
ng-if="!vm.editing() && vm.updated()"
ng-href="{{vm.baseURI}}a/{{vm.id()}}"
>{{vm.timestamp}}</a>
......
......@@ -39,7 +39,6 @@
"is-equal-shallow": "^0.1.3",
"jquery": "1.11.1",
"js-polyfills": "^0.1.11",
"moment": "^2.10.6",
"ng-tags-input": "2.2.0",
"node-uuid": "^1.4.3",
"postcss": "^5.0.6",
......@@ -95,8 +94,7 @@
"annotator": "./h/static/scripts/vendor/annotator.js",
"angular": "./node_modules/angular/angular.js",
"hammerjs": "./node_modules/hammerjs/hammer.js",
"jquery": "./node_modules/jquery/dist/jquery.js",
"moment": "./node_modules/moment/min/moment-with-locales.js"
"jquery": "./node_modules/jquery/dist/jquery.js"
},
"browserify-shim": {
"annotator": {
......
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