This is an AngularJs service that wraps Moment.js and removes Moment's ability to fall back to native Date parsing. Native Date parsing is often problematic because different browsers handle various nonstandard date strings differently. Here are a couple examples:
// This nearly-correct ISO 8601 string does not include
// a timezone specifier (usually a trailing 'Z' to indicate
// 'Zulu' or the UTC timezone). Chrome will parse this
// 'successfully' and will assume the UTC timezone. Firefox
// will do the same but will assume the local timezone.
// Passing the same string to Moment.js will fall back to
// the native Date parsing, and so will be just as inconsistent
// as the browser is. Passing this string to Moment-Strict
// will result in a parsing error in all browsers.
new Date('2015-01-01T00:00:00');
// Ambiguous whether this is mm/dd/yyyy or dd/mm/yyyy since
// different regions of the world have different
// conventions (I think Europe typically uses dd/mm/yyyy while
// America uses mm/dd/yyyy). The same browser (e.g. Chrome)
// may behave differently in different locales around the world.
new Date('01/01/2015');
-
Install via Bower:
bower install bower install https://github.com/lasp/moment-strict.git
-
Include
bower_components/moment-strict/moment-strict.js
in your build- Although they are not listed as bower dependencies, you will also need angular and moment included on the page before moment-strict.js
-
Add a dependency to your angular app for 'moment-strict'
-
Wherever you would normally use
moment(dateStr)
ormoment.utc(dateStr)
instead usemomentStrict(dateStr)
ormomentStrict.utc(dateStr)
.
Copyright 2018 Regents of the University of Colorado. All rights reserved.
Commercial use of this project is forbidden due to the terms set forth by Highstock.