3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
7 ;(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9 typeof define === 'function' && define.amd ? define(factory) :
10 global.moment = factory()
11 }(this, function () { 'use strict';
15 function utils_hooks__hooks () {
16 return hookCallback.apply(null, arguments);
19 // This is done to register the method called with moment()
20 // without creating circular dependencies.
21 function setHookCallback (callback) {
22 hookCallback = callback;
25 function isArray(input) {
26 return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
29 function isDate(input) {
30 return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
33 function map(arr, fn) {
35 for (i = 0; i < arr.length; ++i) {
36 res.push(fn(arr[i], i));
41 function hasOwnProp(a, b) {
42 return Object.prototype.hasOwnProperty.call(a, b);
45 function extend(a, b) {
47 if (hasOwnProp(b, i)) {
52 if (hasOwnProp(b, 'toString')) {
53 a.toString = b.toString;
56 if (hasOwnProp(b, 'valueOf')) {
57 a.valueOf = b.valueOf;
63 function create_utc__createUTC (input, format, locale, strict) {
64 return createLocalOrUTC(input, format, locale, strict, true).utc();
67 function defaultParsingFlags() {
68 // We need to deep clone this object.
77 invalidFormat : false,
78 userInvalidated : false,
85 function getParsingFlags(m) {
87 m._pf = defaultParsingFlags();
93 if (Array.prototype.some) {
94 some = Array.prototype.some;
96 some = function (fun) {
98 var len = t.length >>> 0;
100 for (var i = 0; i < len; i++) {
101 if (i in t && fun.call(this, t[i], i, t)) {
110 function valid__isValid(m) {
111 if (m._isValid == null) {
112 var flags = getParsingFlags(m);
113 var parsedParts = some.call(flags.parsedDateParts, function (i) {
116 m._isValid = !isNaN(m._d.getTime()) &&
117 flags.overflow < 0 &&
119 !flags.invalidMonth &&
120 !flags.invalidWeekday &&
122 !flags.invalidFormat &&
123 !flags.userInvalidated &&
124 (!flags.meridiem || (flags.meridiem && parsedParts));
127 m._isValid = m._isValid &&
128 flags.charsLeftOver === 0 &&
129 flags.unusedTokens.length === 0 &&
130 flags.bigHour === undefined;
136 function valid__createInvalid (flags) {
137 var m = create_utc__createUTC(NaN);
139 extend(getParsingFlags(m), flags);
142 getParsingFlags(m).userInvalidated = true;
148 function isUndefined(input) {
149 return input === void 0;
152 // Plugins that add properties should also add the key here (null value),
153 // so we can properly clone ourselves.
154 var momentProperties = utils_hooks__hooks.momentProperties = [];
156 function copyConfig(to, from) {
159 if (!isUndefined(from._isAMomentObject)) {
160 to._isAMomentObject = from._isAMomentObject;
162 if (!isUndefined(from._i)) {
165 if (!isUndefined(from._f)) {
168 if (!isUndefined(from._l)) {
171 if (!isUndefined(from._strict)) {
172 to._strict = from._strict;
174 if (!isUndefined(from._tzm)) {
177 if (!isUndefined(from._isUTC)) {
178 to._isUTC = from._isUTC;
180 if (!isUndefined(from._offset)) {
181 to._offset = from._offset;
183 if (!isUndefined(from._pf)) {
184 to._pf = getParsingFlags(from);
186 if (!isUndefined(from._locale)) {
187 to._locale = from._locale;
190 if (momentProperties.length > 0) {
191 for (i in momentProperties) {
192 prop = momentProperties[i];
194 if (!isUndefined(val)) {
203 var updateInProgress = false;
205 // Moment prototype object
206 function Moment(config) {
207 copyConfig(this, config);
208 this._d = new Date(config._d != null ? config._d.getTime() : NaN);
209 // Prevent infinite loop in case updateOffset creates new moment
211 if (updateInProgress === false) {
212 updateInProgress = true;
213 utils_hooks__hooks.updateOffset(this);
214 updateInProgress = false;
218 function isMoment (obj) {
219 return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
222 function absFloor (number) {
224 return Math.ceil(number);
226 return Math.floor(number);
230 function toInt(argumentForCoercion) {
231 var coercedNumber = +argumentForCoercion,
234 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
235 value = absFloor(coercedNumber);
241 // compare two arrays, return the number of differences
242 function compareArrays(array1, array2, dontConvert) {
243 var len = Math.min(array1.length, array2.length),
244 lengthDiff = Math.abs(array1.length - array2.length),
247 for (i = 0; i < len; i++) {
248 if ((dontConvert && array1[i] !== array2[i]) ||
249 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
253 return diffs + lengthDiff;
257 if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
258 (typeof console !== 'undefined') && console.warn) {
259 console.warn('Deprecation warning: ' + msg);
263 function deprecate(msg, fn) {
264 var firstTime = true;
266 return extend(function () {
267 if (utils_hooks__hooks.deprecationHandler != null) {
268 utils_hooks__hooks.deprecationHandler(null, msg);
271 warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
274 return fn.apply(this, arguments);
278 var deprecations = {};
280 function deprecateSimple(name, msg) {
281 if (utils_hooks__hooks.deprecationHandler != null) {
282 utils_hooks__hooks.deprecationHandler(name, msg);
284 if (!deprecations[name]) {
286 deprecations[name] = true;
290 utils_hooks__hooks.suppressDeprecationWarnings = false;
291 utils_hooks__hooks.deprecationHandler = null;
293 function isFunction(input) {
294 return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
297 function isObject(input) {
298 return Object.prototype.toString.call(input) === '[object Object]';
301 function locale_set__set (config) {
305 if (isFunction(prop)) {
308 this['_' + i] = prop;
311 this._config = config;
312 // Lenient ordinal parsing accepts just a number in addition to
313 // number + (possibly) stuff coming from _ordinalParseLenient.
314 this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
317 function mergeConfigs(parentConfig, childConfig) {
318 var res = extend({}, parentConfig), prop;
319 for (prop in childConfig) {
320 if (hasOwnProp(childConfig, prop)) {
321 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
323 extend(res[prop], parentConfig[prop]);
324 extend(res[prop], childConfig[prop]);
325 } else if (childConfig[prop] != null) {
326 res[prop] = childConfig[prop];
335 function Locale(config) {
336 if (config != null) {
346 keys = function (obj) {
349 if (hasOwnProp(obj, i)) {
357 // internal storage for locale config files
361 function normalizeLocale(key) {
362 return key ? key.toLowerCase().replace('_', '-') : key;
365 // pick the locale from the array
366 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
367 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
368 function chooseLocale(names) {
369 var i = 0, j, next, locale, split;
371 while (i < names.length) {
372 split = normalizeLocale(names[i]).split('-');
374 next = normalizeLocale(names[i + 1]);
375 next = next ? next.split('-') : null;
377 locale = loadLocale(split.slice(0, j).join('-'));
381 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
382 //the next array item is better than a shallower substring of this one
392 function loadLocale(name) {
393 var oldLocale = null;
394 // TODO: Find a better way to register and load all the locales in Node
395 if (!locales[name] && (typeof module !== 'undefined') &&
396 module && module.exports) {
398 oldLocale = globalLocale._abbr;
399 require('./locale/' + name);
400 // because defineLocale currently also sets the global locale, we
401 // want to undo that for lazy loaded locales
402 locale_locales__getSetGlobalLocale(oldLocale);
405 return locales[name];
408 // This function will load locale and then set the global locale. If
409 // no arguments are passed in, it will simply return the current global
411 function locale_locales__getSetGlobalLocale (key, values) {
414 if (isUndefined(values)) {
415 data = locale_locales__getLocale(key);
418 data = defineLocale(key, values);
422 // moment.duration._locale = moment._locale = data;
427 return globalLocale._abbr;
430 function defineLocale (name, config) {
431 if (config !== null) {
433 if (locales[name] != null) {
434 deprecateSimple('defineLocaleOverride',
435 'use moment.updateLocale(localeName, config) to change ' +
436 'an existing locale. moment.defineLocale(localeName, ' +
437 'config) should only be used for creating a new locale');
438 config = mergeConfigs(locales[name]._config, config);
439 } else if (config.parentLocale != null) {
440 if (locales[config.parentLocale] != null) {
441 config = mergeConfigs(locales[config.parentLocale]._config, config);
443 // treat as if there is no base config
444 deprecateSimple('parentLocaleUndefined',
445 'specified parentLocale is not defined yet');
448 locales[name] = new Locale(config);
450 // backwards compat for now: also set the locale
451 locale_locales__getSetGlobalLocale(name);
453 return locales[name];
455 // useful for testing
456 delete locales[name];
461 function updateLocale(name, config) {
462 if (config != null) {
464 if (locales[name] != null) {
465 config = mergeConfigs(locales[name]._config, config);
467 locale = new Locale(config);
468 locale.parentLocale = locales[name];
469 locales[name] = locale;
471 // backwards compat for now: also set the locale
472 locale_locales__getSetGlobalLocale(name);
474 // pass null for config to unupdate, useful for tests
475 if (locales[name] != null) {
476 if (locales[name].parentLocale != null) {
477 locales[name] = locales[name].parentLocale;
478 } else if (locales[name] != null) {
479 delete locales[name];
483 return locales[name];
486 // returns locale data
487 function locale_locales__getLocale (key) {
490 if (key && key._locale && key._locale._abbr) {
491 key = key._locale._abbr;
499 //short-circuit everything else
500 locale = loadLocale(key);
507 return chooseLocale(key);
510 function locale_locales__listLocales() {
511 return keys(locales);
516 function addUnitAlias (unit, shorthand) {
517 var lowerCase = unit.toLowerCase();
518 aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
521 function normalizeUnits(units) {
522 return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
525 function normalizeObjectUnits(inputObject) {
526 var normalizedInput = {},
530 for (prop in inputObject) {
531 if (hasOwnProp(inputObject, prop)) {
532 normalizedProp = normalizeUnits(prop);
533 if (normalizedProp) {
534 normalizedInput[normalizedProp] = inputObject[prop];
539 return normalizedInput;
542 function makeGetSet (unit, keepTime) {
543 return function (value) {
545 get_set__set(this, unit, value);
546 utils_hooks__hooks.updateOffset(this, keepTime);
549 return get_set__get(this, unit);
554 function get_set__get (mom, unit) {
555 return mom.isValid() ?
556 mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
559 function get_set__set (mom, unit, value) {
561 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
567 function getSet (units, value) {
569 if (typeof units === 'object') {
570 for (unit in units) {
571 this.set(unit, units[unit]);
574 units = normalizeUnits(units);
575 if (isFunction(this[units])) {
576 return this[units](value);
582 function zeroFill(number, targetLength, forceSign) {
583 var absNumber = '' + Math.abs(number),
584 zerosToFill = targetLength - absNumber.length,
586 return (sign ? (forceSign ? '+' : '') : '-') +
587 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
590 var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
592 var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
594 var formatFunctions = {};
596 var formatTokenFunctions = {};
601 // callback: function () { this.month() + 1 }
602 function addFormatToken (token, padded, ordinal, callback) {
604 if (typeof callback === 'string') {
606 return this[callback]();
610 formatTokenFunctions[token] = func;
613 formatTokenFunctions[padded[0]] = function () {
614 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
618 formatTokenFunctions[ordinal] = function () {
619 return this.localeData().ordinal(func.apply(this, arguments), token);
624 function removeFormattingTokens(input) {
625 if (input.match(/\[[\s\S]/)) {
626 return input.replace(/^\[|\]$/g, '');
628 return input.replace(/\\/g, '');
631 function makeFormatFunction(format) {
632 var array = format.match(formattingTokens), i, length;
634 for (i = 0, length = array.length; i < length; i++) {
635 if (formatTokenFunctions[array[i]]) {
636 array[i] = formatTokenFunctions[array[i]];
638 array[i] = removeFormattingTokens(array[i]);
642 return function (mom) {
644 for (i = 0; i < length; i++) {
645 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
651 // format date using native date object
652 function formatMoment(m, format) {
654 return m.localeData().invalidDate();
657 format = expandFormat(format, m.localeData());
658 formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
660 return formatFunctions[format](m);
663 function expandFormat(format, locale) {
666 function replaceLongDateFormatTokens(input) {
667 return locale.longDateFormat(input) || input;
670 localFormattingTokens.lastIndex = 0;
671 while (i >= 0 && localFormattingTokens.test(format)) {
672 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
673 localFormattingTokens.lastIndex = 0;
680 var match1 = /\d/; // 0 - 9
681 var match2 = /\d\d/; // 00 - 99
682 var match3 = /\d{3}/; // 000 - 999
683 var match4 = /\d{4}/; // 0000 - 9999
684 var match6 = /[+-]?\d{6}/; // -999999 - 999999
685 var match1to2 = /\d\d?/; // 0 - 99
686 var match3to4 = /\d\d\d\d?/; // 999 - 9999
687 var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
688 var match1to3 = /\d{1,3}/; // 0 - 999
689 var match1to4 = /\d{1,4}/; // 0 - 9999
690 var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
692 var matchUnsigned = /\d+/; // 0 - inf
693 var matchSigned = /[+-]?\d+/; // -inf - inf
695 var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
696 var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
698 var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
700 // any word (or two) characters or numbers including two/three word month in arabic.
701 // includes scottish gaelic two word and hyphenated months
702 var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
707 function addRegexToken (token, regex, strictRegex) {
708 regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
709 return (isStrict && strictRegex) ? strictRegex : regex;
713 function getParseRegexForToken (token, config) {
714 if (!hasOwnProp(regexes, token)) {
715 return new RegExp(unescapeFormat(token));
718 return regexes[token](config._strict, config._locale);
721 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
722 function unescapeFormat(s) {
723 return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
724 return p1 || p2 || p3 || p4;
728 function regexEscape(s) {
729 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
734 function addParseToken (token, callback) {
735 var i, func = callback;
736 if (typeof token === 'string') {
739 if (typeof callback === 'number') {
740 func = function (input, array) {
741 array[callback] = toInt(input);
744 for (i = 0; i < token.length; i++) {
745 tokens[token[i]] = func;
749 function addWeekParseToken (token, callback) {
750 addParseToken(token, function (input, array, config, token) {
751 config._w = config._w || {};
752 callback(input, config._w, config, token);
756 function addTimeToArrayFromToken(token, input, config) {
757 if (input != null && hasOwnProp(tokens, token)) {
758 tokens[token](input, config._a, config, token);
774 if (Array.prototype.indexOf) {
775 indexOf = Array.prototype.indexOf;
777 indexOf = function (o) {
780 for (i = 0; i < this.length; ++i) {
789 function daysInMonth(year, month) {
790 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
795 addFormatToken('M', ['MM', 2], 'Mo', function () {
796 return this.month() + 1;
799 addFormatToken('MMM', 0, 0, function (format) {
800 return this.localeData().monthsShort(this, format);
803 addFormatToken('MMMM', 0, 0, function (format) {
804 return this.localeData().months(this, format);
809 addUnitAlias('month', 'M');
813 addRegexToken('M', match1to2);
814 addRegexToken('MM', match1to2, match2);
815 addRegexToken('MMM', function (isStrict, locale) {
816 return locale.monthsShortRegex(isStrict);
818 addRegexToken('MMMM', function (isStrict, locale) {
819 return locale.monthsRegex(isStrict);
822 addParseToken(['M', 'MM'], function (input, array) {
823 array[MONTH] = toInt(input) - 1;
826 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
827 var month = config._locale.monthsParse(input, token, config._strict);
828 // if we didn't find a month name, mark the date as invalid.
830 array[MONTH] = month;
832 getParsingFlags(config).invalidMonth = input;
838 var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
839 var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
840 function localeMonths (m, format) {
841 return isArray(this._months) ? this._months[m.month()] :
842 this._months[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
845 var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
846 function localeMonthsShort (m, format) {
847 return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
848 this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
851 function units_month__handleStrictParse(monthName, format, strict) {
852 var i, ii, mom, llc = monthName.toLocaleLowerCase();
853 if (!this._monthsParse) {
855 this._monthsParse = [];
856 this._longMonthsParse = [];
857 this._shortMonthsParse = [];
858 for (i = 0; i < 12; ++i) {
859 mom = create_utc__createUTC([2000, i]);
860 this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
861 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
866 if (format === 'MMM') {
867 ii = indexOf.call(this._shortMonthsParse, llc);
868 return ii !== -1 ? ii : null;
870 ii = indexOf.call(this._longMonthsParse, llc);
871 return ii !== -1 ? ii : null;
874 if (format === 'MMM') {
875 ii = indexOf.call(this._shortMonthsParse, llc);
879 ii = indexOf.call(this._longMonthsParse, llc);
880 return ii !== -1 ? ii : null;
882 ii = indexOf.call(this._longMonthsParse, llc);
886 ii = indexOf.call(this._shortMonthsParse, llc);
887 return ii !== -1 ? ii : null;
892 function localeMonthsParse (monthName, format, strict) {
895 if (this._monthsParseExact) {
896 return units_month__handleStrictParse.call(this, monthName, format, strict);
899 if (!this._monthsParse) {
900 this._monthsParse = [];
901 this._longMonthsParse = [];
902 this._shortMonthsParse = [];
906 // Sorting makes sure if one month (or abbr) is a prefix of another
907 // see sorting in computeMonthsParse
908 for (i = 0; i < 12; i++) {
909 // make the regex if we don't have it already
910 mom = create_utc__createUTC([2000, i]);
911 if (strict && !this._longMonthsParse[i]) {
912 this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
913 this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
915 if (!strict && !this._monthsParse[i]) {
916 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
917 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
920 if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
922 } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
924 } else if (!strict && this._monthsParse[i].test(monthName)) {
932 function setMonth (mom, value) {
935 if (!mom.isValid()) {
940 if (typeof value === 'string') {
941 if (/^\d+$/.test(value)) {
942 value = toInt(value);
944 value = mom.localeData().monthsParse(value);
945 // TODO: Another silent failure?
946 if (typeof value !== 'number') {
952 dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
953 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
957 function getSetMonth (value) {
959 setMonth(this, value);
960 utils_hooks__hooks.updateOffset(this, true);
963 return get_set__get(this, 'Month');
967 function getDaysInMonth () {
968 return daysInMonth(this.year(), this.month());
971 var defaultMonthsShortRegex = matchWord;
972 function monthsShortRegex (isStrict) {
973 if (this._monthsParseExact) {
974 if (!hasOwnProp(this, '_monthsRegex')) {
975 computeMonthsParse.call(this);
978 return this._monthsShortStrictRegex;
980 return this._monthsShortRegex;
983 return this._monthsShortStrictRegex && isStrict ?
984 this._monthsShortStrictRegex : this._monthsShortRegex;
988 var defaultMonthsRegex = matchWord;
989 function monthsRegex (isStrict) {
990 if (this._monthsParseExact) {
991 if (!hasOwnProp(this, '_monthsRegex')) {
992 computeMonthsParse.call(this);
995 return this._monthsStrictRegex;
997 return this._monthsRegex;
1000 return this._monthsStrictRegex && isStrict ?
1001 this._monthsStrictRegex : this._monthsRegex;
1005 function computeMonthsParse () {
1006 function cmpLenRev(a, b) {
1007 return b.length - a.length;
1010 var shortPieces = [], longPieces = [], mixedPieces = [],
1012 for (i = 0; i < 12; i++) {
1013 // make the regex if we don't have it already
1014 mom = create_utc__createUTC([2000, i]);
1015 shortPieces.push(this.monthsShort(mom, ''));
1016 longPieces.push(this.months(mom, ''));
1017 mixedPieces.push(this.months(mom, ''));
1018 mixedPieces.push(this.monthsShort(mom, ''));
1020 // Sorting makes sure if one month (or abbr) is a prefix of another it
1021 // will match the longer piece.
1022 shortPieces.sort(cmpLenRev);
1023 longPieces.sort(cmpLenRev);
1024 mixedPieces.sort(cmpLenRev);
1025 for (i = 0; i < 12; i++) {
1026 shortPieces[i] = regexEscape(shortPieces[i]);
1027 longPieces[i] = regexEscape(longPieces[i]);
1028 mixedPieces[i] = regexEscape(mixedPieces[i]);
1031 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
1032 this._monthsShortRegex = this._monthsRegex;
1033 this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
1034 this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
1037 function checkOverflow (m) {
1041 if (a && getParsingFlags(m).overflow === -2) {
1043 a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
1044 a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
1045 a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
1046 a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
1047 a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
1048 a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
1051 if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
1054 if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
1057 if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
1061 getParsingFlags(m).overflow = overflow;
1068 // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
1069 var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
1070 var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
1072 var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
1075 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
1076 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
1077 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
1078 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
1079 ['YYYY-DDD', /\d{4}-\d{3}/],
1080 ['YYYY-MM', /\d{4}-\d\d/, false],
1081 ['YYYYYYMMDD', /[+-]\d{10}/],
1082 ['YYYYMMDD', /\d{8}/],
1083 // YYYYMM is NOT allowed by the standard
1084 ['GGGG[W]WWE', /\d{4}W\d{3}/],
1085 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
1086 ['YYYYDDD', /\d{7}/]
1089 // iso time formats and regexes
1091 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
1092 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
1093 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
1094 ['HH:mm', /\d\d:\d\d/],
1095 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
1096 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
1097 ['HHmmss', /\d\d\d\d\d\d/],
1098 ['HHmm', /\d\d\d\d/],
1102 var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
1104 // date from iso format
1105 function configFromISO(config) {
1108 match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
1109 allowTime, dateFormat, timeFormat, tzFormat;
1112 getParsingFlags(config).iso = true;
1114 for (i = 0, l = isoDates.length; i < l; i++) {
1115 if (isoDates[i][1].exec(match[1])) {
1116 dateFormat = isoDates[i][0];
1117 allowTime = isoDates[i][2] !== false;
1121 if (dateFormat == null) {
1122 config._isValid = false;
1126 for (i = 0, l = isoTimes.length; i < l; i++) {
1127 if (isoTimes[i][1].exec(match[3])) {
1128 // match[2] should be 'T' or space
1129 timeFormat = (match[2] || ' ') + isoTimes[i][0];
1133 if (timeFormat == null) {
1134 config._isValid = false;
1138 if (!allowTime && timeFormat != null) {
1139 config._isValid = false;
1143 if (tzRegex.exec(match[4])) {
1146 config._isValid = false;
1150 config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
1151 configFromStringAndFormat(config);
1153 config._isValid = false;
1157 // date from iso format or fallback
1158 function configFromString(config) {
1159 var matched = aspNetJsonRegex.exec(config._i);
1161 if (matched !== null) {
1162 config._d = new Date(+matched[1]);
1166 configFromISO(config);
1167 if (config._isValid === false) {
1168 delete config._isValid;
1169 utils_hooks__hooks.createFromInputFallback(config);
1173 utils_hooks__hooks.createFromInputFallback = deprecate(
1174 'moment construction falls back to js Date. This is ' +
1175 'discouraged and will be removed in upcoming major ' +
1176 'release. Please refer to ' +
1177 'https://github.com/moment/moment/issues/1407 for more info.',
1179 config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
1183 function createDate (y, m, d, h, M, s, ms) {
1184 //can't just apply() to create a date:
1185 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
1186 var date = new Date(y, m, d, h, M, s, ms);
1188 //the date constructor remaps years 0-99 to 1900-1999
1189 if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
1190 date.setFullYear(y);
1195 function createUTCDate (y) {
1196 var date = new Date(Date.UTC.apply(null, arguments));
1198 //the Date.UTC function remaps years 0-99 to 1900-1999
1199 if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
1200 date.setUTCFullYear(y);
1207 addFormatToken('Y', 0, 0, function () {
1208 var y = this.year();
1209 return y <= 9999 ? '' + y : '+' + y;
1212 addFormatToken(0, ['YY', 2], 0, function () {
1213 return this.year() % 100;
1216 addFormatToken(0, ['YYYY', 4], 0, 'year');
1217 addFormatToken(0, ['YYYYY', 5], 0, 'year');
1218 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
1222 addUnitAlias('year', 'y');
1226 addRegexToken('Y', matchSigned);
1227 addRegexToken('YY', match1to2, match2);
1228 addRegexToken('YYYY', match1to4, match4);
1229 addRegexToken('YYYYY', match1to6, match6);
1230 addRegexToken('YYYYYY', match1to6, match6);
1232 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
1233 addParseToken('YYYY', function (input, array) {
1234 array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
1236 addParseToken('YY', function (input, array) {
1237 array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
1239 addParseToken('Y', function (input, array) {
1240 array[YEAR] = parseInt(input, 10);
1245 function daysInYear(year) {
1246 return isLeapYear(year) ? 366 : 365;
1249 function isLeapYear(year) {
1250 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
1255 utils_hooks__hooks.parseTwoDigitYear = function (input) {
1256 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
1261 var getSetYear = makeGetSet('FullYear', true);
1263 function getIsLeapYear () {
1264 return isLeapYear(this.year());
1267 // start-of-first-week - start-of-year
1268 function firstWeekOffset(year, dow, doy) {
1269 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1270 fwd = 7 + dow - doy,
1271 // first-week day local weekday -- which local weekday is fwd
1272 fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
1274 return -fwdlw + fwd - 1;
1277 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1278 function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
1279 var localWeekday = (7 + weekday - dow) % 7,
1280 weekOffset = firstWeekOffset(year, dow, doy),
1281 dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
1282 resYear, resDayOfYear;
1284 if (dayOfYear <= 0) {
1286 resDayOfYear = daysInYear(resYear) + dayOfYear;
1287 } else if (dayOfYear > daysInYear(year)) {
1289 resDayOfYear = dayOfYear - daysInYear(year);
1292 resDayOfYear = dayOfYear;
1297 dayOfYear: resDayOfYear
1301 function weekOfYear(mom, dow, doy) {
1302 var weekOffset = firstWeekOffset(mom.year(), dow, doy),
1303 week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
1307 resYear = mom.year() - 1;
1308 resWeek = week + weeksInYear(resYear, dow, doy);
1309 } else if (week > weeksInYear(mom.year(), dow, doy)) {
1310 resWeek = week - weeksInYear(mom.year(), dow, doy);
1311 resYear = mom.year() + 1;
1313 resYear = mom.year();
1323 function weeksInYear(year, dow, doy) {
1324 var weekOffset = firstWeekOffset(year, dow, doy),
1325 weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
1326 return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
1329 // Pick the first defined of two or three arguments.
1330 function defaults(a, b, c) {
1340 function currentDateArray(config) {
1341 // hooks is actually the exported moment object
1342 var nowValue = new Date(utils_hooks__hooks.now());
1343 if (config._useUTC) {
1344 return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
1346 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
1349 // convert an array to a date.
1350 // the array should mirror the parameters below
1351 // note: all values past the year are optional and will default to the lowest possible value.
1352 // [year, month, day , hour, minute, second, millisecond]
1353 function configFromArray (config) {
1354 var i, date, input = [], currentDate, yearToUse;
1360 currentDate = currentDateArray(config);
1362 //compute day of the year from weeks and weekdays
1363 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
1364 dayOfYearFromWeekInfo(config);
1367 //if the day of the year is set, figure out what it is
1368 if (config._dayOfYear) {
1369 yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
1371 if (config._dayOfYear > daysInYear(yearToUse)) {
1372 getParsingFlags(config)._overflowDayOfYear = true;
1375 date = createUTCDate(yearToUse, 0, config._dayOfYear);
1376 config._a[MONTH] = date.getUTCMonth();
1377 config._a[DATE] = date.getUTCDate();
1380 // Default to current date.
1381 // * if no year, month, day of month are given, default to today
1382 // * if day of month is given, default month and year
1383 // * if month is given, default only year
1384 // * if year is given, don't default anything
1385 for (i = 0; i < 3 && config._a[i] == null; ++i) {
1386 config._a[i] = input[i] = currentDate[i];
1389 // Zero out whatever was not defaulted, including time
1390 for (; i < 7; i++) {
1391 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
1394 // Check for 24:00:00.000
1395 if (config._a[HOUR] === 24 &&
1396 config._a[MINUTE] === 0 &&
1397 config._a[SECOND] === 0 &&
1398 config._a[MILLISECOND] === 0) {
1399 config._nextDay = true;
1400 config._a[HOUR] = 0;
1403 config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
1404 // Apply timezone offset from input. The actual utcOffset can be changed
1406 if (config._tzm != null) {
1407 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
1410 if (config._nextDay) {
1411 config._a[HOUR] = 24;
1415 function dayOfYearFromWeekInfo(config) {
1416 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
1419 if (w.GG != null || w.W != null || w.E != null) {
1423 // TODO: We need to take the current isoWeekYear, but that depends on
1424 // how we interpret now (local, utc, fixed offset). So create
1425 // a now version of current config (take local/utc/offset flags, and
1427 weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
1428 week = defaults(w.W, 1);
1429 weekday = defaults(w.E, 1);
1430 if (weekday < 1 || weekday > 7) {
1431 weekdayOverflow = true;
1434 dow = config._locale._week.dow;
1435 doy = config._locale._week.doy;
1437 weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
1438 week = defaults(w.w, 1);
1441 // weekday -- low day numbers are considered next week
1443 if (weekday < 0 || weekday > 6) {
1444 weekdayOverflow = true;
1446 } else if (w.e != null) {
1447 // local weekday -- counting starts from begining of week
1448 weekday = w.e + dow;
1449 if (w.e < 0 || w.e > 6) {
1450 weekdayOverflow = true;
1453 // default to begining of week
1457 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
1458 getParsingFlags(config)._overflowWeeks = true;
1459 } else if (weekdayOverflow != null) {
1460 getParsingFlags(config)._overflowWeekday = true;
1462 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
1463 config._a[YEAR] = temp.year;
1464 config._dayOfYear = temp.dayOfYear;
1468 // constant that refers to the ISO standard
1469 utils_hooks__hooks.ISO_8601 = function () {};
1471 // date from string and format string
1472 function configFromStringAndFormat(config) {
1473 // TODO: Move this to another part of the creation flow to prevent circular deps
1474 if (config._f === utils_hooks__hooks.ISO_8601) {
1475 configFromISO(config);
1480 getParsingFlags(config).empty = true;
1482 // This array is used to make a Date, either with `new Date` or `Date.UTC`
1483 var string = '' + config._i,
1484 i, parsedInput, tokens, token, skipped,
1485 stringLength = string.length,
1486 totalParsedInputLength = 0;
1488 tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
1490 for (i = 0; i < tokens.length; i++) {
1492 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
1493 // console.log('token', token, 'parsedInput', parsedInput,
1494 // 'regex', getParseRegexForToken(token, config));
1496 skipped = string.substr(0, string.indexOf(parsedInput));
1497 if (skipped.length > 0) {
1498 getParsingFlags(config).unusedInput.push(skipped);
1500 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
1501 totalParsedInputLength += parsedInput.length;
1503 // don't parse if it's not a known token
1504 if (formatTokenFunctions[token]) {
1506 getParsingFlags(config).empty = false;
1509 getParsingFlags(config).unusedTokens.push(token);
1511 addTimeToArrayFromToken(token, parsedInput, config);
1513 else if (config._strict && !parsedInput) {
1514 getParsingFlags(config).unusedTokens.push(token);
1518 // add remaining unparsed input length to the string
1519 getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
1520 if (string.length > 0) {
1521 getParsingFlags(config).unusedInput.push(string);
1524 // clear _12h flag if hour is <= 12
1525 if (getParsingFlags(config).bigHour === true &&
1526 config._a[HOUR] <= 12 &&
1527 config._a[HOUR] > 0) {
1528 getParsingFlags(config).bigHour = undefined;
1531 getParsingFlags(config).parsedDateParts = config._a.slice(0);
1532 getParsingFlags(config).meridiem = config._meridiem;
1534 config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
1536 configFromArray(config);
1537 checkOverflow(config);
1541 function meridiemFixWrap (locale, hour, meridiem) {
1544 if (meridiem == null) {
1548 if (locale.meridiemHour != null) {
1549 return locale.meridiemHour(hour, meridiem);
1550 } else if (locale.isPM != null) {
1552 isPm = locale.isPM(meridiem);
1553 if (isPm && hour < 12) {
1556 if (!isPm && hour === 12) {
1561 // this is not supposed to happen
1566 // date from string and array of format strings
1567 function configFromStringAndArray(config) {
1575 if (config._f.length === 0) {
1576 getParsingFlags(config).invalidFormat = true;
1577 config._d = new Date(NaN);
1581 for (i = 0; i < config._f.length; i++) {
1583 tempConfig = copyConfig({}, config);
1584 if (config._useUTC != null) {
1585 tempConfig._useUTC = config._useUTC;
1587 tempConfig._f = config._f[i];
1588 configFromStringAndFormat(tempConfig);
1590 if (!valid__isValid(tempConfig)) {
1594 // if there is any input that was not parsed add a penalty for that format
1595 currentScore += getParsingFlags(tempConfig).charsLeftOver;
1598 currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
1600 getParsingFlags(tempConfig).score = currentScore;
1602 if (scoreToBeat == null || currentScore < scoreToBeat) {
1603 scoreToBeat = currentScore;
1604 bestMoment = tempConfig;
1608 extend(config, bestMoment || tempConfig);
1611 function configFromObject(config) {
1616 var i = normalizeObjectUnits(config._i);
1617 config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
1618 return obj && parseInt(obj, 10);
1621 configFromArray(config);
1624 function createFromConfig (config) {
1625 var res = new Moment(checkOverflow(prepareConfig(config)));
1627 // Adding is smart enough around DST
1629 res._nextDay = undefined;
1635 function prepareConfig (config) {
1636 var input = config._i,
1639 config._locale = config._locale || locale_locales__getLocale(config._l);
1641 if (input === null || (format === undefined && input === '')) {
1642 return valid__createInvalid({nullInput: true});
1645 if (typeof input === 'string') {
1646 config._i = input = config._locale.preparse(input);
1649 if (isMoment(input)) {
1650 return new Moment(checkOverflow(input));
1651 } else if (isArray(format)) {
1652 configFromStringAndArray(config);
1653 } else if (format) {
1654 configFromStringAndFormat(config);
1655 } else if (isDate(input)) {
1658 configFromInput(config);
1661 if (!valid__isValid(config)) {
1668 function configFromInput(config) {
1669 var input = config._i;
1670 if (input === undefined) {
1671 config._d = new Date(utils_hooks__hooks.now());
1672 } else if (isDate(input)) {
1673 config._d = new Date(input.valueOf());
1674 } else if (typeof input === 'string') {
1675 configFromString(config);
1676 } else if (isArray(input)) {
1677 config._a = map(input.slice(0), function (obj) {
1678 return parseInt(obj, 10);
1680 configFromArray(config);
1681 } else if (typeof(input) === 'object') {
1682 configFromObject(config);
1683 } else if (typeof(input) === 'number') {
1684 // from milliseconds
1685 config._d = new Date(input);
1687 utils_hooks__hooks.createFromInputFallback(config);
1691 function createLocalOrUTC (input, format, locale, strict, isUTC) {
1694 if (typeof(locale) === 'boolean') {
1698 // object construction must be done this way.
1699 // https://github.com/moment/moment/issues/1423
1700 c._isAMomentObject = true;
1701 c._useUTC = c._isUTC = isUTC;
1707 return createFromConfig(c);
1710 function local__createLocal (input, format, locale, strict) {
1711 return createLocalOrUTC(input, format, locale, strict, false);
1714 var prototypeMin = deprecate(
1715 'moment().min is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
1717 var other = local__createLocal.apply(null, arguments);
1718 if (this.isValid() && other.isValid()) {
1719 return other < this ? this : other;
1721 return valid__createInvalid();
1726 var prototypeMax = deprecate(
1727 'moment().max is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
1729 var other = local__createLocal.apply(null, arguments);
1730 if (this.isValid() && other.isValid()) {
1731 return other > this ? this : other;
1733 return valid__createInvalid();
1738 // Pick a moment m from moments so that m[fn](other) is true for all
1739 // other. This relies on the function fn to be transitive.
1741 // moments should either be an array of moment objects or an array, whose
1742 // first element is an array of moment objects.
1743 function pickBy(fn, moments) {
1745 if (moments.length === 1 && isArray(moments[0])) {
1746 moments = moments[0];
1748 if (!moments.length) {
1749 return local__createLocal();
1752 for (i = 1; i < moments.length; ++i) {
1753 if (!moments[i].isValid() || moments[i][fn](res)) {
1760 // TODO: Use [].sort instead?
1762 var args = [].slice.call(arguments, 0);
1764 return pickBy('isBefore', args);
1768 var args = [].slice.call(arguments, 0);
1770 return pickBy('isAfter', args);
1773 var now = function () {
1774 return Date.now ? Date.now() : +(new Date());
1777 function Duration (duration) {
1778 var normalizedInput = normalizeObjectUnits(duration),
1779 years = normalizedInput.year || 0,
1780 quarters = normalizedInput.quarter || 0,
1781 months = normalizedInput.month || 0,
1782 weeks = normalizedInput.week || 0,
1783 days = normalizedInput.day || 0,
1784 hours = normalizedInput.hour || 0,
1785 minutes = normalizedInput.minute || 0,
1786 seconds = normalizedInput.second || 0,
1787 milliseconds = normalizedInput.millisecond || 0;
1789 // representation for dateAddRemove
1790 this._milliseconds = +milliseconds +
1791 seconds * 1e3 + // 1000
1792 minutes * 6e4 + // 1000 * 60
1793 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
1794 // Because of dateAddRemove treats 24 hours as different from a
1795 // day when working around DST, we need to store them separately
1796 this._days = +days +
1798 // It is impossible translate months into days without knowing
1799 // which months you are are talking about, so we have to store
1801 this._months = +months +
1807 this._locale = locale_locales__getLocale();
1812 function isDuration (obj) {
1813 return obj instanceof Duration;
1818 function offset (token, separator) {
1819 addFormatToken(token, 0, 0, function () {
1820 var offset = this.utcOffset();
1826 return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
1835 addRegexToken('Z', matchShortOffset);
1836 addRegexToken('ZZ', matchShortOffset);
1837 addParseToken(['Z', 'ZZ'], function (input, array, config) {
1838 config._useUTC = true;
1839 config._tzm = offsetFromString(matchShortOffset, input);
1845 // '+10:00' > ['10', '00']
1846 // '-1530' > ['-15', '30']
1847 var chunkOffset = /([\+\-]|\d\d)/gi;
1849 function offsetFromString(matcher, string) {
1850 var matches = ((string || '').match(matcher) || []);
1851 var chunk = matches[matches.length - 1] || [];
1852 var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
1853 var minutes = +(parts[1] * 60) + toInt(parts[2]);
1855 return parts[0] === '+' ? minutes : -minutes;
1858 // Return a moment from input, that is local/utc/zone equivalent to model.
1859 function cloneWithOffset(input, model) {
1862 res = model.clone();
1863 diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf();
1864 // Use low-level api, because this fn is low-level api.
1865 res._d.setTime(res._d.valueOf() + diff);
1866 utils_hooks__hooks.updateOffset(res, false);
1869 return local__createLocal(input).local();
1873 function getDateOffset (m) {
1874 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
1875 // https://github.com/moment/moment/pull/1871
1876 return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
1881 // This function will be called whenever a moment is mutated.
1882 // It is intended to keep the offset in sync with the timezone.
1883 utils_hooks__hooks.updateOffset = function () {};
1887 // keepLocalTime = true means only change the timezone, without
1888 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
1889 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
1890 // +0200, so we adjust the time as needed, to be valid.
1892 // Keeping the time actually adds/subtracts (one hour)
1893 // from the actual represented time. That is why we call updateOffset
1894 // a second time. In case it wants us to change the offset again
1895 // _changeInProgress == true case, then we have to adjust, because
1896 // there is no such time in the given timezone.
1897 function getSetOffset (input, keepLocalTime) {
1898 var offset = this._offset || 0,
1900 if (!this.isValid()) {
1901 return input != null ? this : NaN;
1903 if (input != null) {
1904 if (typeof input === 'string') {
1905 input = offsetFromString(matchShortOffset, input);
1906 } else if (Math.abs(input) < 16) {
1909 if (!this._isUTC && keepLocalTime) {
1910 localAdjust = getDateOffset(this);
1912 this._offset = input;
1914 if (localAdjust != null) {
1915 this.add(localAdjust, 'm');
1917 if (offset !== input) {
1918 if (!keepLocalTime || this._changeInProgress) {
1919 add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
1920 } else if (!this._changeInProgress) {
1921 this._changeInProgress = true;
1922 utils_hooks__hooks.updateOffset(this, true);
1923 this._changeInProgress = null;
1928 return this._isUTC ? offset : getDateOffset(this);
1932 function getSetZone (input, keepLocalTime) {
1933 if (input != null) {
1934 if (typeof input !== 'string') {
1938 this.utcOffset(input, keepLocalTime);
1942 return -this.utcOffset();
1946 function setOffsetToUTC (keepLocalTime) {
1947 return this.utcOffset(0, keepLocalTime);
1950 function setOffsetToLocal (keepLocalTime) {
1952 this.utcOffset(0, keepLocalTime);
1953 this._isUTC = false;
1955 if (keepLocalTime) {
1956 this.subtract(getDateOffset(this), 'm');
1962 function setOffsetToParsedOffset () {
1964 this.utcOffset(this._tzm);
1965 } else if (typeof this._i === 'string') {
1966 this.utcOffset(offsetFromString(matchOffset, this._i));
1971 function hasAlignedHourOffset (input) {
1972 if (!this.isValid()) {
1975 input = input ? local__createLocal(input).utcOffset() : 0;
1977 return (this.utcOffset() - input) % 60 === 0;
1980 function isDaylightSavingTime () {
1982 this.utcOffset() > this.clone().month(0).utcOffset() ||
1983 this.utcOffset() > this.clone().month(5).utcOffset()
1987 function isDaylightSavingTimeShifted () {
1988 if (!isUndefined(this._isDSTShifted)) {
1989 return this._isDSTShifted;
1994 copyConfig(c, this);
1995 c = prepareConfig(c);
1998 var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
1999 this._isDSTShifted = this.isValid() &&
2000 compareArrays(c._a, other.toArray()) > 0;
2002 this._isDSTShifted = false;
2005 return this._isDSTShifted;
2008 function isLocal () {
2009 return this.isValid() ? !this._isUTC : false;
2012 function isUtcOffset () {
2013 return this.isValid() ? this._isUTC : false;
2017 return this.isValid() ? this._isUTC && this._offset === 0 : false;
2020 // ASP.NET json date format regex
2021 var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
2023 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
2024 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
2025 // and further modified to allow for strings containing both week and day
2026 var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/;
2028 function create__createDuration (input, key) {
2029 var duration = input,
2030 // matching against regexp is expensive, do it on demand
2036 if (isDuration(input)) {
2038 ms : input._milliseconds,
2042 } else if (typeof input === 'number') {
2045 duration[key] = input;
2047 duration.milliseconds = input;
2049 } else if (!!(match = aspNetRegex.exec(input))) {
2050 sign = (match[1] === '-') ? -1 : 1;
2053 d : toInt(match[DATE]) * sign,
2054 h : toInt(match[HOUR]) * sign,
2055 m : toInt(match[MINUTE]) * sign,
2056 s : toInt(match[SECOND]) * sign,
2057 ms : toInt(match[MILLISECOND]) * sign
2059 } else if (!!(match = isoRegex.exec(input))) {
2060 sign = (match[1] === '-') ? -1 : 1;
2062 y : parseIso(match[2], sign),
2063 M : parseIso(match[3], sign),
2064 w : parseIso(match[4], sign),
2065 d : parseIso(match[5], sign),
2066 h : parseIso(match[6], sign),
2067 m : parseIso(match[7], sign),
2068 s : parseIso(match[8], sign)
2070 } else if (duration == null) {// checks for null or undefined
2072 } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
2073 diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
2076 duration.ms = diffRes.milliseconds;
2077 duration.M = diffRes.months;
2080 ret = new Duration(duration);
2082 if (isDuration(input) && hasOwnProp(input, '_locale')) {
2083 ret._locale = input._locale;
2089 create__createDuration.fn = Duration.prototype;
2091 function parseIso (inp, sign) {
2092 // We'd normally use ~~inp for this, but unfortunately it also
2093 // converts floats to ints.
2094 // inp may be undefined, so careful calling replace on it.
2095 var res = inp && parseFloat(inp.replace(',', '.'));
2096 // apply sign while we're at it
2097 return (isNaN(res) ? 0 : res) * sign;
2100 function positiveMomentsDifference(base, other) {
2101 var res = {milliseconds: 0, months: 0};
2103 res.months = other.month() - base.month() +
2104 (other.year() - base.year()) * 12;
2105 if (base.clone().add(res.months, 'M').isAfter(other)) {
2109 res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
2114 function momentsDifference(base, other) {
2116 if (!(base.isValid() && other.isValid())) {
2117 return {milliseconds: 0, months: 0};
2120 other = cloneWithOffset(other, base);
2121 if (base.isBefore(other)) {
2122 res = positiveMomentsDifference(base, other);
2124 res = positiveMomentsDifference(other, base);
2125 res.milliseconds = -res.milliseconds;
2126 res.months = -res.months;
2132 function absRound (number) {
2134 return Math.round(-1 * number) * -1;
2136 return Math.round(number);
2140 // TODO: remove 'name' arg after deprecation is removed
2141 function createAdder(direction, name) {
2142 return function (val, period) {
2144 //invert the arguments, but complain about it
2145 if (period !== null && !isNaN(+period)) {
2146 deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
2147 tmp = val; val = period; period = tmp;
2150 val = typeof val === 'string' ? +val : val;
2151 dur = create__createDuration(val, period);
2152 add_subtract__addSubtract(this, dur, direction);
2157 function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
2158 var milliseconds = duration._milliseconds,
2159 days = absRound(duration._days),
2160 months = absRound(duration._months);
2162 if (!mom.isValid()) {
2167 updateOffset = updateOffset == null ? true : updateOffset;
2170 mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
2173 get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
2176 setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
2179 utils_hooks__hooks.updateOffset(mom, days || months);
2183 var add_subtract__add = createAdder(1, 'add');
2184 var add_subtract__subtract = createAdder(-1, 'subtract');
2186 function moment_calendar__calendar (time, formats) {
2187 // We want to compare the start of today, vs this.
2188 // Getting start-of-today depends on whether we're local/utc/offset or not.
2189 var now = time || local__createLocal(),
2190 sod = cloneWithOffset(now, this).startOf('day'),
2191 diff = this.diff(sod, 'days', true),
2192 format = diff < -6 ? 'sameElse' :
2193 diff < -1 ? 'lastWeek' :
2194 diff < 0 ? 'lastDay' :
2195 diff < 1 ? 'sameDay' :
2196 diff < 2 ? 'nextDay' :
2197 diff < 7 ? 'nextWeek' : 'sameElse';
2199 var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
2201 return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
2205 return new Moment(this);
2208 function isAfter (input, units) {
2209 var localInput = isMoment(input) ? input : local__createLocal(input);
2210 if (!(this.isValid() && localInput.isValid())) {
2213 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
2214 if (units === 'millisecond') {
2215 return this.valueOf() > localInput.valueOf();
2217 return localInput.valueOf() < this.clone().startOf(units).valueOf();
2221 function isBefore (input, units) {
2222 var localInput = isMoment(input) ? input : local__createLocal(input);
2223 if (!(this.isValid() && localInput.isValid())) {
2226 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
2227 if (units === 'millisecond') {
2228 return this.valueOf() < localInput.valueOf();
2230 return this.clone().endOf(units).valueOf() < localInput.valueOf();
2234 function isBetween (from, to, units, inclusivity) {
2235 inclusivity = inclusivity || '()';
2236 return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
2237 (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
2240 function isSame (input, units) {
2241 var localInput = isMoment(input) ? input : local__createLocal(input),
2243 if (!(this.isValid() && localInput.isValid())) {
2246 units = normalizeUnits(units || 'millisecond');
2247 if (units === 'millisecond') {
2248 return this.valueOf() === localInput.valueOf();
2250 inputMs = localInput.valueOf();
2251 return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
2255 function isSameOrAfter (input, units) {
2256 return this.isSame(input, units) || this.isAfter(input,units);
2259 function isSameOrBefore (input, units) {
2260 return this.isSame(input, units) || this.isBefore(input,units);
2263 function diff (input, units, asFloat) {
2268 if (!this.isValid()) {
2272 that = cloneWithOffset(input, this);
2274 if (!that.isValid()) {
2278 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
2280 units = normalizeUnits(units);
2282 if (units === 'year' || units === 'month' || units === 'quarter') {
2283 output = monthDiff(this, that);
2284 if (units === 'quarter') {
2285 output = output / 3;
2286 } else if (units === 'year') {
2287 output = output / 12;
2290 delta = this - that;
2291 output = units === 'second' ? delta / 1e3 : // 1000
2292 units === 'minute' ? delta / 6e4 : // 1000 * 60
2293 units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
2294 units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
2295 units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
2298 return asFloat ? output : absFloor(output);
2301 function monthDiff (a, b) {
2302 // difference in months
2303 var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
2304 // b is in (anchor - 1 month, anchor + 1 month)
2305 anchor = a.clone().add(wholeMonthDiff, 'months'),
2308 if (b - anchor < 0) {
2309 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
2310 // linear across the month
2311 adjust = (b - anchor) / (anchor - anchor2);
2313 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
2314 // linear across the month
2315 adjust = (b - anchor) / (anchor2 - anchor);
2318 //check for negative zero, return zero if negative zero
2319 return -(wholeMonthDiff + adjust) || 0;
2322 utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
2323 utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
2325 function toString () {
2326 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
2329 function moment_format__toISOString () {
2330 var m = this.clone().utc();
2331 if (0 < m.year() && m.year() <= 9999) {
2332 if (isFunction(Date.prototype.toISOString)) {
2333 // native implementation is ~50x faster, use it when we can
2334 return this.toDate().toISOString();
2336 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2339 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2343 function format (inputString) {
2345 inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat;
2347 var output = formatMoment(this, inputString);
2348 return this.localeData().postformat(output);
2351 function from (time, withoutSuffix) {
2352 if (this.isValid() &&
2353 ((isMoment(time) && time.isValid()) ||
2354 local__createLocal(time).isValid())) {
2355 return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
2357 return this.localeData().invalidDate();
2361 function fromNow (withoutSuffix) {
2362 return this.from(local__createLocal(), withoutSuffix);
2365 function to (time, withoutSuffix) {
2366 if (this.isValid() &&
2367 ((isMoment(time) && time.isValid()) ||
2368 local__createLocal(time).isValid())) {
2369 return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
2371 return this.localeData().invalidDate();
2375 function toNow (withoutSuffix) {
2376 return this.to(local__createLocal(), withoutSuffix);
2379 // If passed a locale key, it will set the locale for this
2380 // instance. Otherwise, it will return the locale configuration
2381 // variables for this instance.
2382 function locale (key) {
2385 if (key === undefined) {
2386 return this._locale._abbr;
2388 newLocaleData = locale_locales__getLocale(key);
2389 if (newLocaleData != null) {
2390 this._locale = newLocaleData;
2396 var lang = deprecate(
2397 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
2399 if (key === undefined) {
2400 return this.localeData();
2402 return this.locale(key);
2407 function localeData () {
2408 return this._locale;
2411 function startOf (units) {
2412 units = normalizeUnits(units);
2413 // the following switch intentionally omits break keywords
2414 // to utilize falling through the cases.
2436 this.milliseconds(0);
2439 // weeks are a special case
2440 if (units === 'week') {
2443 if (units === 'isoWeek') {
2447 // quarters are also special
2448 if (units === 'quarter') {
2449 this.month(Math.floor(this.month() / 3) * 3);
2455 function endOf (units) {
2456 units = normalizeUnits(units);
2457 if (units === undefined || units === 'millisecond') {
2461 // 'date' is an alias for 'day', so it should be considered as such.
2462 if (units === 'date') {
2466 return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
2469 function to_type__valueOf () {
2470 return this._d.valueOf() - ((this._offset || 0) * 60000);
2474 return Math.floor(this.valueOf() / 1000);
2477 function toDate () {
2478 return this._offset ? new Date(this.valueOf()) : this._d;
2481 function toArray () {
2483 return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
2486 function toObject () {
2493 minutes: m.minutes(),
2494 seconds: m.seconds(),
2495 milliseconds: m.milliseconds()
2499 function toJSON () {
2500 // new Date(NaN).toJSON() === null
2501 return this.isValid() ? this.toISOString() : null;
2504 function moment_valid__isValid () {
2505 return valid__isValid(this);
2508 function parsingFlags () {
2509 return extend({}, getParsingFlags(this));
2512 function invalidAt () {
2513 return getParsingFlags(this).overflow;
2516 function creationData() {
2520 locale: this._locale,
2522 strict: this._strict
2528 addFormatToken(0, ['gg', 2], 0, function () {
2529 return this.weekYear() % 100;
2532 addFormatToken(0, ['GG', 2], 0, function () {
2533 return this.isoWeekYear() % 100;
2536 function addWeekYearFormatToken (token, getter) {
2537 addFormatToken(0, [token, token.length], 0, getter);
2540 addWeekYearFormatToken('gggg', 'weekYear');
2541 addWeekYearFormatToken('ggggg', 'weekYear');
2542 addWeekYearFormatToken('GGGG', 'isoWeekYear');
2543 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
2547 addUnitAlias('weekYear', 'gg');
2548 addUnitAlias('isoWeekYear', 'GG');
2552 addRegexToken('G', matchSigned);
2553 addRegexToken('g', matchSigned);
2554 addRegexToken('GG', match1to2, match2);
2555 addRegexToken('gg', match1to2, match2);
2556 addRegexToken('GGGG', match1to4, match4);
2557 addRegexToken('gggg', match1to4, match4);
2558 addRegexToken('GGGGG', match1to6, match6);
2559 addRegexToken('ggggg', match1to6, match6);
2561 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
2562 week[token.substr(0, 2)] = toInt(input);
2565 addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
2566 week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
2571 function getSetWeekYear (input) {
2572 return getSetWeekYearHelper.call(this,
2576 this.localeData()._week.dow,
2577 this.localeData()._week.doy);
2580 function getSetISOWeekYear (input) {
2581 return getSetWeekYearHelper.call(this,
2582 input, this.isoWeek(), this.isoWeekday(), 1, 4);
2585 function getISOWeeksInYear () {
2586 return weeksInYear(this.year(), 1, 4);
2589 function getWeeksInYear () {
2590 var weekInfo = this.localeData()._week;
2591 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
2594 function getSetWeekYearHelper(input, week, weekday, dow, doy) {
2596 if (input == null) {
2597 return weekOfYear(this, dow, doy).year;
2599 weeksTarget = weeksInYear(input, dow, doy);
2600 if (week > weeksTarget) {
2603 return setWeekAll.call(this, input, week, weekday, dow, doy);
2607 function setWeekAll(weekYear, week, weekday, dow, doy) {
2608 var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
2609 date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
2611 this.year(date.getUTCFullYear());
2612 this.month(date.getUTCMonth());
2613 this.date(date.getUTCDate());
2619 addFormatToken('Q', 0, 'Qo', 'quarter');
2623 addUnitAlias('quarter', 'Q');
2627 addRegexToken('Q', match1);
2628 addParseToken('Q', function (input, array) {
2629 array[MONTH] = (toInt(input) - 1) * 3;
2634 function getSetQuarter (input) {
2635 return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
2640 addFormatToken('w', ['ww', 2], 'wo', 'week');
2641 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
2645 addUnitAlias('week', 'w');
2646 addUnitAlias('isoWeek', 'W');
2650 addRegexToken('w', match1to2);
2651 addRegexToken('ww', match1to2, match2);
2652 addRegexToken('W', match1to2);
2653 addRegexToken('WW', match1to2, match2);
2655 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
2656 week[token.substr(0, 1)] = toInt(input);
2663 function localeWeek (mom) {
2664 return weekOfYear(mom, this._week.dow, this._week.doy).week;
2667 var defaultLocaleWeek = {
2668 dow : 0, // Sunday is the first day of the week.
2669 doy : 6 // The week that contains Jan 1st is the first week of the year.
2672 function localeFirstDayOfWeek () {
2673 return this._week.dow;
2676 function localeFirstDayOfYear () {
2677 return this._week.doy;
2682 function getSetWeek (input) {
2683 var week = this.localeData().week(this);
2684 return input == null ? week : this.add((input - week) * 7, 'd');
2687 function getSetISOWeek (input) {
2688 var week = weekOfYear(this, 1, 4).week;
2689 return input == null ? week : this.add((input - week) * 7, 'd');
2694 addFormatToken('D', ['DD', 2], 'Do', 'date');
2698 addUnitAlias('date', 'D');
2702 addRegexToken('D', match1to2);
2703 addRegexToken('DD', match1to2, match2);
2704 addRegexToken('Do', function (isStrict, locale) {
2705 return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
2708 addParseToken(['D', 'DD'], DATE);
2709 addParseToken('Do', function (input, array) {
2710 array[DATE] = toInt(input.match(match1to2)[0], 10);
2715 var getSetDayOfMonth = makeGetSet('Date', true);
2719 addFormatToken('d', 0, 'do', 'day');
2721 addFormatToken('dd', 0, 0, function (format) {
2722 return this.localeData().weekdaysMin(this, format);
2725 addFormatToken('ddd', 0, 0, function (format) {
2726 return this.localeData().weekdaysShort(this, format);
2729 addFormatToken('dddd', 0, 0, function (format) {
2730 return this.localeData().weekdays(this, format);
2733 addFormatToken('e', 0, 0, 'weekday');
2734 addFormatToken('E', 0, 0, 'isoWeekday');
2738 addUnitAlias('day', 'd');
2739 addUnitAlias('weekday', 'e');
2740 addUnitAlias('isoWeekday', 'E');
2744 addRegexToken('d', match1to2);
2745 addRegexToken('e', match1to2);
2746 addRegexToken('E', match1to2);
2747 addRegexToken('dd', function (isStrict, locale) {
2748 return locale.weekdaysMinRegex(isStrict);
2750 addRegexToken('ddd', function (isStrict, locale) {
2751 return locale.weekdaysShortRegex(isStrict);
2753 addRegexToken('dddd', function (isStrict, locale) {
2754 return locale.weekdaysRegex(isStrict);
2757 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
2758 var weekday = config._locale.weekdaysParse(input, token, config._strict);
2759 // if we didn't get a weekday name, mark the date as invalid
2760 if (weekday != null) {
2763 getParsingFlags(config).invalidWeekday = input;
2767 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
2768 week[token] = toInt(input);
2773 function parseWeekday(input, locale) {
2774 if (typeof input !== 'string') {
2778 if (!isNaN(input)) {
2779 return parseInt(input, 10);
2782 input = locale.weekdaysParse(input);
2783 if (typeof input === 'number') {
2792 var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
2793 function localeWeekdays (m, format) {
2794 return isArray(this._weekdays) ? this._weekdays[m.day()] :
2795 this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
2798 var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
2799 function localeWeekdaysShort (m) {
2800 return this._weekdaysShort[m.day()];
2803 var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
2804 function localeWeekdaysMin (m) {
2805 return this._weekdaysMin[m.day()];
2808 function day_of_week__handleStrictParse(weekdayName, format, strict) {
2809 var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
2810 if (!this._weekdaysParse) {
2811 this._weekdaysParse = [];
2812 this._shortWeekdaysParse = [];
2813 this._minWeekdaysParse = [];
2815 for (i = 0; i < 7; ++i) {
2816 mom = create_utc__createUTC([2000, 1]).day(i);
2817 this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
2818 this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
2819 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
2824 if (format === 'dddd') {
2825 ii = indexOf.call(this._weekdaysParse, llc);
2826 return ii !== -1 ? ii : null;
2827 } else if (format === 'ddd') {
2828 ii = indexOf.call(this._shortWeekdaysParse, llc);
2829 return ii !== -1 ? ii : null;
2831 ii = indexOf.call(this._minWeekdaysParse, llc);
2832 return ii !== -1 ? ii : null;
2835 if (format === 'dddd') {
2836 ii = indexOf.call(this._weekdaysParse, llc);
2840 ii = indexOf.call(this._shortWeekdaysParse, llc);
2844 ii = indexOf.call(this._minWeekdaysParse, llc);
2845 return ii !== -1 ? ii : null;
2846 } else if (format === 'ddd') {
2847 ii = indexOf.call(this._shortWeekdaysParse, llc);
2851 ii = indexOf.call(this._weekdaysParse, llc);
2855 ii = indexOf.call(this._minWeekdaysParse, llc);
2856 return ii !== -1 ? ii : null;
2858 ii = indexOf.call(this._minWeekdaysParse, llc);
2862 ii = indexOf.call(this._weekdaysParse, llc);
2866 ii = indexOf.call(this._shortWeekdaysParse, llc);
2867 return ii !== -1 ? ii : null;
2872 function localeWeekdaysParse (weekdayName, format, strict) {
2875 if (this._weekdaysParseExact) {
2876 return day_of_week__handleStrictParse.call(this, weekdayName, format, strict);
2879 if (!this._weekdaysParse) {
2880 this._weekdaysParse = [];
2881 this._minWeekdaysParse = [];
2882 this._shortWeekdaysParse = [];
2883 this._fullWeekdaysParse = [];
2886 for (i = 0; i < 7; i++) {
2887 // make the regex if we don't have it already
2889 mom = create_utc__createUTC([2000, 1]).day(i);
2890 if (strict && !this._fullWeekdaysParse[i]) {
2891 this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
2892 this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
2893 this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
2895 if (!this._weekdaysParse[i]) {
2896 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
2897 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
2900 if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
2902 } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
2904 } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
2906 } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
2914 function getSetDayOfWeek (input) {
2915 if (!this.isValid()) {
2916 return input != null ? this : NaN;
2918 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
2919 if (input != null) {
2920 input = parseWeekday(input, this.localeData());
2921 return this.add(input - day, 'd');
2927 function getSetLocaleDayOfWeek (input) {
2928 if (!this.isValid()) {
2929 return input != null ? this : NaN;
2931 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
2932 return input == null ? weekday : this.add(input - weekday, 'd');
2935 function getSetISODayOfWeek (input) {
2936 if (!this.isValid()) {
2937 return input != null ? this : NaN;
2939 // behaves the same as moment#day except
2940 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
2941 // as a setter, sunday should belong to the previous week.
2942 return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
2945 var defaultWeekdaysRegex = matchWord;
2946 function weekdaysRegex (isStrict) {
2947 if (this._weekdaysParseExact) {
2948 if (!hasOwnProp(this, '_weekdaysRegex')) {
2949 computeWeekdaysParse.call(this);
2952 return this._weekdaysStrictRegex;
2954 return this._weekdaysRegex;
2957 return this._weekdaysStrictRegex && isStrict ?
2958 this._weekdaysStrictRegex : this._weekdaysRegex;
2962 var defaultWeekdaysShortRegex = matchWord;
2963 function weekdaysShortRegex (isStrict) {
2964 if (this._weekdaysParseExact) {
2965 if (!hasOwnProp(this, '_weekdaysRegex')) {
2966 computeWeekdaysParse.call(this);
2969 return this._weekdaysShortStrictRegex;
2971 return this._weekdaysShortRegex;
2974 return this._weekdaysShortStrictRegex && isStrict ?
2975 this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
2979 var defaultWeekdaysMinRegex = matchWord;
2980 function weekdaysMinRegex (isStrict) {
2981 if (this._weekdaysParseExact) {
2982 if (!hasOwnProp(this, '_weekdaysRegex')) {
2983 computeWeekdaysParse.call(this);
2986 return this._weekdaysMinStrictRegex;
2988 return this._weekdaysMinRegex;
2991 return this._weekdaysMinStrictRegex && isStrict ?
2992 this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
2997 function computeWeekdaysParse () {
2998 function cmpLenRev(a, b) {
2999 return b.length - a.length;
3002 var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
3003 i, mom, minp, shortp, longp;
3004 for (i = 0; i < 7; i++) {
3005 // make the regex if we don't have it already
3006 mom = create_utc__createUTC([2000, 1]).day(i);
3007 minp = this.weekdaysMin(mom, '');
3008 shortp = this.weekdaysShort(mom, '');
3009 longp = this.weekdays(mom, '');
3010 minPieces.push(minp);
3011 shortPieces.push(shortp);
3012 longPieces.push(longp);
3013 mixedPieces.push(minp);
3014 mixedPieces.push(shortp);
3015 mixedPieces.push(longp);
3017 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
3018 // will match the longer piece.
3019 minPieces.sort(cmpLenRev);
3020 shortPieces.sort(cmpLenRev);
3021 longPieces.sort(cmpLenRev);
3022 mixedPieces.sort(cmpLenRev);
3023 for (i = 0; i < 7; i++) {
3024 shortPieces[i] = regexEscape(shortPieces[i]);
3025 longPieces[i] = regexEscape(longPieces[i]);
3026 mixedPieces[i] = regexEscape(mixedPieces[i]);
3029 this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
3030 this._weekdaysShortRegex = this._weekdaysRegex;
3031 this._weekdaysMinRegex = this._weekdaysRegex;
3033 this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
3034 this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
3035 this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
3040 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
3044 addUnitAlias('dayOfYear', 'DDD');
3048 addRegexToken('DDD', match1to3);
3049 addRegexToken('DDDD', match3);
3050 addParseToken(['DDD', 'DDDD'], function (input, array, config) {
3051 config._dayOfYear = toInt(input);
3058 function getSetDayOfYear (input) {
3059 var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
3060 return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
3065 function hFormat() {
3066 return this.hours() % 12 || 12;
3069 function kFormat() {
3070 return this.hours() || 24;
3073 addFormatToken('H', ['HH', 2], 0, 'hour');
3074 addFormatToken('h', ['hh', 2], 0, hFormat);
3075 addFormatToken('k', ['kk', 2], 0, kFormat);
3077 addFormatToken('hmm', 0, 0, function () {
3078 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
3081 addFormatToken('hmmss', 0, 0, function () {
3082 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
3083 zeroFill(this.seconds(), 2);
3086 addFormatToken('Hmm', 0, 0, function () {
3087 return '' + this.hours() + zeroFill(this.minutes(), 2);
3090 addFormatToken('Hmmss', 0, 0, function () {
3091 return '' + this.hours() + zeroFill(this.minutes(), 2) +
3092 zeroFill(this.seconds(), 2);
3095 function meridiem (token, lowercase) {
3096 addFormatToken(token, 0, 0, function () {
3097 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
3101 meridiem('a', true);
3102 meridiem('A', false);
3106 addUnitAlias('hour', 'h');
3110 function matchMeridiem (isStrict, locale) {
3111 return locale._meridiemParse;
3114 addRegexToken('a', matchMeridiem);
3115 addRegexToken('A', matchMeridiem);
3116 addRegexToken('H', match1to2);
3117 addRegexToken('h', match1to2);
3118 addRegexToken('HH', match1to2, match2);
3119 addRegexToken('hh', match1to2, match2);
3121 addRegexToken('hmm', match3to4);
3122 addRegexToken('hmmss', match5to6);
3123 addRegexToken('Hmm', match3to4);
3124 addRegexToken('Hmmss', match5to6);
3126 addParseToken(['H', 'HH'], HOUR);
3127 addParseToken(['a', 'A'], function (input, array, config) {
3128 config._isPm = config._locale.isPM(input);
3129 config._meridiem = input;
3131 addParseToken(['h', 'hh'], function (input, array, config) {
3132 array[HOUR] = toInt(input);
3133 getParsingFlags(config).bigHour = true;
3135 addParseToken('hmm', function (input, array, config) {
3136 var pos = input.length - 2;
3137 array[HOUR] = toInt(input.substr(0, pos));
3138 array[MINUTE] = toInt(input.substr(pos));
3139 getParsingFlags(config).bigHour = true;
3141 addParseToken('hmmss', function (input, array, config) {
3142 var pos1 = input.length - 4;
3143 var pos2 = input.length - 2;
3144 array[HOUR] = toInt(input.substr(0, pos1));
3145 array[MINUTE] = toInt(input.substr(pos1, 2));
3146 array[SECOND] = toInt(input.substr(pos2));
3147 getParsingFlags(config).bigHour = true;
3149 addParseToken('Hmm', function (input, array, config) {
3150 var pos = input.length - 2;
3151 array[HOUR] = toInt(input.substr(0, pos));
3152 array[MINUTE] = toInt(input.substr(pos));
3154 addParseToken('Hmmss', function (input, array, config) {
3155 var pos1 = input.length - 4;
3156 var pos2 = input.length - 2;
3157 array[HOUR] = toInt(input.substr(0, pos1));
3158 array[MINUTE] = toInt(input.substr(pos1, 2));
3159 array[SECOND] = toInt(input.substr(pos2));
3164 function localeIsPM (input) {
3165 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
3166 // Using charAt should be more compatible.
3167 return ((input + '').toLowerCase().charAt(0) === 'p');
3170 var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
3171 function localeMeridiem (hours, minutes, isLower) {
3173 return isLower ? 'pm' : 'PM';
3175 return isLower ? 'am' : 'AM';
3182 // Setting the hour should keep the time, because the user explicitly
3183 // specified which hour he wants. So trying to maintain the same hour (in
3184 // a new timezone) makes sense. Adding/subtracting hours does not follow
3186 var getSetHour = makeGetSet('Hours', true);
3190 addFormatToken('m', ['mm', 2], 0, 'minute');
3194 addUnitAlias('minute', 'm');
3198 addRegexToken('m', match1to2);
3199 addRegexToken('mm', match1to2, match2);
3200 addParseToken(['m', 'mm'], MINUTE);
3204 var getSetMinute = makeGetSet('Minutes', false);
3208 addFormatToken('s', ['ss', 2], 0, 'second');
3212 addUnitAlias('second', 's');
3216 addRegexToken('s', match1to2);
3217 addRegexToken('ss', match1to2, match2);
3218 addParseToken(['s', 'ss'], SECOND);
3222 var getSetSecond = makeGetSet('Seconds', false);
3226 addFormatToken('S', 0, 0, function () {
3227 return ~~(this.millisecond() / 100);
3230 addFormatToken(0, ['SS', 2], 0, function () {
3231 return ~~(this.millisecond() / 10);
3234 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
3235 addFormatToken(0, ['SSSS', 4], 0, function () {
3236 return this.millisecond() * 10;
3238 addFormatToken(0, ['SSSSS', 5], 0, function () {
3239 return this.millisecond() * 100;
3241 addFormatToken(0, ['SSSSSS', 6], 0, function () {
3242 return this.millisecond() * 1000;
3244 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
3245 return this.millisecond() * 10000;
3247 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
3248 return this.millisecond() * 100000;
3250 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
3251 return this.millisecond() * 1000000;
3257 addUnitAlias('millisecond', 'ms');
3261 addRegexToken('S', match1to3, match1);
3262 addRegexToken('SS', match1to3, match2);
3263 addRegexToken('SSS', match1to3, match3);
3266 for (token = 'SSSS'; token.length <= 9; token += 'S') {
3267 addRegexToken(token, matchUnsigned);
3270 function parseMs(input, array) {
3271 array[MILLISECOND] = toInt(('0.' + input) * 1000);
3274 for (token = 'S'; token.length <= 9; token += 'S') {
3275 addParseToken(token, parseMs);
3279 var getSetMillisecond = makeGetSet('Milliseconds', false);
3283 addFormatToken('z', 0, 0, 'zoneAbbr');
3284 addFormatToken('zz', 0, 0, 'zoneName');
3288 function getZoneAbbr () {
3289 return this._isUTC ? 'UTC' : '';
3292 function getZoneName () {
3293 return this._isUTC ? 'Coordinated Universal Time' : '';
3296 var momentPrototype__proto = Moment.prototype;
3298 momentPrototype__proto.add = add_subtract__add;
3299 momentPrototype__proto.calendar = moment_calendar__calendar;
3300 momentPrototype__proto.clone = clone;
3301 momentPrototype__proto.diff = diff;
3302 momentPrototype__proto.endOf = endOf;
3303 momentPrototype__proto.format = format;
3304 momentPrototype__proto.from = from;
3305 momentPrototype__proto.fromNow = fromNow;
3306 momentPrototype__proto.to = to;
3307 momentPrototype__proto.toNow = toNow;
3308 momentPrototype__proto.get = getSet;
3309 momentPrototype__proto.invalidAt = invalidAt;
3310 momentPrototype__proto.isAfter = isAfter;
3311 momentPrototype__proto.isBefore = isBefore;
3312 momentPrototype__proto.isBetween = isBetween;
3313 momentPrototype__proto.isSame = isSame;
3314 momentPrototype__proto.isSameOrAfter = isSameOrAfter;
3315 momentPrototype__proto.isSameOrBefore = isSameOrBefore;
3316 momentPrototype__proto.isValid = moment_valid__isValid;
3317 momentPrototype__proto.lang = lang;
3318 momentPrototype__proto.locale = locale;
3319 momentPrototype__proto.localeData = localeData;
3320 momentPrototype__proto.max = prototypeMax;
3321 momentPrototype__proto.min = prototypeMin;
3322 momentPrototype__proto.parsingFlags = parsingFlags;
3323 momentPrototype__proto.set = getSet;
3324 momentPrototype__proto.startOf = startOf;
3325 momentPrototype__proto.subtract = add_subtract__subtract;
3326 momentPrototype__proto.toArray = toArray;
3327 momentPrototype__proto.toObject = toObject;
3328 momentPrototype__proto.toDate = toDate;
3329 momentPrototype__proto.toISOString = moment_format__toISOString;
3330 momentPrototype__proto.toJSON = toJSON;
3331 momentPrototype__proto.toString = toString;
3332 momentPrototype__proto.unix = unix;
3333 momentPrototype__proto.valueOf = to_type__valueOf;
3334 momentPrototype__proto.creationData = creationData;
3337 momentPrototype__proto.year = getSetYear;
3338 momentPrototype__proto.isLeapYear = getIsLeapYear;
3341 momentPrototype__proto.weekYear = getSetWeekYear;
3342 momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
3345 momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
3348 momentPrototype__proto.month = getSetMonth;
3349 momentPrototype__proto.daysInMonth = getDaysInMonth;
3352 momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
3353 momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
3354 momentPrototype__proto.weeksInYear = getWeeksInYear;
3355 momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
3358 momentPrototype__proto.date = getSetDayOfMonth;
3359 momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
3360 momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
3361 momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
3362 momentPrototype__proto.dayOfYear = getSetDayOfYear;
3365 momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
3368 momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
3371 momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
3374 momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
3377 momentPrototype__proto.utcOffset = getSetOffset;
3378 momentPrototype__proto.utc = setOffsetToUTC;
3379 momentPrototype__proto.local = setOffsetToLocal;
3380 momentPrototype__proto.parseZone = setOffsetToParsedOffset;
3381 momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
3382 momentPrototype__proto.isDST = isDaylightSavingTime;
3383 momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
3384 momentPrototype__proto.isLocal = isLocal;
3385 momentPrototype__proto.isUtcOffset = isUtcOffset;
3386 momentPrototype__proto.isUtc = isUtc;
3387 momentPrototype__proto.isUTC = isUtc;
3390 momentPrototype__proto.zoneAbbr = getZoneAbbr;
3391 momentPrototype__proto.zoneName = getZoneName;
3394 momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
3395 momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
3396 momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
3397 momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
3399 var momentPrototype = momentPrototype__proto;
3401 function moment__createUnix (input) {
3402 return local__createLocal(input * 1000);
3405 function moment__createInZone () {
3406 return local__createLocal.apply(null, arguments).parseZone();
3409 var defaultCalendar = {
3410 sameDay : '[Today at] LT',
3411 nextDay : '[Tomorrow at] LT',
3412 nextWeek : 'dddd [at] LT',
3413 lastDay : '[Yesterday at] LT',
3414 lastWeek : '[Last] dddd [at] LT',
3418 function locale_calendar__calendar (key, mom, now) {
3419 var output = this._calendar[key];
3420 return isFunction(output) ? output.call(mom, now) : output;
3423 var defaultLongDateFormat = {
3427 LL : 'MMMM D, YYYY',
3428 LLL : 'MMMM D, YYYY h:mm A',
3429 LLLL : 'dddd, MMMM D, YYYY h:mm A'
3432 function longDateFormat (key) {
3433 var format = this._longDateFormat[key],
3434 formatUpper = this._longDateFormat[key.toUpperCase()];
3436 if (format || !formatUpper) {
3440 this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
3441 return val.slice(1);
3444 return this._longDateFormat[key];
3447 var defaultInvalidDate = 'Invalid date';
3449 function invalidDate () {
3450 return this._invalidDate;
3453 var defaultOrdinal = '%d';
3454 var defaultOrdinalParse = /\d{1,2}/;
3456 function ordinal (number) {
3457 return this._ordinal.replace('%d', number);
3460 function preParsePostFormat (string) {
3464 var defaultRelativeTime = {
3467 s : 'a few seconds',
3480 function relative__relativeTime (number, withoutSuffix, string, isFuture) {
3481 var output = this._relativeTime[string];
3482 return (isFunction(output)) ?
3483 output(number, withoutSuffix, string, isFuture) :
3484 output.replace(/%d/i, number);
3487 function pastFuture (diff, output) {
3488 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
3489 return isFunction(format) ? format(output) : format.replace(/%s/i, output);
3492 var prototype__proto = Locale.prototype;
3494 prototype__proto._calendar = defaultCalendar;
3495 prototype__proto.calendar = locale_calendar__calendar;
3496 prototype__proto._longDateFormat = defaultLongDateFormat;
3497 prototype__proto.longDateFormat = longDateFormat;
3498 prototype__proto._invalidDate = defaultInvalidDate;
3499 prototype__proto.invalidDate = invalidDate;
3500 prototype__proto._ordinal = defaultOrdinal;
3501 prototype__proto.ordinal = ordinal;
3502 prototype__proto._ordinalParse = defaultOrdinalParse;
3503 prototype__proto.preparse = preParsePostFormat;
3504 prototype__proto.postformat = preParsePostFormat;
3505 prototype__proto._relativeTime = defaultRelativeTime;
3506 prototype__proto.relativeTime = relative__relativeTime;
3507 prototype__proto.pastFuture = pastFuture;
3508 prototype__proto.set = locale_set__set;
3511 prototype__proto.months = localeMonths;
3512 prototype__proto._months = defaultLocaleMonths;
3513 prototype__proto.monthsShort = localeMonthsShort;
3514 prototype__proto._monthsShort = defaultLocaleMonthsShort;
3515 prototype__proto.monthsParse = localeMonthsParse;
3516 prototype__proto._monthsRegex = defaultMonthsRegex;
3517 prototype__proto.monthsRegex = monthsRegex;
3518 prototype__proto._monthsShortRegex = defaultMonthsShortRegex;
3519 prototype__proto.monthsShortRegex = monthsShortRegex;
3522 prototype__proto.week = localeWeek;
3523 prototype__proto._week = defaultLocaleWeek;
3524 prototype__proto.firstDayOfYear = localeFirstDayOfYear;
3525 prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
3528 prototype__proto.weekdays = localeWeekdays;
3529 prototype__proto._weekdays = defaultLocaleWeekdays;
3530 prototype__proto.weekdaysMin = localeWeekdaysMin;
3531 prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
3532 prototype__proto.weekdaysShort = localeWeekdaysShort;
3533 prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
3534 prototype__proto.weekdaysParse = localeWeekdaysParse;
3536 prototype__proto._weekdaysRegex = defaultWeekdaysRegex;
3537 prototype__proto.weekdaysRegex = weekdaysRegex;
3538 prototype__proto._weekdaysShortRegex = defaultWeekdaysShortRegex;
3539 prototype__proto.weekdaysShortRegex = weekdaysShortRegex;
3540 prototype__proto._weekdaysMinRegex = defaultWeekdaysMinRegex;
3541 prototype__proto.weekdaysMinRegex = weekdaysMinRegex;
3544 prototype__proto.isPM = localeIsPM;
3545 prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
3546 prototype__proto.meridiem = localeMeridiem;
3548 function lists__get (format, index, field, setter) {
3549 var locale = locale_locales__getLocale();
3550 var utc = create_utc__createUTC().set(setter, index);
3551 return locale[field](utc, format);
3554 function listMonthsImpl (format, index, field) {
3555 if (typeof format === 'number') {
3560 format = format || '';
3562 if (index != null) {
3563 return lists__get(format, index, field, 'month');
3568 for (i = 0; i < 12; i++) {
3569 out[i] = lists__get(format, i, field, 'month');
3582 function listWeekdaysImpl (localeSorted, format, index, field) {
3583 if (typeof localeSorted === 'boolean') {
3584 if (typeof format === 'number') {
3589 format = format || '';
3591 format = localeSorted;
3593 localeSorted = false;
3595 if (typeof format === 'number') {
3600 format = format || '';
3603 var locale = locale_locales__getLocale(),
3604 shift = localeSorted ? locale._week.dow : 0;
3606 if (index != null) {
3607 return lists__get(format, (index + shift) % 7, field, 'day');
3612 for (i = 0; i < 7; i++) {
3613 out[i] = lists__get(format, (i + shift) % 7, field, 'day');
3618 function lists__listMonths (format, index) {
3619 return listMonthsImpl(format, index, 'months');
3622 function lists__listMonthsShort (format, index) {
3623 return listMonthsImpl(format, index, 'monthsShort');
3626 function lists__listWeekdays (localeSorted, format, index) {
3627 return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
3630 function lists__listWeekdaysShort (localeSorted, format, index) {
3631 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
3634 function lists__listWeekdaysMin (localeSorted, format, index) {
3635 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
3638 locale_locales__getSetGlobalLocale('en', {
3639 ordinalParse: /\d{1,2}(th|st|nd|rd)/,
3640 ordinal : function (number) {
3641 var b = number % 10,
3642 output = (toInt(number % 100 / 10) === 1) ? 'th' :
3645 (b === 3) ? 'rd' : 'th';
3646 return number + output;
3650 // Side effect imports
3651 utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
3652 utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
3654 var mathAbs = Math.abs;
3656 function duration_abs__abs () {
3657 var data = this._data;
3659 this._milliseconds = mathAbs(this._milliseconds);
3660 this._days = mathAbs(this._days);
3661 this._months = mathAbs(this._months);
3663 data.milliseconds = mathAbs(data.milliseconds);
3664 data.seconds = mathAbs(data.seconds);
3665 data.minutes = mathAbs(data.minutes);
3666 data.hours = mathAbs(data.hours);
3667 data.months = mathAbs(data.months);
3668 data.years = mathAbs(data.years);
3673 function duration_add_subtract__addSubtract (duration, input, value, direction) {
3674 var other = create__createDuration(input, value);
3676 duration._milliseconds += direction * other._milliseconds;
3677 duration._days += direction * other._days;
3678 duration._months += direction * other._months;
3680 return duration._bubble();
3683 // supports only 2.0-style add(1, 's') or add(duration)
3684 function duration_add_subtract__add (input, value) {
3685 return duration_add_subtract__addSubtract(this, input, value, 1);
3688 // supports only 2.0-style subtract(1, 's') or subtract(duration)
3689 function duration_add_subtract__subtract (input, value) {
3690 return duration_add_subtract__addSubtract(this, input, value, -1);
3693 function absCeil (number) {
3695 return Math.floor(number);
3697 return Math.ceil(number);
3701 function bubble () {
3702 var milliseconds = this._milliseconds;
3703 var days = this._days;
3704 var months = this._months;
3705 var data = this._data;
3706 var seconds, minutes, hours, years, monthsFromDays;
3708 // if we have a mix of positive and negative values, bubble down first
3709 // check: https://github.com/moment/moment/issues/2166
3710 if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
3711 (milliseconds <= 0 && days <= 0 && months <= 0))) {
3712 milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
3717 // The following code bubbles up values, see the tests for
3718 // examples of what that means.
3719 data.milliseconds = milliseconds % 1000;
3721 seconds = absFloor(milliseconds / 1000);
3722 data.seconds = seconds % 60;
3724 minutes = absFloor(seconds / 60);
3725 data.minutes = minutes % 60;
3727 hours = absFloor(minutes / 60);
3728 data.hours = hours % 24;
3730 days += absFloor(hours / 24);
3732 // convert days to months
3733 monthsFromDays = absFloor(daysToMonths(days));
3734 months += monthsFromDays;
3735 days -= absCeil(monthsToDays(monthsFromDays));
3737 // 12 months -> 1 year
3738 years = absFloor(months / 12);
3742 data.months = months;
3748 function daysToMonths (days) {
3749 // 400 years have 146097 days (taking into account leap year rules)
3750 // 400 years have 12 months === 4800
3751 return days * 4800 / 146097;
3754 function monthsToDays (months) {
3755 // the reverse of daysToMonths
3756 return months * 146097 / 4800;
3759 function as (units) {
3762 var milliseconds = this._milliseconds;
3764 units = normalizeUnits(units);
3766 if (units === 'month' || units === 'year') {
3767 days = this._days + milliseconds / 864e5;
3768 months = this._months + daysToMonths(days);
3769 return units === 'month' ? months : months / 12;
3771 // handle milliseconds separately because of floating point math errors (issue #1867)
3772 days = this._days + Math.round(monthsToDays(this._months));
3774 case 'week' : return days / 7 + milliseconds / 6048e5;
3775 case 'day' : return days + milliseconds / 864e5;
3776 case 'hour' : return days * 24 + milliseconds / 36e5;
3777 case 'minute' : return days * 1440 + milliseconds / 6e4;
3778 case 'second' : return days * 86400 + milliseconds / 1000;
3779 // Math.floor prevents floating point math errors here
3780 case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
3781 default: throw new Error('Unknown unit ' + units);
3786 // TODO: Use this.as('ms')?
3787 function duration_as__valueOf () {
3789 this._milliseconds +
3790 this._days * 864e5 +
3791 (this._months % 12) * 2592e6 +
3792 toInt(this._months / 12) * 31536e6
3796 function makeAs (alias) {
3797 return function () {
3798 return this.as(alias);
3802 var asMilliseconds = makeAs('ms');
3803 var asSeconds = makeAs('s');
3804 var asMinutes = makeAs('m');
3805 var asHours = makeAs('h');
3806 var asDays = makeAs('d');
3807 var asWeeks = makeAs('w');
3808 var asMonths = makeAs('M');
3809 var asYears = makeAs('y');
3811 function duration_get__get (units) {
3812 units = normalizeUnits(units);
3813 return this[units + 's']();
3816 function makeGetter(name) {
3817 return function () {
3818 return this._data[name];
3822 var milliseconds = makeGetter('milliseconds');
3823 var seconds = makeGetter('seconds');
3824 var minutes = makeGetter('minutes');
3825 var hours = makeGetter('hours');
3826 var days = makeGetter('days');
3827 var months = makeGetter('months');
3828 var years = makeGetter('years');
3831 return absFloor(this.days() / 7);
3834 var round = Math.round;
3836 s: 45, // seconds to minute
3837 m: 45, // minutes to hour
3838 h: 22, // hours to day
3839 d: 26, // days to month
3840 M: 11 // months to year
3843 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
3844 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
3845 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
3848 function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
3849 var duration = create__createDuration(posNegDuration).abs();
3850 var seconds = round(duration.as('s'));
3851 var minutes = round(duration.as('m'));
3852 var hours = round(duration.as('h'));
3853 var days = round(duration.as('d'));
3854 var months = round(duration.as('M'));
3855 var years = round(duration.as('y'));
3857 var a = seconds < thresholds.s && ['s', seconds] ||
3858 minutes <= 1 && ['m'] ||
3859 minutes < thresholds.m && ['mm', minutes] ||
3860 hours <= 1 && ['h'] ||
3861 hours < thresholds.h && ['hh', hours] ||
3862 days <= 1 && ['d'] ||
3863 days < thresholds.d && ['dd', days] ||
3864 months <= 1 && ['M'] ||
3865 months < thresholds.M && ['MM', months] ||
3866 years <= 1 && ['y'] || ['yy', years];
3868 a[2] = withoutSuffix;
3869 a[3] = +posNegDuration > 0;
3871 return substituteTimeAgo.apply(null, a);
3874 // This function allows you to set a threshold for relative time strings
3875 function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
3876 if (thresholds[threshold] === undefined) {
3879 if (limit === undefined) {
3880 return thresholds[threshold];
3882 thresholds[threshold] = limit;
3886 function humanize (withSuffix) {
3887 var locale = this.localeData();
3888 var output = duration_humanize__relativeTime(this, !withSuffix, locale);
3891 output = locale.pastFuture(+this, output);
3894 return locale.postformat(output);
3897 var iso_string__abs = Math.abs;
3899 function iso_string__toISOString() {
3900 // for ISO strings we do not use the normal bubbling rules:
3901 // * milliseconds bubble up until they become hours
3902 // * days do not bubble at all
3903 // * months bubble up until they become years
3904 // This is because there is no context-free conversion between hours and days
3905 // (think of clock changes)
3906 // and also not between days and months (28-31 days per month)
3907 var seconds = iso_string__abs(this._milliseconds) / 1000;
3908 var days = iso_string__abs(this._days);
3909 var months = iso_string__abs(this._months);
3910 var minutes, hours, years;
3912 // 3600 seconds -> 60 minutes -> 1 hour
3913 minutes = absFloor(seconds / 60);
3914 hours = absFloor(minutes / 60);
3918 // 12 months -> 1 year
3919 years = absFloor(months / 12);
3923 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
3930 var total = this.asSeconds();
3933 // this is the same as C#'s (Noda) and python (isodate)...
3934 // but not other JS (goog.date)
3938 return (total < 0 ? '-' : '') +
3940 (Y ? Y + 'Y' : '') +
3941 (M ? M + 'M' : '') +
3942 (D ? D + 'D' : '') +
3943 ((h || m || s) ? 'T' : '') +
3944 (h ? h + 'H' : '') +
3945 (m ? m + 'M' : '') +
3949 var duration_prototype__proto = Duration.prototype;
3951 duration_prototype__proto.abs = duration_abs__abs;
3952 duration_prototype__proto.add = duration_add_subtract__add;
3953 duration_prototype__proto.subtract = duration_add_subtract__subtract;
3954 duration_prototype__proto.as = as;
3955 duration_prototype__proto.asMilliseconds = asMilliseconds;
3956 duration_prototype__proto.asSeconds = asSeconds;
3957 duration_prototype__proto.asMinutes = asMinutes;
3958 duration_prototype__proto.asHours = asHours;
3959 duration_prototype__proto.asDays = asDays;
3960 duration_prototype__proto.asWeeks = asWeeks;
3961 duration_prototype__proto.asMonths = asMonths;
3962 duration_prototype__proto.asYears = asYears;
3963 duration_prototype__proto.valueOf = duration_as__valueOf;
3964 duration_prototype__proto._bubble = bubble;
3965 duration_prototype__proto.get = duration_get__get;
3966 duration_prototype__proto.milliseconds = milliseconds;
3967 duration_prototype__proto.seconds = seconds;
3968 duration_prototype__proto.minutes = minutes;
3969 duration_prototype__proto.hours = hours;
3970 duration_prototype__proto.days = days;
3971 duration_prototype__proto.weeks = weeks;
3972 duration_prototype__proto.months = months;
3973 duration_prototype__proto.years = years;
3974 duration_prototype__proto.humanize = humanize;
3975 duration_prototype__proto.toISOString = iso_string__toISOString;
3976 duration_prototype__proto.toString = iso_string__toISOString;
3977 duration_prototype__proto.toJSON = iso_string__toISOString;
3978 duration_prototype__proto.locale = locale;
3979 duration_prototype__proto.localeData = localeData;
3982 duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
3983 duration_prototype__proto.lang = lang;
3985 // Side effect imports
3989 addFormatToken('X', 0, 0, 'unix');
3990 addFormatToken('x', 0, 0, 'valueOf');
3994 addRegexToken('x', matchSigned);
3995 addRegexToken('X', matchTimestamp);
3996 addParseToken('X', function (input, array, config) {
3997 config._d = new Date(parseFloat(input, 10) * 1000);
3999 addParseToken('x', function (input, array, config) {
4000 config._d = new Date(toInt(input));
4003 // Side effect imports
4006 utils_hooks__hooks.version = '2.13.0';
4008 setHookCallback(local__createLocal);
4010 utils_hooks__hooks.fn = momentPrototype;
4011 utils_hooks__hooks.min = min;
4012 utils_hooks__hooks.max = max;
4013 utils_hooks__hooks.now = now;
4014 utils_hooks__hooks.utc = create_utc__createUTC;
4015 utils_hooks__hooks.unix = moment__createUnix;
4016 utils_hooks__hooks.months = lists__listMonths;
4017 utils_hooks__hooks.isDate = isDate;
4018 utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
4019 utils_hooks__hooks.invalid = valid__createInvalid;
4020 utils_hooks__hooks.duration = create__createDuration;
4021 utils_hooks__hooks.isMoment = isMoment;
4022 utils_hooks__hooks.weekdays = lists__listWeekdays;
4023 utils_hooks__hooks.parseZone = moment__createInZone;
4024 utils_hooks__hooks.localeData = locale_locales__getLocale;
4025 utils_hooks__hooks.isDuration = isDuration;
4026 utils_hooks__hooks.monthsShort = lists__listMonthsShort;
4027 utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
4028 utils_hooks__hooks.defineLocale = defineLocale;
4029 utils_hooks__hooks.updateLocale = updateLocale;
4030 utils_hooks__hooks.locales = locale_locales__listLocales;
4031 utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
4032 utils_hooks__hooks.normalizeUnits = normalizeUnits;
4033 utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
4034 utils_hooks__hooks.prototype = momentPrototype;
4036 var _moment = utils_hooks__hooks;