3 ;(function (global
, factory
) {
4 typeof exports
=== 'object' && typeof module
!== 'undefined' ? module
.exports
= factory() :
5 typeof define
=== 'function' && define
.amd
? define(factory
) :
6 global
.moment
= factory()
7 }(this, (function () { 'use strict';
12 return hookCallback
.apply(null, arguments
);
15 // This is done to register the method called with moment()
16 // without creating circular dependencies.
17 function setHookCallback (callback
) {
18 hookCallback
= callback
;
21 function isArray(input
) {
22 return input
instanceof Array
|| Object
.prototype.toString
.call(input
) === '[object Array]';
25 function isObject(input
) {
26 // IE8 will treat undefined and null as object if it wasn't for
28 return input
!= null && Object
.prototype.toString
.call(input
) === '[object Object]';
31 function isObjectEmpty(obj
) {
32 if (Object
.getOwnPropertyNames
) {
33 return (Object
.getOwnPropertyNames(obj
).length
=== 0);
37 if (obj
.hasOwnProperty(k
)) {
45 function isUndefined(input
) {
46 return input
=== void 0;
49 function isNumber(input
) {
50 return typeof input
=== 'number' || Object
.prototype.toString
.call(input
) === '[object Number]';
53 function isDate(input
) {
54 return input
instanceof Date
|| Object
.prototype.toString
.call(input
) === '[object Date]';
57 function map(arr
, fn
) {
59 for (i
= 0; i
< arr
.length
; ++i
) {
60 res
.push(fn(arr
[i
], i
));
65 function hasOwnProp(a
, b
) {
66 return Object
.prototype.hasOwnProperty
.call(a
, b
);
69 function extend(a
, b
) {
71 if (hasOwnProp(b
, i
)) {
76 if (hasOwnProp(b
, 'toString')) {
77 a
.toString
= b
.toString
;
80 if (hasOwnProp(b
, 'valueOf')) {
81 a
.valueOf
= b
.valueOf
;
87 function createUTC (input
, format
, locale
, strict
) {
88 return createLocalOrUTC(input
, format
, locale
, strict
, true).utc();
91 function defaultParsingFlags() {
92 // We need to deep clone this object.
101 invalidFormat
: false,
102 userInvalidated
: false,
104 parsedDateParts
: [],
107 weekdayMismatch
: false
111 function getParsingFlags(m
) {
113 m
._pf
= defaultParsingFlags();
119 if (Array
.prototype.some
) {
120 some
= Array
.prototype.some
;
122 some = function (fun
) {
123 var t
= Object(this);
124 var len
= t
.length
>>> 0;
126 for (var i
= 0; i
< len
; i
++) {
127 if (i
in t
&& fun
.call(this, t
[i
], i
, t
)) {
136 function isValid(m
) {
137 if (m
._isValid
== null) {
138 var flags
= getParsingFlags(m
);
139 var parsedParts
= some
.call(flags
.parsedDateParts
, function (i
) {
142 var isNowValid
= !isNaN(m
._d
.getTime()) &&
143 flags
.overflow
< 0 &&
145 !flags
.invalidMonth
&&
146 !flags
.invalidWeekday
&&
147 !flags
.weekdayMismatch
&&
149 !flags
.invalidFormat
&&
150 !flags
.userInvalidated
&&
151 (!flags
.meridiem
|| (flags
.meridiem
&& parsedParts
));
154 isNowValid
= isNowValid
&&
155 flags
.charsLeftOver
=== 0 &&
156 flags
.unusedTokens
.length
=== 0 &&
157 flags
.bigHour
=== undefined;
160 if (Object
.isFrozen
== null || !Object
.isFrozen(m
)) {
161 m
._isValid
= isNowValid
;
170 function createInvalid (flags
) {
171 var m
= createUTC(NaN
);
173 extend(getParsingFlags(m
), flags
);
176 getParsingFlags(m
).userInvalidated
= true;
182 // Plugins that add properties should also add the key here (null value),
183 // so we can properly clone ourselves.
184 var momentProperties
= hooks
.momentProperties
= [];
186 function copyConfig(to
, from) {
189 if (!isUndefined(from._isAMomentObject
)) {
190 to
._isAMomentObject
= from._isAMomentObject
;
192 if (!isUndefined(from._i
)) {
195 if (!isUndefined(from._f
)) {
198 if (!isUndefined(from._l
)) {
201 if (!isUndefined(from._strict
)) {
202 to
._strict
= from._strict
;
204 if (!isUndefined(from._tzm
)) {
207 if (!isUndefined(from._isUTC
)) {
208 to
._isUTC
= from._isUTC
;
210 if (!isUndefined(from._offset
)) {
211 to
._offset
= from._offset
;
213 if (!isUndefined(from._pf
)) {
214 to
._pf
= getParsingFlags(from);
216 if (!isUndefined(from._locale
)) {
217 to
._locale
= from._locale
;
220 if (momentProperties
.length
> 0) {
221 for (i
= 0; i
< momentProperties
.length
; i
++) {
222 prop
= momentProperties
[i
];
224 if (!isUndefined(val
)) {
233 var updateInProgress
= false;
235 // Moment prototype object
236 function Moment(config
) {
237 copyConfig(this, config
);
238 this._d
= new Date(config
._d
!= null ? config
._d
.getTime() : NaN
);
239 if (!this.isValid()) {
240 this._d
= new Date(NaN
);
242 // Prevent infinite loop in case updateOffset creates new moment
244 if (updateInProgress
=== false) {
245 updateInProgress
= true;
246 hooks
.updateOffset(this);
247 updateInProgress
= false;
251 function isMoment (obj
) {
252 return obj
instanceof Moment
|| (obj
!= null && obj
._isAMomentObject
!= null);
255 function absFloor (number
) {
258 return Math
.ceil(number
) || 0;
260 return Math
.floor(number
);
264 function toInt(argumentForCoercion
) {
265 var coercedNumber
= +argumentForCoercion
,
268 if (coercedNumber
!== 0 && isFinite(coercedNumber
)) {
269 value
= absFloor(coercedNumber
);
275 // compare two arrays, return the number of differences
276 function compareArrays(array1
, array2
, dontConvert
) {
277 var len
= Math
.min(array1
.length
, array2
.length
),
278 lengthDiff
= Math
.abs(array1
.length
- array2
.length
),
281 for (i
= 0; i
< len
; i
++) {
282 if ((dontConvert
&& array1
[i
] !== array2
[i
]) ||
283 (!dontConvert
&& toInt(array1
[i
]) !== toInt(array2
[i
]))) {
287 return diffs
+ lengthDiff
;
291 if (hooks
.suppressDeprecationWarnings
=== false &&
292 (typeof console
!== 'undefined') && console
.warn
) {
293 console
.warn('Deprecation warning: ' + msg
);
297 function deprecate(msg
, fn
) {
298 var firstTime
= true;
300 return extend(function () {
301 if (hooks
.deprecationHandler
!= null) {
302 hooks
.deprecationHandler(null, msg
);
307 for (var i
= 0; i
< arguments
.length
; i
++) {
309 if (typeof arguments
[i
] === 'object') {
310 arg
+= '\n[' + i
+ '] ';
311 for (var key
in arguments
[0]) {
312 arg
+= key
+ ': ' + arguments
[0][key
] + ', ';
314 arg
= arg
.slice(0, -2); // Remove trailing comma and space
320 warn(msg
+ '\nArguments: ' + Array
.prototype.slice
.call(args
).join('') + '\n' + (new Error()).stack
);
323 return fn
.apply(this, arguments
);
327 var deprecations
= {};
329 function deprecateSimple(name
, msg
) {
330 if (hooks
.deprecationHandler
!= null) {
331 hooks
.deprecationHandler(name
, msg
);
333 if (!deprecations
[name
]) {
335 deprecations
[name
] = true;
339 hooks
.suppressDeprecationWarnings
= false;
340 hooks
.deprecationHandler
= null;
342 function isFunction(input
) {
343 return input
instanceof Function
|| Object
.prototype.toString
.call(input
) === '[object Function]';
346 function set (config
) {
350 if (isFunction(prop
)) {
353 this['_' + i
] = prop
;
356 this._config
= config
;
357 // Lenient ordinal parsing accepts just a number in addition to
358 // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
359 // TODO: Remove "ordinalParse" fallback in next major release.
360 this._dayOfMonthOrdinalParseLenient
= new RegExp(
361 (this._dayOfMonthOrdinalParse
.source
|| this._ordinalParse
.source
) +
362 '|' + (/\d{1,2}/).source
);
365 function mergeConfigs(parentConfig
, childConfig
) {
366 var res
= extend({}, parentConfig
), prop
;
367 for (prop
in childConfig
) {
368 if (hasOwnProp(childConfig
, prop
)) {
369 if (isObject(parentConfig
[prop
]) && isObject(childConfig
[prop
])) {
371 extend(res
[prop
], parentConfig
[prop
]);
372 extend(res
[prop
], childConfig
[prop
]);
373 } else if (childConfig
[prop
] != null) {
374 res
[prop
] = childConfig
[prop
];
380 for (prop
in parentConfig
) {
381 if (hasOwnProp(parentConfig
, prop
) &&
382 !hasOwnProp(childConfig
, prop
) &&
383 isObject(parentConfig
[prop
])) {
384 // make sure changes to properties don't modify parent config
385 res
[prop
] = extend({}, res
[prop
]);
391 function Locale(config
) {
392 if (config
!= null) {
402 keys = function (obj
) {
405 if (hasOwnProp(obj
, i
)) {
413 var defaultCalendar
= {
414 sameDay
: '[Today at] LT',
415 nextDay
: '[Tomorrow at] LT',
416 nextWeek
: 'dddd [at] LT',
417 lastDay
: '[Yesterday at] LT',
418 lastWeek
: '[Last] dddd [at] LT',
422 function calendar (key
, mom
, now
) {
423 var output
= this._calendar
[key
] || this._calendar
['sameElse'];
424 return isFunction(output
) ? output
.call(mom
, now
) : output
;
427 var defaultLongDateFormat
= {
432 LLL
: 'MMMM D, YYYY h:mm A',
433 LLLL
: 'dddd, MMMM D, YYYY h:mm A'
436 function longDateFormat (key
) {
437 var format
= this._longDateFormat
[key
],
438 formatUpper
= this._longDateFormat
[key
.toUpperCase()];
440 if (format
|| !formatUpper
) {
444 this._longDateFormat
[key
] = formatUpper
.replace(/MMMM|MM|DD|dddd/g, function (val
) {
448 return this._longDateFormat
[key
];
451 var defaultInvalidDate
= 'Invalid date';
453 function invalidDate () {
454 return this._invalidDate
;
457 var defaultOrdinal
= '%d';
458 var defaultDayOfMonthOrdinalParse
= /\d{1,2}/;
460 function ordinal (number
) {
461 return this._ordinal
.replace('%d', number
);
464 var defaultRelativeTime
= {
481 function relativeTime (number
, withoutSuffix
, string
, isFuture
) {
482 var output
= this._relativeTime
[string
];
483 return (isFunction(output
)) ?
484 output(number
, withoutSuffix
, string
, isFuture
) :
485 output
.replace(/%d/i, number
);
488 function pastFuture (diff
, output
) {
489 var format
= this._relativeTime
[diff
> 0 ? 'future' : 'past'];
490 return isFunction(format
) ? format(output
) : format
.replace(/%s/i, output
);
495 function addUnitAlias (unit
, shorthand
) {
496 var lowerCase
= unit
.toLowerCase();
497 aliases
[lowerCase
] = aliases
[lowerCase
+ 's'] = aliases
[shorthand
] = unit
;
500 function normalizeUnits(units
) {
501 return typeof units
=== 'string' ? aliases
[units
] || aliases
[units
.toLowerCase()] : undefined;
504 function normalizeObjectUnits(inputObject
) {
505 var normalizedInput
= {},
509 for (prop
in inputObject
) {
510 if (hasOwnProp(inputObject
, prop
)) {
511 normalizedProp
= normalizeUnits(prop
);
512 if (normalizedProp
) {
513 normalizedInput
[normalizedProp
] = inputObject
[prop
];
518 return normalizedInput
;
523 function addUnitPriority(unit
, priority
) {
524 priorities
[unit
] = priority
;
527 function getPrioritizedUnits(unitsObj
) {
529 for (var u
in unitsObj
) {
530 units
.push({unit
: u
, priority
: priorities
[u
]});
532 units
.sort(function (a
, b
) {
533 return a
.priority
- b
.priority
;
538 function zeroFill(number
, targetLength
, forceSign
) {
539 var absNumber
= '' + Math
.abs(number
),
540 zerosToFill
= targetLength
- absNumber
.length
,
542 return (sign
? (forceSign
? '+' : '') : '-') +
543 Math
.pow(10, Math
.max(0, zerosToFill
)).toString().substr(1) + absNumber
;
546 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;
548 var localFormattingTokens
= /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
550 var formatFunctions
= {};
552 var formatTokenFunctions
= {};
557 // callback: function () { this.month() + 1 }
558 function addFormatToken (token
, padded
, ordinal
, callback
) {
560 if (typeof callback
=== 'string') {
562 return this[callback
]();
566 formatTokenFunctions
[token
] = func
;
569 formatTokenFunctions
[padded
[0]] = function () {
570 return zeroFill(func
.apply(this, arguments
), padded
[1], padded
[2]);
574 formatTokenFunctions
[ordinal
] = function () {
575 return this.localeData().ordinal(func
.apply(this, arguments
), token
);
580 function removeFormattingTokens(input
) {
581 if (input
.match(/\[[\s\S]/)) {
582 return input
.replace(/^\[|\]$/g, '');
584 return input
.replace(/\\/g
, '');
587 function makeFormatFunction(format
) {
588 var array
= format
.match(formattingTokens
), i
, length
;
590 for (i
= 0, length
= array
.length
; i
< length
; i
++) {
591 if (formatTokenFunctions
[array
[i
]]) {
592 array
[i
] = formatTokenFunctions
[array
[i
]];
594 array
[i
] = removeFormattingTokens(array
[i
]);
598 return function (mom
) {
600 for (i
= 0; i
< length
; i
++) {
601 output
+= isFunction(array
[i
]) ? array
[i
].call(mom
, format
) : array
[i
];
607 // format date using native date object
608 function formatMoment(m
, format
) {
610 return m
.localeData().invalidDate();
613 format
= expandFormat(format
, m
.localeData());
614 formatFunctions
[format
] = formatFunctions
[format
] || makeFormatFunction(format
);
616 return formatFunctions
[format
](m
);
619 function expandFormat(format
, locale
) {
622 function replaceLongDateFormatTokens(input
) {
623 return locale
.longDateFormat(input
) || input
;
626 localFormattingTokens
.lastIndex
= 0;
627 while (i
>= 0 && localFormattingTokens
.test(format
)) {
628 format
= format
.replace(localFormattingTokens
, replaceLongDateFormatTokens
);
629 localFormattingTokens
.lastIndex
= 0;
636 var match1
= /\d/; // 0 - 9
637 var match2
= /\d\d/; // 00 - 99
638 var match3
= /\d{3}/; // 000 - 999
639 var match4
= /\d{4}/; // 0000 - 9999
640 var match6
= /[+-]?\d{6}/; // -999999 - 999999
641 var match1to2
= /\d\d?/; // 0 - 99
642 var match3to4
= /\d\d\d\d?/; // 999 - 9999
643 var match5to6
= /\d\d\d\d\d\d?/; // 99999 - 999999
644 var match1to3
= /\d{1,3}/; // 0 - 999
645 var match1to4
= /\d{1,4}/; // 0 - 9999
646 var match1to6
= /[+-]?\d{1,6}/; // -999999 - 999999
648 var matchUnsigned
= /\d+/; // 0 - inf
649 var matchSigned
= /[+-]?\d+/; // -inf - inf
651 var matchOffset
= /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
652 var matchShortOffset
= /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
654 var matchTimestamp
= /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
656 // any word (or two) characters or numbers including two/three word month in arabic.
657 // includes scottish gaelic two word and hyphenated months
658 var matchWord
= /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;
662 function addRegexToken (token
, regex
, strictRegex
) {
663 regexes
[token
] = isFunction(regex
) ? regex : function (isStrict
, localeData
) {
664 return (isStrict
&& strictRegex
) ? strictRegex
: regex
;
668 function getParseRegexForToken (token
, config
) {
669 if (!hasOwnProp(regexes
, token
)) {
670 return new RegExp(unescapeFormat(token
));
673 return regexes
[token
](config
._strict
, config
._locale
);
676 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
677 function unescapeFormat(s
) {
678 return regexEscape(s
.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched
, p1
, p2
, p3
, p4
) {
679 return p1
|| p2
|| p3
|| p4
;
683 function regexEscape(s
) {
684 return s
.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
689 function addParseToken (token
, callback
) {
690 var i
, func
= callback
;
691 if (typeof token
=== 'string') {
694 if (isNumber(callback
)) {
695 func = function (input
, array
) {
696 array
[callback
] = toInt(input
);
699 for (i
= 0; i
< token
.length
; i
++) {
700 tokens
[token
[i
]] = func
;
704 function addWeekParseToken (token
, callback
) {
705 addParseToken(token
, function (input
, array
, config
, token
) {
706 config
._w
= config
._w
|| {};
707 callback(input
, config
._w
, config
, token
);
711 function addTimeToArrayFromToken(token
, input
, config
) {
712 if (input
!= null && hasOwnProp(tokens
, token
)) {
713 tokens
[token
](input
, config
._a
, config
, token
);
729 addFormatToken('Y', 0, 0, function () {
731 return y
<= 9999 ? '' + y
: '+' + y
;
734 addFormatToken(0, ['YY', 2], 0, function () {
735 return this.year() % 100;
738 addFormatToken(0, ['YYYY', 4], 0, 'year');
739 addFormatToken(0, ['YYYYY', 5], 0, 'year');
740 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
744 addUnitAlias('year', 'y');
748 addUnitPriority('year', 1);
752 addRegexToken('Y', matchSigned
);
753 addRegexToken('YY', match1to2
, match2
);
754 addRegexToken('YYYY', match1to4
, match4
);
755 addRegexToken('YYYYY', match1to6
, match6
);
756 addRegexToken('YYYYYY', match1to6
, match6
);
758 addParseToken(['YYYYY', 'YYYYYY'], YEAR
);
759 addParseToken('YYYY', function (input
, array
) {
760 array
[YEAR
] = input
.length
=== 2 ? hooks
.parseTwoDigitYear(input
) : toInt(input
);
762 addParseToken('YY', function (input
, array
) {
763 array
[YEAR
] = hooks
.parseTwoDigitYear(input
);
765 addParseToken('Y', function (input
, array
) {
766 array
[YEAR
] = parseInt(input
, 10);
771 function daysInYear(year
) {
772 return isLeapYear(year
) ? 366 : 365;
775 function isLeapYear(year
) {
776 return (year
% 4 === 0 && year
% 100 !== 0) || year
% 400 === 0;
781 hooks
.parseTwoDigitYear = function (input
) {
782 return toInt(input
) + (toInt(input
) > 68 ? 1900 : 2000);
787 var getSetYear
= makeGetSet('FullYear', true);
789 function getIsLeapYear () {
790 return isLeapYear(this.year());
793 function makeGetSet (unit
, keepTime
) {
794 return function (value
) {
796 set$1(this, unit
, value
);
797 hooks
.updateOffset(this, keepTime
);
800 return get(this, unit
);
805 function get (mom
, unit
) {
806 return mom
.isValid() ?
807 mom
._d
['get' + (mom
._isUTC
? 'UTC' : '') + unit
]() : NaN
;
810 function set$1 (mom
, unit
, value
) {
811 if (mom
.isValid() && !isNaN(value
)) {
812 if (unit
=== 'FullYear' && isLeapYear(mom
.year()) && mom
.month() === 1 && mom
.date() === 29) {
813 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + unit
](value
, mom
.month(), daysInMonth(value
, mom
.month()));
816 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + unit
](value
);
823 function stringGet (units
) {
824 units
= normalizeUnits(units
);
825 if (isFunction(this[units
])) {
826 return this[units
]();
832 function stringSet (units
, value
) {
833 if (typeof units
=== 'object') {
834 units
= normalizeObjectUnits(units
);
835 var prioritized
= getPrioritizedUnits(units
);
836 for (var i
= 0; i
< prioritized
.length
; i
++) {
837 this[prioritized
[i
].unit
](units
[prioritized
[i
].unit
]);
840 units
= normalizeUnits(units
);
841 if (isFunction(this[units
])) {
842 return this[units
](value
);
849 return ((n
% x
) + x
) % x
;
854 if (Array
.prototype.indexOf
) {
855 indexOf
= Array
.prototype.indexOf
;
857 indexOf = function (o
) {
860 for (i
= 0; i
< this.length
; ++i
) {
869 function daysInMonth(year
, month
) {
870 if (isNaN(year
) || isNaN(month
)) {
873 var modMonth
= mod(month
, 12);
874 year
+= (month
- modMonth
) / 12;
875 return modMonth
=== 1 ? (isLeapYear(year
) ? 29 : 28) : (31 - modMonth
% 7 % 2);
880 addFormatToken('M', ['MM', 2], 'Mo', function () {
881 return this.month() + 1;
884 addFormatToken('MMM', 0, 0, function (format
) {
885 return this.localeData().monthsShort(this, format
);
888 addFormatToken('MMMM', 0, 0, function (format
) {
889 return this.localeData().months(this, format
);
894 addUnitAlias('month', 'M');
898 addUnitPriority('month', 8);
902 addRegexToken('M', match1to2
);
903 addRegexToken('MM', match1to2
, match2
);
904 addRegexToken('MMM', function (isStrict
, locale
) {
905 return locale
.monthsShortRegex(isStrict
);
907 addRegexToken('MMMM', function (isStrict
, locale
) {
908 return locale
.monthsRegex(isStrict
);
911 addParseToken(['M', 'MM'], function (input
, array
) {
912 array
[MONTH
] = toInt(input
) - 1;
915 addParseToken(['MMM', 'MMMM'], function (input
, array
, config
, token
) {
916 var month
= config
._locale
.monthsParse(input
, token
, config
._strict
);
917 // if we didn't find a month name, mark the date as invalid.
919 array
[MONTH
] = month
;
921 getParsingFlags(config
).invalidMonth
= input
;
927 var MONTHS_IN_FORMAT
= /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
928 var defaultLocaleMonths
= 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
929 function localeMonths (m
, format
) {
931 return isArray(this._months
) ? this._months
:
932 this._months
['standalone'];
934 return isArray(this._months
) ? this._months
[m
.month()] :
935 this._months
[(this._months
.isFormat
|| MONTHS_IN_FORMAT
).test(format
) ? 'format' : 'standalone'][m
.month()];
938 var defaultLocaleMonthsShort
= 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
939 function localeMonthsShort (m
, format
) {
941 return isArray(this._monthsShort
) ? this._monthsShort
:
942 this._monthsShort
['standalone'];
944 return isArray(this._monthsShort
) ? this._monthsShort
[m
.month()] :
945 this._monthsShort
[MONTHS_IN_FORMAT
.test(format
) ? 'format' : 'standalone'][m
.month()];
948 function handleStrictParse(monthName
, format
, strict
) {
949 var i
, ii
, mom
, llc
= monthName
.toLocaleLowerCase();
950 if (!this._monthsParse
) {
952 this._monthsParse
= [];
953 this._longMonthsParse
= [];
954 this._shortMonthsParse
= [];
955 for (i
= 0; i
< 12; ++i
) {
956 mom
= createUTC([2000, i
]);
957 this._shortMonthsParse
[i
] = this.monthsShort(mom
, '').toLocaleLowerCase();
958 this._longMonthsParse
[i
] = this.months(mom
, '').toLocaleLowerCase();
963 if (format
=== 'MMM') {
964 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
965 return ii
!== -1 ? ii
: null;
967 ii
= indexOf
.call(this._longMonthsParse
, llc
);
968 return ii
!== -1 ? ii
: null;
971 if (format
=== 'MMM') {
972 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
976 ii
= indexOf
.call(this._longMonthsParse
, llc
);
977 return ii
!== -1 ? ii
: null;
979 ii
= indexOf
.call(this._longMonthsParse
, llc
);
983 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
984 return ii
!== -1 ? ii
: null;
989 function localeMonthsParse (monthName
, format
, strict
) {
992 if (this._monthsParseExact
) {
993 return handleStrictParse
.call(this, monthName
, format
, strict
);
996 if (!this._monthsParse
) {
997 this._monthsParse
= [];
998 this._longMonthsParse
= [];
999 this._shortMonthsParse
= [];
1002 // TODO: add sorting
1003 // Sorting makes sure if one month (or abbr) is a prefix of another
1004 // see sorting in computeMonthsParse
1005 for (i
= 0; i
< 12; i
++) {
1006 // make the regex if we don't have it already
1007 mom
= createUTC([2000, i
]);
1008 if (strict
&& !this._longMonthsParse
[i
]) {
1009 this._longMonthsParse
[i
] = new RegExp('^' + this.months(mom
, '').replace('.', '') + '$', 'i');
1010 this._shortMonthsParse
[i
] = new RegExp('^' + this.monthsShort(mom
, '').replace('.', '') + '$', 'i');
1012 if (!strict
&& !this._monthsParse
[i
]) {
1013 regex
= '^' + this.months(mom
, '') + '|^' + this.monthsShort(mom
, '');
1014 this._monthsParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
1017 if (strict
&& format
=== 'MMMM' && this._longMonthsParse
[i
].test(monthName
)) {
1019 } else if (strict
&& format
=== 'MMM' && this._shortMonthsParse
[i
].test(monthName
)) {
1021 } else if (!strict
&& this._monthsParse
[i
].test(monthName
)) {
1029 function setMonth (mom
, value
) {
1032 if (!mom
.isValid()) {
1037 if (typeof value
=== 'string') {
1038 if (/^\d+$/.test(value
)) {
1039 value
= toInt(value
);
1041 value
= mom
.localeData().monthsParse(value
);
1042 // TODO: Another silent failure?
1043 if (!isNumber(value
)) {
1049 dayOfMonth
= Math
.min(mom
.date(), daysInMonth(mom
.year(), value
));
1050 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + 'Month'](value
, dayOfMonth
);
1054 function getSetMonth (value
) {
1055 if (value
!= null) {
1056 setMonth(this, value
);
1057 hooks
.updateOffset(this, true);
1060 return get(this, 'Month');
1064 function getDaysInMonth () {
1065 return daysInMonth(this.year(), this.month());
1068 var defaultMonthsShortRegex
= matchWord
;
1069 function monthsShortRegex (isStrict
) {
1070 if (this._monthsParseExact
) {
1071 if (!hasOwnProp(this, '_monthsRegex')) {
1072 computeMonthsParse
.call(this);
1075 return this._monthsShortStrictRegex
;
1077 return this._monthsShortRegex
;
1080 if (!hasOwnProp(this, '_monthsShortRegex')) {
1081 this._monthsShortRegex
= defaultMonthsShortRegex
;
1083 return this._monthsShortStrictRegex
&& isStrict
?
1084 this._monthsShortStrictRegex
: this._monthsShortRegex
;
1088 var defaultMonthsRegex
= matchWord
;
1089 function monthsRegex (isStrict
) {
1090 if (this._monthsParseExact
) {
1091 if (!hasOwnProp(this, '_monthsRegex')) {
1092 computeMonthsParse
.call(this);
1095 return this._monthsStrictRegex
;
1097 return this._monthsRegex
;
1100 if (!hasOwnProp(this, '_monthsRegex')) {
1101 this._monthsRegex
= defaultMonthsRegex
;
1103 return this._monthsStrictRegex
&& isStrict
?
1104 this._monthsStrictRegex
: this._monthsRegex
;
1108 function computeMonthsParse () {
1109 function cmpLenRev(a
, b
) {
1110 return b
.length
- a
.length
;
1113 var shortPieces
= [], longPieces
= [], mixedPieces
= [],
1115 for (i
= 0; i
< 12; i
++) {
1116 // make the regex if we don't have it already
1117 mom
= createUTC([2000, i
]);
1118 shortPieces
.push(this.monthsShort(mom
, ''));
1119 longPieces
.push(this.months(mom
, ''));
1120 mixedPieces
.push(this.months(mom
, ''));
1121 mixedPieces
.push(this.monthsShort(mom
, ''));
1123 // Sorting makes sure if one month (or abbr) is a prefix of another it
1124 // will match the longer piece.
1125 shortPieces
.sort(cmpLenRev
);
1126 longPieces
.sort(cmpLenRev
);
1127 mixedPieces
.sort(cmpLenRev
);
1128 for (i
= 0; i
< 12; i
++) {
1129 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1130 longPieces
[i
] = regexEscape(longPieces
[i
]);
1132 for (i
= 0; i
< 24; i
++) {
1133 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1136 this._monthsRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1137 this._monthsShortRegex
= this._monthsRegex
;
1138 this._monthsStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1139 this._monthsShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1142 function createDate (y
, m
, d
, h
, M
, s
, ms
) {
1143 // can't just apply() to create a date:
1144 // https://stackoverflow.com/q/181348
1145 var date
= new Date(y
, m
, d
, h
, M
, s
, ms
);
1147 // the date constructor remaps years 0-99 to 1900-1999
1148 if (y
< 100 && y
>= 0 && isFinite(date
.getFullYear())) {
1149 date
.setFullYear(y
);
1154 function createUTCDate (y
) {
1155 var date
= new Date(Date
.UTC
.apply(null, arguments
));
1157 // the Date.UTC function remaps years 0-99 to 1900-1999
1158 if (y
< 100 && y
>= 0 && isFinite(date
.getUTCFullYear())) {
1159 date
.setUTCFullYear(y
);
1164 // start-of-first-week - start-of-year
1165 function firstWeekOffset(year
, dow
, doy
) {
1166 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1167 fwd
= 7 + dow
- doy
,
1168 // first-week day local weekday -- which local weekday is fwd
1169 fwdlw
= (7 + createUTCDate(year
, 0, fwd
).getUTCDay() - dow
) % 7;
1171 return -fwdlw
+ fwd
- 1;
1174 // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1175 function dayOfYearFromWeeks(year
, week
, weekday
, dow
, doy
) {
1176 var localWeekday
= (7 + weekday
- dow
) % 7,
1177 weekOffset
= firstWeekOffset(year
, dow
, doy
),
1178 dayOfYear
= 1 + 7 * (week
- 1) + localWeekday
+ weekOffset
,
1179 resYear
, resDayOfYear
;
1181 if (dayOfYear
<= 0) {
1183 resDayOfYear
= daysInYear(resYear
) + dayOfYear
;
1184 } else if (dayOfYear
> daysInYear(year
)) {
1186 resDayOfYear
= dayOfYear
- daysInYear(year
);
1189 resDayOfYear
= dayOfYear
;
1194 dayOfYear
: resDayOfYear
1198 function weekOfYear(mom
, dow
, doy
) {
1199 var weekOffset
= firstWeekOffset(mom
.year(), dow
, doy
),
1200 week
= Math
.floor((mom
.dayOfYear() - weekOffset
- 1) / 7) + 1,
1204 resYear
= mom
.year() - 1;
1205 resWeek
= week
+ weeksInYear(resYear
, dow
, doy
);
1206 } else if (week
> weeksInYear(mom
.year(), dow
, doy
)) {
1207 resWeek
= week
- weeksInYear(mom
.year(), dow
, doy
);
1208 resYear
= mom
.year() + 1;
1210 resYear
= mom
.year();
1220 function weeksInYear(year
, dow
, doy
) {
1221 var weekOffset
= firstWeekOffset(year
, dow
, doy
),
1222 weekOffsetNext
= firstWeekOffset(year
+ 1, dow
, doy
);
1223 return (daysInYear(year
) - weekOffset
+ weekOffsetNext
) / 7;
1228 addFormatToken('w', ['ww', 2], 'wo', 'week');
1229 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
1233 addUnitAlias('week', 'w');
1234 addUnitAlias('isoWeek', 'W');
1238 addUnitPriority('week', 5);
1239 addUnitPriority('isoWeek', 5);
1243 addRegexToken('w', match1to2
);
1244 addRegexToken('ww', match1to2
, match2
);
1245 addRegexToken('W', match1to2
);
1246 addRegexToken('WW', match1to2
, match2
);
1248 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input
, week
, config
, token
) {
1249 week
[token
.substr(0, 1)] = toInt(input
);
1256 function localeWeek (mom
) {
1257 return weekOfYear(mom
, this._week
.dow
, this._week
.doy
).week
;
1260 var defaultLocaleWeek
= {
1261 dow
: 0, // Sunday is the first day of the week.
1262 doy
: 6 // The week that contains Jan 1st is the first week of the year.
1265 function localeFirstDayOfWeek () {
1266 return this._week
.dow
;
1269 function localeFirstDayOfYear () {
1270 return this._week
.doy
;
1275 function getSetWeek (input
) {
1276 var week
= this.localeData().week(this);
1277 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1280 function getSetISOWeek (input
) {
1281 var week
= weekOfYear(this, 1, 4).week
;
1282 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1287 addFormatToken('d', 0, 'do', 'day');
1289 addFormatToken('dd', 0, 0, function (format
) {
1290 return this.localeData().weekdaysMin(this, format
);
1293 addFormatToken('ddd', 0, 0, function (format
) {
1294 return this.localeData().weekdaysShort(this, format
);
1297 addFormatToken('dddd', 0, 0, function (format
) {
1298 return this.localeData().weekdays(this, format
);
1301 addFormatToken('e', 0, 0, 'weekday');
1302 addFormatToken('E', 0, 0, 'isoWeekday');
1306 addUnitAlias('day', 'd');
1307 addUnitAlias('weekday', 'e');
1308 addUnitAlias('isoWeekday', 'E');
1311 addUnitPriority('day', 11);
1312 addUnitPriority('weekday', 11);
1313 addUnitPriority('isoWeekday', 11);
1317 addRegexToken('d', match1to2
);
1318 addRegexToken('e', match1to2
);
1319 addRegexToken('E', match1to2
);
1320 addRegexToken('dd', function (isStrict
, locale
) {
1321 return locale
.weekdaysMinRegex(isStrict
);
1323 addRegexToken('ddd', function (isStrict
, locale
) {
1324 return locale
.weekdaysShortRegex(isStrict
);
1326 addRegexToken('dddd', function (isStrict
, locale
) {
1327 return locale
.weekdaysRegex(isStrict
);
1330 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input
, week
, config
, token
) {
1331 var weekday
= config
._locale
.weekdaysParse(input
, token
, config
._strict
);
1332 // if we didn't get a weekday name, mark the date as invalid
1333 if (weekday
!= null) {
1336 getParsingFlags(config
).invalidWeekday
= input
;
1340 addWeekParseToken(['d', 'e', 'E'], function (input
, week
, config
, token
) {
1341 week
[token
] = toInt(input
);
1346 function parseWeekday(input
, locale
) {
1347 if (typeof input
!== 'string') {
1351 if (!isNaN(input
)) {
1352 return parseInt(input
, 10);
1355 input
= locale
.weekdaysParse(input
);
1356 if (typeof input
=== 'number') {
1363 function parseIsoWeekday(input
, locale
) {
1364 if (typeof input
=== 'string') {
1365 return locale
.weekdaysParse(input
) % 7 || 7;
1367 return isNaN(input
) ? null : input
;
1372 var defaultLocaleWeekdays
= 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
1373 function localeWeekdays (m
, format
) {
1375 return isArray(this._weekdays
) ? this._weekdays
:
1376 this._weekdays
['standalone'];
1378 return isArray(this._weekdays
) ? this._weekdays
[m
.day()] :
1379 this._weekdays
[this._weekdays
.isFormat
.test(format
) ? 'format' : 'standalone'][m
.day()];
1382 var defaultLocaleWeekdaysShort
= 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
1383 function localeWeekdaysShort (m
) {
1384 return (m
) ? this._weekdaysShort
[m
.day()] : this._weekdaysShort
;
1387 var defaultLocaleWeekdaysMin
= 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
1388 function localeWeekdaysMin (m
) {
1389 return (m
) ? this._weekdaysMin
[m
.day()] : this._weekdaysMin
;
1392 function handleStrictParse
$1(weekdayName
, format
, strict
) {
1393 var i
, ii
, mom
, llc
= weekdayName
.toLocaleLowerCase();
1394 if (!this._weekdaysParse
) {
1395 this._weekdaysParse
= [];
1396 this._shortWeekdaysParse
= [];
1397 this._minWeekdaysParse
= [];
1399 for (i
= 0; i
< 7; ++i
) {
1400 mom
= createUTC([2000, 1]).day(i
);
1401 this._minWeekdaysParse
[i
] = this.weekdaysMin(mom
, '').toLocaleLowerCase();
1402 this._shortWeekdaysParse
[i
] = this.weekdaysShort(mom
, '').toLocaleLowerCase();
1403 this._weekdaysParse
[i
] = this.weekdays(mom
, '').toLocaleLowerCase();
1408 if (format
=== 'dddd') {
1409 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1410 return ii
!== -1 ? ii
: null;
1411 } else if (format
=== 'ddd') {
1412 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1413 return ii
!== -1 ? ii
: null;
1415 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1416 return ii
!== -1 ? ii
: null;
1419 if (format
=== 'dddd') {
1420 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1424 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1428 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1429 return ii
!== -1 ? ii
: null;
1430 } else if (format
=== 'ddd') {
1431 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1435 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1439 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1440 return ii
!== -1 ? ii
: null;
1442 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1446 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1450 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1451 return ii
!== -1 ? ii
: null;
1456 function localeWeekdaysParse (weekdayName
, format
, strict
) {
1459 if (this._weekdaysParseExact
) {
1460 return handleStrictParse
$1.call(this, weekdayName
, format
, strict
);
1463 if (!this._weekdaysParse
) {
1464 this._weekdaysParse
= [];
1465 this._minWeekdaysParse
= [];
1466 this._shortWeekdaysParse
= [];
1467 this._fullWeekdaysParse
= [];
1470 for (i
= 0; i
< 7; i
++) {
1471 // make the regex if we don't have it already
1473 mom
= createUTC([2000, 1]).day(i
);
1474 if (strict
&& !this._fullWeekdaysParse
[i
]) {
1475 this._fullWeekdaysParse
[i
] = new RegExp('^' + this.weekdays(mom
, '').replace('.', '\\.?') + '$', 'i');
1476 this._shortWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysShort(mom
, '').replace('.', '\\.?') + '$', 'i');
1477 this._minWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysMin(mom
, '').replace('.', '\\.?') + '$', 'i');
1479 if (!this._weekdaysParse
[i
]) {
1480 regex
= '^' + this.weekdays(mom
, '') + '|^' + this.weekdaysShort(mom
, '') + '|^' + this.weekdaysMin(mom
, '');
1481 this._weekdaysParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
1484 if (strict
&& format
=== 'dddd' && this._fullWeekdaysParse
[i
].test(weekdayName
)) {
1486 } else if (strict
&& format
=== 'ddd' && this._shortWeekdaysParse
[i
].test(weekdayName
)) {
1488 } else if (strict
&& format
=== 'dd' && this._minWeekdaysParse
[i
].test(weekdayName
)) {
1490 } else if (!strict
&& this._weekdaysParse
[i
].test(weekdayName
)) {
1498 function getSetDayOfWeek (input
) {
1499 if (!this.isValid()) {
1500 return input
!= null ? this : NaN
;
1502 var day
= this._isUTC
? this._d
.getUTCDay() : this._d
.getDay();
1503 if (input
!= null) {
1504 input
= parseWeekday(input
, this.localeData());
1505 return this.add(input
- day
, 'd');
1511 function getSetLocaleDayOfWeek (input
) {
1512 if (!this.isValid()) {
1513 return input
!= null ? this : NaN
;
1515 var weekday
= (this.day() + 7 - this.localeData()._week
.dow
) % 7;
1516 return input
== null ? weekday
: this.add(input
- weekday
, 'd');
1519 function getSetISODayOfWeek (input
) {
1520 if (!this.isValid()) {
1521 return input
!= null ? this : NaN
;
1524 // behaves the same as moment#day except
1525 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
1526 // as a setter, sunday should belong to the previous week.
1528 if (input
!= null) {
1529 var weekday
= parseIsoWeekday(input
, this.localeData());
1530 return this.day(this.day() % 7 ? weekday
: weekday
- 7);
1532 return this.day() || 7;
1536 var defaultWeekdaysRegex
= matchWord
;
1537 function weekdaysRegex (isStrict
) {
1538 if (this._weekdaysParseExact
) {
1539 if (!hasOwnProp(this, '_weekdaysRegex')) {
1540 computeWeekdaysParse
.call(this);
1543 return this._weekdaysStrictRegex
;
1545 return this._weekdaysRegex
;
1548 if (!hasOwnProp(this, '_weekdaysRegex')) {
1549 this._weekdaysRegex
= defaultWeekdaysRegex
;
1551 return this._weekdaysStrictRegex
&& isStrict
?
1552 this._weekdaysStrictRegex
: this._weekdaysRegex
;
1556 var defaultWeekdaysShortRegex
= matchWord
;
1557 function weekdaysShortRegex (isStrict
) {
1558 if (this._weekdaysParseExact
) {
1559 if (!hasOwnProp(this, '_weekdaysRegex')) {
1560 computeWeekdaysParse
.call(this);
1563 return this._weekdaysShortStrictRegex
;
1565 return this._weekdaysShortRegex
;
1568 if (!hasOwnProp(this, '_weekdaysShortRegex')) {
1569 this._weekdaysShortRegex
= defaultWeekdaysShortRegex
;
1571 return this._weekdaysShortStrictRegex
&& isStrict
?
1572 this._weekdaysShortStrictRegex
: this._weekdaysShortRegex
;
1576 var defaultWeekdaysMinRegex
= matchWord
;
1577 function weekdaysMinRegex (isStrict
) {
1578 if (this._weekdaysParseExact
) {
1579 if (!hasOwnProp(this, '_weekdaysRegex')) {
1580 computeWeekdaysParse
.call(this);
1583 return this._weekdaysMinStrictRegex
;
1585 return this._weekdaysMinRegex
;
1588 if (!hasOwnProp(this, '_weekdaysMinRegex')) {
1589 this._weekdaysMinRegex
= defaultWeekdaysMinRegex
;
1591 return this._weekdaysMinStrictRegex
&& isStrict
?
1592 this._weekdaysMinStrictRegex
: this._weekdaysMinRegex
;
1597 function computeWeekdaysParse () {
1598 function cmpLenRev(a
, b
) {
1599 return b
.length
- a
.length
;
1602 var minPieces
= [], shortPieces
= [], longPieces
= [], mixedPieces
= [],
1603 i
, mom
, minp
, shortp
, longp
;
1604 for (i
= 0; i
< 7; i
++) {
1605 // make the regex if we don't have it already
1606 mom
= createUTC([2000, 1]).day(i
);
1607 minp
= this.weekdaysMin(mom
, '');
1608 shortp
= this.weekdaysShort(mom
, '');
1609 longp
= this.weekdays(mom
, '');
1610 minPieces
.push(minp
);
1611 shortPieces
.push(shortp
);
1612 longPieces
.push(longp
);
1613 mixedPieces
.push(minp
);
1614 mixedPieces
.push(shortp
);
1615 mixedPieces
.push(longp
);
1617 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
1618 // will match the longer piece.
1619 minPieces
.sort(cmpLenRev
);
1620 shortPieces
.sort(cmpLenRev
);
1621 longPieces
.sort(cmpLenRev
);
1622 mixedPieces
.sort(cmpLenRev
);
1623 for (i
= 0; i
< 7; i
++) {
1624 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1625 longPieces
[i
] = regexEscape(longPieces
[i
]);
1626 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1629 this._weekdaysRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1630 this._weekdaysShortRegex
= this._weekdaysRegex
;
1631 this._weekdaysMinRegex
= this._weekdaysRegex
;
1633 this._weekdaysStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1634 this._weekdaysShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1635 this._weekdaysMinStrictRegex
= new RegExp('^(' + minPieces
.join('|') + ')', 'i');
1640 function hFormat() {
1641 return this.hours() % 12 || 12;
1644 function kFormat() {
1645 return this.hours() || 24;
1648 addFormatToken('H', ['HH', 2], 0, 'hour');
1649 addFormatToken('h', ['hh', 2], 0, hFormat
);
1650 addFormatToken('k', ['kk', 2], 0, kFormat
);
1652 addFormatToken('hmm', 0, 0, function () {
1653 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2);
1656 addFormatToken('hmmss', 0, 0, function () {
1657 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2) +
1658 zeroFill(this.seconds(), 2);
1661 addFormatToken('Hmm', 0, 0, function () {
1662 return '' + this.hours() + zeroFill(this.minutes(), 2);
1665 addFormatToken('Hmmss', 0, 0, function () {
1666 return '' + this.hours() + zeroFill(this.minutes(), 2) +
1667 zeroFill(this.seconds(), 2);
1670 function meridiem (token
, lowercase
) {
1671 addFormatToken(token
, 0, 0, function () {
1672 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase
);
1676 meridiem('a', true);
1677 meridiem('A', false);
1681 addUnitAlias('hour', 'h');
1684 addUnitPriority('hour', 13);
1688 function matchMeridiem (isStrict
, locale
) {
1689 return locale
._meridiemParse
;
1692 addRegexToken('a', matchMeridiem
);
1693 addRegexToken('A', matchMeridiem
);
1694 addRegexToken('H', match1to2
);
1695 addRegexToken('h', match1to2
);
1696 addRegexToken('k', match1to2
);
1697 addRegexToken('HH', match1to2
, match2
);
1698 addRegexToken('hh', match1to2
, match2
);
1699 addRegexToken('kk', match1to2
, match2
);
1701 addRegexToken('hmm', match3to4
);
1702 addRegexToken('hmmss', match5to6
);
1703 addRegexToken('Hmm', match3to4
);
1704 addRegexToken('Hmmss', match5to6
);
1706 addParseToken(['H', 'HH'], HOUR
);
1707 addParseToken(['k', 'kk'], function (input
, array
, config
) {
1708 var kInput
= toInt(input
);
1709 array
[HOUR
] = kInput
=== 24 ? 0 : kInput
;
1711 addParseToken(['a', 'A'], function (input
, array
, config
) {
1712 config
._isPm
= config
._locale
.isPM(input
);
1713 config
._meridiem
= input
;
1715 addParseToken(['h', 'hh'], function (input
, array
, config
) {
1716 array
[HOUR
] = toInt(input
);
1717 getParsingFlags(config
).bigHour
= true;
1719 addParseToken('hmm', function (input
, array
, config
) {
1720 var pos
= input
.length
- 2;
1721 array
[HOUR
] = toInt(input
.substr(0, pos
));
1722 array
[MINUTE
] = toInt(input
.substr(pos
));
1723 getParsingFlags(config
).bigHour
= true;
1725 addParseToken('hmmss', function (input
, array
, config
) {
1726 var pos1
= input
.length
- 4;
1727 var pos2
= input
.length
- 2;
1728 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1729 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1730 array
[SECOND
] = toInt(input
.substr(pos2
));
1731 getParsingFlags(config
).bigHour
= true;
1733 addParseToken('Hmm', function (input
, array
, config
) {
1734 var pos
= input
.length
- 2;
1735 array
[HOUR
] = toInt(input
.substr(0, pos
));
1736 array
[MINUTE
] = toInt(input
.substr(pos
));
1738 addParseToken('Hmmss', function (input
, array
, config
) {
1739 var pos1
= input
.length
- 4;
1740 var pos2
= input
.length
- 2;
1741 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1742 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1743 array
[SECOND
] = toInt(input
.substr(pos2
));
1748 function localeIsPM (input
) {
1749 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
1750 // Using charAt should be more compatible.
1751 return ((input
+ '').toLowerCase().charAt(0) === 'p');
1754 var defaultLocaleMeridiemParse
= /[ap]\.?m?\.?/i;
1755 function localeMeridiem (hours
, minutes
, isLower
) {
1757 return isLower
? 'pm' : 'PM';
1759 return isLower
? 'am' : 'AM';
1766 // Setting the hour should keep the time, because the user explicitly
1767 // specified which hour they want. So trying to maintain the same hour (in
1768 // a new timezone) makes sense. Adding/subtracting hours does not follow
1770 var getSetHour
= makeGetSet('Hours', true);
1773 calendar
: defaultCalendar
,
1774 longDateFormat
: defaultLongDateFormat
,
1775 invalidDate
: defaultInvalidDate
,
1776 ordinal
: defaultOrdinal
,
1777 dayOfMonthOrdinalParse
: defaultDayOfMonthOrdinalParse
,
1778 relativeTime
: defaultRelativeTime
,
1780 months
: defaultLocaleMonths
,
1781 monthsShort
: defaultLocaleMonthsShort
,
1783 week
: defaultLocaleWeek
,
1785 weekdays
: defaultLocaleWeekdays
,
1786 weekdaysMin
: defaultLocaleWeekdaysMin
,
1787 weekdaysShort
: defaultLocaleWeekdaysShort
,
1789 meridiemParse
: defaultLocaleMeridiemParse
1792 // internal storage for locale config files
1794 var localeFamilies
= {};
1797 function normalizeLocale(key
) {
1798 return key
? key
.toLowerCase().replace('_', '-') : key
;
1801 // pick the locale from the array
1802 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
1803 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
1804 function chooseLocale(names
) {
1805 var i
= 0, j
, next
, locale
, split
;
1807 while (i
< names
.length
) {
1808 split
= normalizeLocale(names
[i
]).split('-');
1810 next
= normalizeLocale(names
[i
+ 1]);
1811 next
= next
? next
.split('-') : null;
1813 locale
= loadLocale(split
.slice(0, j
).join('-'));
1817 if (next
&& next
.length
>= j
&& compareArrays(split
, next
, true) >= j
- 1) {
1818 //the next array item is better than a shallower substring of this one
1825 return globalLocale
;
1828 function loadLocale(name
) {
1829 var oldLocale
= null;
1830 // TODO: Find a better way to register and load all the locales in Node
1831 if (!locales
[name
] && (typeof module
!== 'undefined') &&
1832 module
&& module
.exports
) {
1834 oldLocale
= globalLocale
._abbr
;
1835 var aliasedRequire
= require
;
1836 aliasedRequire('./locale/' + name
);
1837 getSetGlobalLocale(oldLocale
);
1840 return locales
[name
];
1843 // This function will load locale and then set the global locale. If
1844 // no arguments are passed in, it will simply return the current global
1846 function getSetGlobalLocale (key
, values
) {
1849 if (isUndefined(values
)) {
1850 data
= getLocale(key
);
1853 data
= defineLocale(key
, values
);
1857 // moment.duration._locale = moment._locale = data;
1858 globalLocale
= data
;
1861 if ((typeof console
!== 'undefined') && console
.warn
) {
1862 //warn user if arguments are passed but the locale could not be set
1863 console
.warn('Locale ' + key
+ ' not found. Did you forget to load it?');
1868 return globalLocale
._abbr
;
1871 function defineLocale (name
, config
) {
1872 if (config
!== null) {
1873 var locale
, parentConfig
= baseConfig
;
1875 if (locales
[name
] != null) {
1876 deprecateSimple('defineLocaleOverride',
1877 'use moment.updateLocale(localeName, config) to change ' +
1878 'an existing locale. moment.defineLocale(localeName, ' +
1879 'config) should only be used for creating a new locale ' +
1880 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
1881 parentConfig
= locales
[name
]._config
;
1882 } else if (config
.parentLocale
!= null) {
1883 if (locales
[config
.parentLocale
] != null) {
1884 parentConfig
= locales
[config
.parentLocale
]._config
;
1886 locale
= loadLocale(config
.parentLocale
);
1887 if (locale
!= null) {
1888 parentConfig
= locale
._config
;
1890 if (!localeFamilies
[config
.parentLocale
]) {
1891 localeFamilies
[config
.parentLocale
] = [];
1893 localeFamilies
[config
.parentLocale
].push({
1901 locales
[name
] = new Locale(mergeConfigs(parentConfig
, config
));
1903 if (localeFamilies
[name
]) {
1904 localeFamilies
[name
].forEach(function (x
) {
1905 defineLocale(x
.name
, x
.config
);
1909 // backwards compat for now: also set the locale
1910 // make sure we set the locale AFTER all child locales have been
1911 // created, so we won't end up with the child locale set.
1912 getSetGlobalLocale(name
);
1915 return locales
[name
];
1917 // useful for testing
1918 delete locales
[name
];
1923 function updateLocale(name
, config
) {
1924 if (config
!= null) {
1925 var locale
, tmpLocale
, parentConfig
= baseConfig
;
1927 tmpLocale
= loadLocale(name
);
1928 if (tmpLocale
!= null) {
1929 parentConfig
= tmpLocale
._config
;
1931 config
= mergeConfigs(parentConfig
, config
);
1932 locale
= new Locale(config
);
1933 locale
.parentLocale
= locales
[name
];
1934 locales
[name
] = locale
;
1936 // backwards compat for now: also set the locale
1937 getSetGlobalLocale(name
);
1939 // pass null for config to unupdate, useful for tests
1940 if (locales
[name
] != null) {
1941 if (locales
[name
].parentLocale
!= null) {
1942 locales
[name
] = locales
[name
].parentLocale
;
1943 } else if (locales
[name
] != null) {
1944 delete locales
[name
];
1948 return locales
[name
];
1951 // returns locale data
1952 function getLocale (key
) {
1955 if (key
&& key
._locale
&& key
._locale
._abbr
) {
1956 key
= key
._locale
._abbr
;
1960 return globalLocale
;
1963 if (!isArray(key
)) {
1964 //short-circuit everything else
1965 locale
= loadLocale(key
);
1972 return chooseLocale(key
);
1975 function listLocales() {
1976 return keys(locales
);
1979 function checkOverflow (m
) {
1983 if (a
&& getParsingFlags(m
).overflow
=== -2) {
1985 a
[MONTH
] < 0 || a
[MONTH
] > 11 ? MONTH
:
1986 a
[DATE
] < 1 || a
[DATE
] > daysInMonth(a
[YEAR
], a
[MONTH
]) ? DATE
:
1987 a
[HOUR
] < 0 || a
[HOUR
] > 24 || (a
[HOUR
] === 24 && (a
[MINUTE
] !== 0 || a
[SECOND
] !== 0 || a
[MILLISECOND
] !== 0)) ? HOUR
:
1988 a
[MINUTE
] < 0 || a
[MINUTE
] > 59 ? MINUTE
:
1989 a
[SECOND
] < 0 || a
[SECOND
] > 59 ? SECOND
:
1990 a
[MILLISECOND
] < 0 || a
[MILLISECOND
] > 999 ? MILLISECOND
:
1993 if (getParsingFlags(m
)._overflowDayOfYear
&& (overflow
< YEAR
|| overflow
> DATE
)) {
1996 if (getParsingFlags(m
)._overflowWeeks
&& overflow
=== -1) {
1999 if (getParsingFlags(m
)._overflowWeekday
&& overflow
=== -1) {
2003 getParsingFlags(m
).overflow
= overflow
;
2009 // Pick the first defined of two or three arguments.
2010 function defaults(a
, b
, c
) {
2020 function currentDateArray(config
) {
2021 // hooks is actually the exported moment object
2022 var nowValue
= new Date(hooks
.now());
2023 if (config
._useUTC
) {
2024 return [nowValue
.getUTCFullYear(), nowValue
.getUTCMonth(), nowValue
.getUTCDate()];
2026 return [nowValue
.getFullYear(), nowValue
.getMonth(), nowValue
.getDate()];
2029 // convert an array to a date.
2030 // the array should mirror the parameters below
2031 // note: all values past the year are optional and will default to the lowest possible value.
2032 // [year, month, day , hour, minute, second, millisecond]
2033 function configFromArray (config
) {
2034 var i
, date
, input
= [], currentDate
, expectedWeekday
, yearToUse
;
2040 currentDate
= currentDateArray(config
);
2042 //compute day of the year from weeks and weekdays
2043 if (config
._w
&& config
._a
[DATE
] == null && config
._a
[MONTH
] == null) {
2044 dayOfYearFromWeekInfo(config
);
2047 //if the day of the year is set, figure out what it is
2048 if (config
._dayOfYear
!= null) {
2049 yearToUse
= defaults(config
._a
[YEAR
], currentDate
[YEAR
]);
2051 if (config
._dayOfYear
> daysInYear(yearToUse
) || config
._dayOfYear
=== 0) {
2052 getParsingFlags(config
)._overflowDayOfYear
= true;
2055 date
= createUTCDate(yearToUse
, 0, config
._dayOfYear
);
2056 config
._a
[MONTH
] = date
.getUTCMonth();
2057 config
._a
[DATE
] = date
.getUTCDate();
2060 // Default to current date.
2061 // * if no year, month, day of month are given, default to today
2062 // * if day of month is given, default month and year
2063 // * if month is given, default only year
2064 // * if year is given, don't default anything
2065 for (i
= 0; i
< 3 && config
._a
[i
] == null; ++i
) {
2066 config
._a
[i
] = input
[i
] = currentDate
[i
];
2069 // Zero out whatever was not defaulted, including time
2070 for (; i
< 7; i
++) {
2071 config
._a
[i
] = input
[i
] = (config
._a
[i
] == null) ? (i
=== 2 ? 1 : 0) : config
._a
[i
];
2074 // Check for 24:00:00.000
2075 if (config
._a
[HOUR
] === 24 &&
2076 config
._a
[MINUTE
] === 0 &&
2077 config
._a
[SECOND
] === 0 &&
2078 config
._a
[MILLISECOND
] === 0) {
2079 config
._nextDay
= true;
2080 config
._a
[HOUR
] = 0;
2083 config
._d
= (config
._useUTC
? createUTCDate
: createDate
).apply(null, input
);
2084 expectedWeekday
= config
._useUTC
? config
._d
.getUTCDay() : config
._d
.getDay();
2086 // Apply timezone offset from input. The actual utcOffset can be changed
2088 if (config
._tzm
!= null) {
2089 config
._d
.setUTCMinutes(config
._d
.getUTCMinutes() - config
._tzm
);
2092 if (config
._nextDay
) {
2093 config
._a
[HOUR
] = 24;
2096 // check for mismatching day of week
2097 if (config
._w
&& typeof config
._w
.d
!== 'undefined' && config
._w
.d
!== expectedWeekday
) {
2098 getParsingFlags(config
).weekdayMismatch
= true;
2102 function dayOfYearFromWeekInfo(config
) {
2103 var w
, weekYear
, week
, weekday
, dow
, doy
, temp
, weekdayOverflow
;
2106 if (w
.GG
!= null || w
.W
!= null || w
.E
!= null) {
2110 // TODO: We need to take the current isoWeekYear, but that depends on
2111 // how we interpret now (local, utc, fixed offset). So create
2112 // a now version of current config (take local/utc/offset flags, and
2114 weekYear
= defaults(w
.GG
, config
._a
[YEAR
], weekOfYear(createLocal(), 1, 4).year
);
2115 week
= defaults(w
.W
, 1);
2116 weekday
= defaults(w
.E
, 1);
2117 if (weekday
< 1 || weekday
> 7) {
2118 weekdayOverflow
= true;
2121 dow
= config
._locale
._week
.dow
;
2122 doy
= config
._locale
._week
.doy
;
2124 var curWeek
= weekOfYear(createLocal(), dow
, doy
);
2126 weekYear
= defaults(w
.gg
, config
._a
[YEAR
], curWeek
.year
);
2128 // Default to current week.
2129 week
= defaults(w
.w
, curWeek
.week
);
2132 // weekday -- low day numbers are considered next week
2134 if (weekday
< 0 || weekday
> 6) {
2135 weekdayOverflow
= true;
2137 } else if (w
.e
!= null) {
2138 // local weekday -- counting starts from begining of week
2139 weekday
= w
.e
+ dow
;
2140 if (w
.e
< 0 || w
.e
> 6) {
2141 weekdayOverflow
= true;
2144 // default to begining of week
2148 if (week
< 1 || week
> weeksInYear(weekYear
, dow
, doy
)) {
2149 getParsingFlags(config
)._overflowWeeks
= true;
2150 } else if (weekdayOverflow
!= null) {
2151 getParsingFlags(config
)._overflowWeekday
= true;
2153 temp
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
);
2154 config
._a
[YEAR
] = temp
.year
;
2155 config
._dayOfYear
= temp
.dayOfYear
;
2160 // 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)
2161 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)?)?$/;
2162 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)?)?$/;
2164 var tzRegex
= /Z|[+-]\d\d(?::?\d\d)?/;
2167 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
2168 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
2169 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
2170 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
2171 ['YYYY-DDD', /\d{4}-\d{3}/],
2172 ['YYYY-MM', /\d{4}-\d\d/, false],
2173 ['YYYYYYMMDD', /[+-]\d{10}/],
2174 ['YYYYMMDD', /\d{8}/],
2175 // YYYYMM is NOT allowed by the standard
2176 ['GGGG[W]WWE', /\d{4}W\d{3}/],
2177 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
2178 ['YYYYDDD', /\d{7}/]
2181 // iso time formats and regexes
2183 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
2184 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
2185 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
2186 ['HH:mm', /\d\d:\d\d/],
2187 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
2188 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
2189 ['HHmmss', /\d\d\d\d\d\d/],
2190 ['HHmm', /\d\d\d\d/],
2194 var aspNetJsonRegex
= /^\/?Date\((\-?\d+)/i;
2196 // date from iso format
2197 function configFromISO(config
) {
2200 match
= extendedIsoRegex
.exec(string
) || basicIsoRegex
.exec(string
),
2201 allowTime
, dateFormat
, timeFormat
, tzFormat
;
2204 getParsingFlags(config
).iso
= true;
2206 for (i
= 0, l
= isoDates
.length
; i
< l
; i
++) {
2207 if (isoDates
[i
][1].exec(match
[1])) {
2208 dateFormat
= isoDates
[i
][0];
2209 allowTime
= isoDates
[i
][2] !== false;
2213 if (dateFormat
== null) {
2214 config
._isValid
= false;
2218 for (i
= 0, l
= isoTimes
.length
; i
< l
; i
++) {
2219 if (isoTimes
[i
][1].exec(match
[3])) {
2220 // match[2] should be 'T' or space
2221 timeFormat
= (match
[2] || ' ') + isoTimes
[i
][0];
2225 if (timeFormat
== null) {
2226 config
._isValid
= false;
2230 if (!allowTime
&& timeFormat
!= null) {
2231 config
._isValid
= false;
2235 if (tzRegex
.exec(match
[4])) {
2238 config
._isValid
= false;
2242 config
._f
= dateFormat
+ (timeFormat
|| '') + (tzFormat
|| '');
2243 configFromStringAndFormat(config
);
2245 config
._isValid
= false;
2249 // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
2250 var rfc2822
= /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/;
2252 function extractFromRFC2822Strings(yearStr
, monthStr
, dayStr
, hourStr
, minuteStr
, secondStr
) {
2254 untruncateYear(yearStr
),
2255 defaultLocaleMonthsShort
.indexOf(monthStr
),
2256 parseInt(dayStr
, 10),
2257 parseInt(hourStr
, 10),
2258 parseInt(minuteStr
, 10)
2262 result
.push(parseInt(secondStr
, 10));
2268 function untruncateYear(yearStr
) {
2269 var year
= parseInt(yearStr
, 10);
2272 } else if (year
<= 999) {
2278 function preprocessRFC2822(s
) {
2279 // Remove comments and folding whitespace and replace multiple-spaces with a single space
2280 return s
.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
2283 function checkWeekday(weekdayStr
, parsedInput
, config
) {
2285 // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
2286 var weekdayProvided
= defaultLocaleWeekdaysShort
.indexOf(weekdayStr
),
2287 weekdayActual
= new Date(parsedInput
[0], parsedInput
[1], parsedInput
[2]).getDay();
2288 if (weekdayProvided
!== weekdayActual
) {
2289 getParsingFlags(config
).weekdayMismatch
= true;
2290 config
._isValid
= false;
2310 function calculateOffset(obsOffset
, militaryOffset
, numOffset
) {
2312 return obsOffsets
[obsOffset
];
2313 } else if (militaryOffset
) {
2314 // the only allowed military tz is Z
2317 var hm
= parseInt(numOffset
, 10);
2318 var m
= hm
% 100, h
= (hm
- m
) / 100;
2323 // date and time from ref 2822 format
2324 function configFromRFC2822(config
) {
2325 var match
= rfc2822
.exec(preprocessRFC2822(config
._i
));
2327 var parsedArray
= extractFromRFC2822Strings(match
[4], match
[3], match
[2], match
[5], match
[6], match
[7]);
2328 if (!checkWeekday(match
[1], parsedArray
, config
)) {
2332 config
._a
= parsedArray
;
2333 config
._tzm
= calculateOffset(match
[8], match
[9], match
[10]);
2335 config
._d
= createUTCDate
.apply(null, config
._a
);
2336 config
._d
.setUTCMinutes(config
._d
.getUTCMinutes() - config
._tzm
);
2338 getParsingFlags(config
).rfc2822
= true;
2340 config
._isValid
= false;
2344 // date from iso format or fallback
2345 function configFromString(config
) {
2346 var matched
= aspNetJsonRegex
.exec(config
._i
);
2348 if (matched
!== null) {
2349 config
._d
= new Date(+matched
[1]);
2353 configFromISO(config
);
2354 if (config
._isValid
=== false) {
2355 delete config
._isValid
;
2360 configFromRFC2822(config
);
2361 if (config
._isValid
=== false) {
2362 delete config
._isValid
;
2367 // Final attempt, use Input Fallback
2368 hooks
.createFromInputFallback(config
);
2371 hooks
.createFromInputFallback
= deprecate(
2372 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
2373 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
2374 'discouraged and will be removed in an upcoming major release. Please refer to ' +
2375 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
2377 config
._d
= new Date(config
._i
+ (config
._useUTC
? ' UTC' : ''));
2381 // constant that refers to the ISO standard
2382 hooks
.ISO_8601 = function () {};
2384 // constant that refers to the RFC 2822 form
2385 hooks
.RFC_2822 = function () {};
2387 // date from string and format string
2388 function configFromStringAndFormat(config
) {
2389 // TODO: Move this to another part of the creation flow to prevent circular deps
2390 if (config
._f
=== hooks
.ISO_8601
) {
2391 configFromISO(config
);
2394 if (config
._f
=== hooks
.RFC_2822
) {
2395 configFromRFC2822(config
);
2399 getParsingFlags(config
).empty
= true;
2401 // This array is used to make a Date, either with `new Date` or `Date.UTC`
2402 var string
= '' + config
._i
,
2403 i
, parsedInput
, tokens
, token
, skipped
,
2404 stringLength
= string
.length
,
2405 totalParsedInputLength
= 0;
2407 tokens
= expandFormat(config
._f
, config
._locale
).match(formattingTokens
) || [];
2409 for (i
= 0; i
< tokens
.length
; i
++) {
2411 parsedInput
= (string
.match(getParseRegexForToken(token
, config
)) || [])[0];
2412 // console.log('token', token, 'parsedInput', parsedInput,
2413 // 'regex', getParseRegexForToken(token, config));
2415 skipped
= string
.substr(0, string
.indexOf(parsedInput
));
2416 if (skipped
.length
> 0) {
2417 getParsingFlags(config
).unusedInput
.push(skipped
);
2419 string
= string
.slice(string
.indexOf(parsedInput
) + parsedInput
.length
);
2420 totalParsedInputLength
+= parsedInput
.length
;
2422 // don't parse if it's not a known token
2423 if (formatTokenFunctions
[token
]) {
2425 getParsingFlags(config
).empty
= false;
2428 getParsingFlags(config
).unusedTokens
.push(token
);
2430 addTimeToArrayFromToken(token
, parsedInput
, config
);
2432 else if (config
._strict
&& !parsedInput
) {
2433 getParsingFlags(config
).unusedTokens
.push(token
);
2437 // add remaining unparsed input length to the string
2438 getParsingFlags(config
).charsLeftOver
= stringLength
- totalParsedInputLength
;
2439 if (string
.length
> 0) {
2440 getParsingFlags(config
).unusedInput
.push(string
);
2443 // clear _12h flag if hour is <= 12
2444 if (config
._a
[HOUR
] <= 12 &&
2445 getParsingFlags(config
).bigHour
=== true &&
2446 config
._a
[HOUR
] > 0) {
2447 getParsingFlags(config
).bigHour
= undefined;
2450 getParsingFlags(config
).parsedDateParts
= config
._a
.slice(0);
2451 getParsingFlags(config
).meridiem
= config
._meridiem
;
2453 config
._a
[HOUR
] = meridiemFixWrap(config
._locale
, config
._a
[HOUR
], config
._meridiem
);
2455 configFromArray(config
);
2456 checkOverflow(config
);
2460 function meridiemFixWrap (locale
, hour
, meridiem
) {
2463 if (meridiem
== null) {
2467 if (locale
.meridiemHour
!= null) {
2468 return locale
.meridiemHour(hour
, meridiem
);
2469 } else if (locale
.isPM
!= null) {
2471 isPm
= locale
.isPM(meridiem
);
2472 if (isPm
&& hour
< 12) {
2475 if (!isPm
&& hour
=== 12) {
2480 // this is not supposed to happen
2485 // date from string and array of format strings
2486 function configFromStringAndArray(config
) {
2494 if (config
._f
.length
=== 0) {
2495 getParsingFlags(config
).invalidFormat
= true;
2496 config
._d
= new Date(NaN
);
2500 for (i
= 0; i
< config
._f
.length
; i
++) {
2502 tempConfig
= copyConfig({}, config
);
2503 if (config
._useUTC
!= null) {
2504 tempConfig
._useUTC
= config
._useUTC
;
2506 tempConfig
._f
= config
._f
[i
];
2507 configFromStringAndFormat(tempConfig
);
2509 if (!isValid(tempConfig
)) {
2513 // if there is any input that was not parsed add a penalty for that format
2514 currentScore
+= getParsingFlags(tempConfig
).charsLeftOver
;
2517 currentScore
+= getParsingFlags(tempConfig
).unusedTokens
.length
* 10;
2519 getParsingFlags(tempConfig
).score
= currentScore
;
2521 if (scoreToBeat
== null || currentScore
< scoreToBeat
) {
2522 scoreToBeat
= currentScore
;
2523 bestMoment
= tempConfig
;
2527 extend(config
, bestMoment
|| tempConfig
);
2530 function configFromObject(config
) {
2535 var i
= normalizeObjectUnits(config
._i
);
2536 config
._a
= map([i
.year
, i
.month
, i
.day
|| i
.date
, i
.hour
, i
.minute
, i
.second
, i
.millisecond
], function (obj
) {
2537 return obj
&& parseInt(obj
, 10);
2540 configFromArray(config
);
2543 function createFromConfig (config
) {
2544 var res
= new Moment(checkOverflow(prepareConfig(config
)));
2546 // Adding is smart enough around DST
2548 res
._nextDay
= undefined;
2554 function prepareConfig (config
) {
2555 var input
= config
._i
,
2558 config
._locale
= config
._locale
|| getLocale(config
._l
);
2560 if (input
=== null || (format
=== undefined && input
=== '')) {
2561 return createInvalid({nullInput
: true});
2564 if (typeof input
=== 'string') {
2565 config
._i
= input
= config
._locale
.preparse(input
);
2568 if (isMoment(input
)) {
2569 return new Moment(checkOverflow(input
));
2570 } else if (isDate(input
)) {
2572 } else if (isArray(format
)) {
2573 configFromStringAndArray(config
);
2574 } else if (format
) {
2575 configFromStringAndFormat(config
);
2577 configFromInput(config
);
2580 if (!isValid(config
)) {
2587 function configFromInput(config
) {
2588 var input
= config
._i
;
2589 if (isUndefined(input
)) {
2590 config
._d
= new Date(hooks
.now());
2591 } else if (isDate(input
)) {
2592 config
._d
= new Date(input
.valueOf());
2593 } else if (typeof input
=== 'string') {
2594 configFromString(config
);
2595 } else if (isArray(input
)) {
2596 config
._a
= map(input
.slice(0), function (obj
) {
2597 return parseInt(obj
, 10);
2599 configFromArray(config
);
2600 } else if (isObject(input
)) {
2601 configFromObject(config
);
2602 } else if (isNumber(input
)) {
2603 // from milliseconds
2604 config
._d
= new Date(input
);
2606 hooks
.createFromInputFallback(config
);
2610 function createLocalOrUTC (input
, format
, locale
, strict
, isUTC
) {
2613 if (locale
=== true || locale
=== false) {
2618 if ((isObject(input
) && isObjectEmpty(input
)) ||
2619 (isArray(input
) && input
.length
=== 0)) {
2622 // object construction must be done this way.
2623 // https://github.com/moment/moment/issues/1423
2624 c
._isAMomentObject
= true;
2625 c
._useUTC
= c
._isUTC
= isUTC
;
2631 return createFromConfig(c
);
2634 function createLocal (input
, format
, locale
, strict
) {
2635 return createLocalOrUTC(input
, format
, locale
, strict
, false);
2638 var prototypeMin
= deprecate(
2639 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
2641 var other
= createLocal
.apply(null, arguments
);
2642 if (this.isValid() && other
.isValid()) {
2643 return other
< this ? this : other
;
2645 return createInvalid();
2650 var prototypeMax
= deprecate(
2651 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
2653 var other
= createLocal
.apply(null, arguments
);
2654 if (this.isValid() && other
.isValid()) {
2655 return other
> this ? this : other
;
2657 return createInvalid();
2662 // Pick a moment m from moments so that m[fn](other) is true for all
2663 // other. This relies on the function fn to be transitive.
2665 // moments should either be an array of moment objects or an array, whose
2666 // first element is an array of moment objects.
2667 function pickBy(fn
, moments
) {
2669 if (moments
.length
=== 1 && isArray(moments
[0])) {
2670 moments
= moments
[0];
2672 if (!moments
.length
) {
2673 return createLocal();
2676 for (i
= 1; i
< moments
.length
; ++i
) {
2677 if (!moments
[i
].isValid() || moments
[i
][fn
](res
)) {
2684 // TODO: Use [].sort instead?
2686 var args
= [].slice
.call(arguments
, 0);
2688 return pickBy('isBefore', args
);
2692 var args
= [].slice
.call(arguments
, 0);
2694 return pickBy('isAfter', args
);
2697 var now = function () {
2698 return Date
.now
? Date
.now() : +(new Date());
2701 var ordering
= ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
2703 function isDurationValid(m
) {
2704 for (var key
in m
) {
2705 if (!(indexOf
.call(ordering
, key
) !== -1 && (m
[key
] == null || !isNaN(m
[key
])))) {
2710 var unitHasDecimal
= false;
2711 for (var i
= 0; i
< ordering
.length
; ++i
) {
2712 if (m
[ordering
[i
]]) {
2713 if (unitHasDecimal
) {
2714 return false; // only allow non-integers for smallest unit
2716 if (parseFloat(m
[ordering
[i
]]) !== toInt(m
[ordering
[i
]])) {
2717 unitHasDecimal
= true;
2725 function isValid
$1() {
2726 return this._isValid
;
2729 function createInvalid
$1() {
2730 return createDuration(NaN
);
2733 function Duration (duration
) {
2734 var normalizedInput
= normalizeObjectUnits(duration
),
2735 years
= normalizedInput
.year
|| 0,
2736 quarters
= normalizedInput
.quarter
|| 0,
2737 months
= normalizedInput
.month
|| 0,
2738 weeks
= normalizedInput
.week
|| 0,
2739 days
= normalizedInput
.day
|| 0,
2740 hours
= normalizedInput
.hour
|| 0,
2741 minutes
= normalizedInput
.minute
|| 0,
2742 seconds
= normalizedInput
.second
|| 0,
2743 milliseconds
= normalizedInput
.millisecond
|| 0;
2745 this._isValid
= isDurationValid(normalizedInput
);
2747 // representation for dateAddRemove
2748 this._milliseconds
= +milliseconds
+
2749 seconds
* 1e3
+ // 1000
2750 minutes
* 6e4
+ // 1000 * 60
2751 hours
* 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
2752 // Because of dateAddRemove treats 24 hours as different from a
2753 // day when working around DST, we need to store them separately
2754 this._days
= +days
+
2756 // It is impossible to translate months into days without knowing
2757 // which months you are are talking about, so we have to store
2759 this._months
= +months
+
2765 this._locale
= getLocale();
2770 function isDuration (obj
) {
2771 return obj
instanceof Duration
;
2774 function absRound (number
) {
2776 return Math
.round(-1 * number
) * -1;
2778 return Math
.round(number
);
2784 function offset (token
, separator
) {
2785 addFormatToken(token
, 0, 0, function () {
2786 var offset
= this.utcOffset();
2792 return sign
+ zeroFill(~~(offset
/ 60), 2) + separator
+ zeroFill(~~(offset
) % 60, 2);
2801 addRegexToken('Z', matchShortOffset
);
2802 addRegexToken('ZZ', matchShortOffset
);
2803 addParseToken(['Z', 'ZZ'], function (input
, array
, config
) {
2804 config
._useUTC
= true;
2805 config
._tzm
= offsetFromString(matchShortOffset
, input
);
2811 // '+10:00' > ['10', '00']
2812 // '-1530' > ['-15', '30']
2813 var chunkOffset
= /([\+\-]|\d\d)/gi;
2815 function offsetFromString(matcher
, string
) {
2816 var matches
= (string
|| '').match(matcher
);
2818 if (matches
=== null) {
2822 var chunk
= matches
[matches
.length
- 1] || [];
2823 var parts
= (chunk
+ '').match(chunkOffset
) || ['-', 0, 0];
2824 var minutes
= +(parts
[1] * 60) + toInt(parts
[2]);
2826 return minutes
=== 0 ?
2828 parts
[0] === '+' ? minutes
: -minutes
;
2831 // Return a moment from input, that is local/utc/zone equivalent to model.
2832 function cloneWithOffset(input
, model
) {
2835 res
= model
.clone();
2836 diff
= (isMoment(input
) || isDate(input
) ? input
.valueOf() : createLocal(input
).valueOf()) - res
.valueOf();
2837 // Use low-level api, because this fn is low-level api.
2838 res
._d
.setTime(res
._d
.valueOf() + diff
);
2839 hooks
.updateOffset(res
, false);
2842 return createLocal(input
).local();
2846 function getDateOffset (m
) {
2847 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
2848 // https://github.com/moment/moment/pull/1871
2849 return -Math
.round(m
._d
.getTimezoneOffset() / 15) * 15;
2854 // This function will be called whenever a moment is mutated.
2855 // It is intended to keep the offset in sync with the timezone.
2856 hooks
.updateOffset = function () {};
2860 // keepLocalTime = true means only change the timezone, without
2861 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
2862 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
2863 // +0200, so we adjust the time as needed, to be valid.
2865 // Keeping the time actually adds/subtracts (one hour)
2866 // from the actual represented time. That is why we call updateOffset
2867 // a second time. In case it wants us to change the offset again
2868 // _changeInProgress == true case, then we have to adjust, because
2869 // there is no such time in the given timezone.
2870 function getSetOffset (input
, keepLocalTime
, keepMinutes
) {
2871 var offset
= this._offset
|| 0,
2873 if (!this.isValid()) {
2874 return input
!= null ? this : NaN
;
2876 if (input
!= null) {
2877 if (typeof input
=== 'string') {
2878 input
= offsetFromString(matchShortOffset
, input
);
2879 if (input
=== null) {
2882 } else if (Math
.abs(input
) < 16 && !keepMinutes
) {
2885 if (!this._isUTC
&& keepLocalTime
) {
2886 localAdjust
= getDateOffset(this);
2888 this._offset
= input
;
2890 if (localAdjust
!= null) {
2891 this.add(localAdjust
, 'm');
2893 if (offset
!== input
) {
2894 if (!keepLocalTime
|| this._changeInProgress
) {
2895 addSubtract(this, createDuration(input
- offset
, 'm'), 1, false);
2896 } else if (!this._changeInProgress
) {
2897 this._changeInProgress
= true;
2898 hooks
.updateOffset(this, true);
2899 this._changeInProgress
= null;
2904 return this._isUTC
? offset
: getDateOffset(this);
2908 function getSetZone (input
, keepLocalTime
) {
2909 if (input
!= null) {
2910 if (typeof input
!== 'string') {
2914 this.utcOffset(input
, keepLocalTime
);
2918 return -this.utcOffset();
2922 function setOffsetToUTC (keepLocalTime
) {
2923 return this.utcOffset(0, keepLocalTime
);
2926 function setOffsetToLocal (keepLocalTime
) {
2928 this.utcOffset(0, keepLocalTime
);
2929 this._isUTC
= false;
2931 if (keepLocalTime
) {
2932 this.subtract(getDateOffset(this), 'm');
2938 function setOffsetToParsedOffset () {
2939 if (this._tzm
!= null) {
2940 this.utcOffset(this._tzm
, false, true);
2941 } else if (typeof this._i
=== 'string') {
2942 var tZone
= offsetFromString(matchOffset
, this._i
);
2943 if (tZone
!= null) {
2944 this.utcOffset(tZone
);
2947 this.utcOffset(0, true);
2953 function hasAlignedHourOffset (input
) {
2954 if (!this.isValid()) {
2957 input
= input
? createLocal(input
).utcOffset() : 0;
2959 return (this.utcOffset() - input
) % 60 === 0;
2962 function isDaylightSavingTime () {
2964 this.utcOffset() > this.clone().month(0).utcOffset() ||
2965 this.utcOffset() > this.clone().month(5).utcOffset()
2969 function isDaylightSavingTimeShifted () {
2970 if (!isUndefined(this._isDSTShifted
)) {
2971 return this._isDSTShifted
;
2976 copyConfig(c
, this);
2977 c
= prepareConfig(c
);
2980 var other
= c
._isUTC
? createUTC(c
._a
) : createLocal(c
._a
);
2981 this._isDSTShifted
= this.isValid() &&
2982 compareArrays(c
._a
, other
.toArray()) > 0;
2984 this._isDSTShifted
= false;
2987 return this._isDSTShifted
;
2990 function isLocal () {
2991 return this.isValid() ? !this._isUTC
: false;
2994 function isUtcOffset () {
2995 return this.isValid() ? this._isUTC
: false;
2999 return this.isValid() ? this._isUTC
&& this._offset
=== 0 : false;
3002 // ASP.NET json date format regex
3003 var aspNetRegex
= /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
3005 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
3006 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
3007 // and further modified to allow for strings containing both week and day
3008 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)?)?$/;
3010 function createDuration (input
, key
) {
3011 var duration
= input
,
3012 // matching against regexp is expensive, do it on demand
3018 if (isDuration(input
)) {
3020 ms
: input
._milliseconds
,
3024 } else if (isNumber(input
)) {
3027 duration
[key
] = input
;
3029 duration
.milliseconds
= input
;
3031 } else if (!!(match
= aspNetRegex
.exec(input
))) {
3032 sign
= (match
[1] === '-') ? -1 : 1;
3035 d
: toInt(match
[DATE
]) * sign
,
3036 h
: toInt(match
[HOUR
]) * sign
,
3037 m
: toInt(match
[MINUTE
]) * sign
,
3038 s
: toInt(match
[SECOND
]) * sign
,
3039 ms
: toInt(absRound(match
[MILLISECOND
] * 1000)) * sign
// the millisecond decimal point is included in the match
3041 } else if (!!(match
= isoRegex
.exec(input
))) {
3042 sign
= (match
[1] === '-') ? -1 : (match
[1] === '+') ? 1 : 1;
3044 y
: parseIso(match
[2], sign
),
3045 M
: parseIso(match
[3], sign
),
3046 w
: parseIso(match
[4], sign
),
3047 d
: parseIso(match
[5], sign
),
3048 h
: parseIso(match
[6], sign
),
3049 m
: parseIso(match
[7], sign
),
3050 s
: parseIso(match
[8], sign
)
3052 } else if (duration
== null) {// checks for null or undefined
3054 } else if (typeof duration
=== 'object' && ('from' in duration
|| 'to' in duration
)) {
3055 diffRes
= momentsDifference(createLocal(duration
.from), createLocal(duration
.to
));
3058 duration
.ms
= diffRes
.milliseconds
;
3059 duration
.M
= diffRes
.months
;
3062 ret
= new Duration(duration
);
3064 if (isDuration(input
) && hasOwnProp(input
, '_locale')) {
3065 ret
._locale
= input
._locale
;
3071 createDuration
.fn
= Duration
.prototype;
3072 createDuration
.invalid
= createInvalid
$1;
3074 function parseIso (inp
, sign
) {
3075 // We'd normally use ~~inp for this, but unfortunately it also
3076 // converts floats to ints.
3077 // inp may be undefined, so careful calling replace on it.
3078 var res
= inp
&& parseFloat(inp
.replace(',', '.'));
3079 // apply sign while we're at it
3080 return (isNaN(res
) ? 0 : res
) * sign
;
3083 function positiveMomentsDifference(base
, other
) {
3084 var res
= {milliseconds
: 0, months
: 0};
3086 res
.months
= other
.month() - base
.month() +
3087 (other
.year() - base
.year()) * 12;
3088 if (base
.clone().add(res
.months
, 'M').isAfter(other
)) {
3092 res
.milliseconds
= +other
- +(base
.clone().add(res
.months
, 'M'));
3097 function momentsDifference(base
, other
) {
3099 if (!(base
.isValid() && other
.isValid())) {
3100 return {milliseconds
: 0, months
: 0};
3103 other
= cloneWithOffset(other
, base
);
3104 if (base
.isBefore(other
)) {
3105 res
= positiveMomentsDifference(base
, other
);
3107 res
= positiveMomentsDifference(other
, base
);
3108 res
.milliseconds
= -res
.milliseconds
;
3109 res
.months
= -res
.months
;
3115 // TODO: remove 'name' arg after deprecation is removed
3116 function createAdder(direction
, name
) {
3117 return function (val
, period
) {
3119 //invert the arguments, but complain about it
3120 if (period
!== null && !isNaN(+period
)) {
3121 deprecateSimple(name
, 'moment().' + name
+ '(period, number) is deprecated. Please use moment().' + name
+ '(number, period). ' +
3122 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
3123 tmp
= val
; val
= period
; period
= tmp
;
3126 val
= typeof val
=== 'string' ? +val
: val
;
3127 dur
= createDuration(val
, period
);
3128 addSubtract(this, dur
, direction
);
3133 function addSubtract (mom
, duration
, isAdding
, updateOffset
) {
3134 var milliseconds
= duration
._milliseconds
,
3135 days
= absRound(duration
._days
),
3136 months
= absRound(duration
._months
);
3138 if (!mom
.isValid()) {
3143 updateOffset
= updateOffset
== null ? true : updateOffset
;
3146 setMonth(mom
, get(mom
, 'Month') + months
* isAdding
);
3149 set$1(mom
, 'Date', get(mom
, 'Date') + days
* isAdding
);
3152 mom
._d
.setTime(mom
._d
.valueOf() + milliseconds
* isAdding
);
3155 hooks
.updateOffset(mom
, days
|| months
);
3159 var add
= createAdder(1, 'add');
3160 var subtract
= createAdder(-1, 'subtract');
3162 function getCalendarFormat(myMoment
, now
) {
3163 var diff
= myMoment
.diff(now
, 'days', true);
3164 return diff
< -6 ? 'sameElse' :
3165 diff
< -1 ? 'lastWeek' :
3166 diff
< 0 ? 'lastDay' :
3167 diff
< 1 ? 'sameDay' :
3168 diff
< 2 ? 'nextDay' :
3169 diff
< 7 ? 'nextWeek' : 'sameElse';
3172 function calendar
$1 (time
, formats
) {
3173 // We want to compare the start of today, vs this.
3174 // Getting start-of-today depends on whether we're local/utc/offset or not.
3175 var now
= time
|| createLocal(),
3176 sod
= cloneWithOffset(now
, this).startOf('day'),
3177 format
= hooks
.calendarFormat(this, sod
) || 'sameElse';
3179 var output
= formats
&& (isFunction(formats
[format
]) ? formats
[format
].call(this, now
) : formats
[format
]);
3181 return this.format(output
|| this.localeData().calendar(format
, this, createLocal(now
)));
3185 return new Moment(this);
3188 function isAfter (input
, units
) {
3189 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3190 if (!(this.isValid() && localInput
.isValid())) {
3193 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3194 if (units
=== 'millisecond') {
3195 return this.valueOf() > localInput
.valueOf();
3197 return localInput
.valueOf() < this.clone().startOf(units
).valueOf();
3201 function isBefore (input
, units
) {
3202 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3203 if (!(this.isValid() && localInput
.isValid())) {
3206 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3207 if (units
=== 'millisecond') {
3208 return this.valueOf() < localInput
.valueOf();
3210 return this.clone().endOf(units
).valueOf() < localInput
.valueOf();
3214 function isBetween (from, to
, units
, inclusivity
) {
3215 inclusivity
= inclusivity
|| '()';
3216 return (inclusivity
[0] === '(' ? this.isAfter(from, units
) : !this.isBefore(from, units
)) &&
3217 (inclusivity
[1] === ')' ? this.isBefore(to
, units
) : !this.isAfter(to
, units
));
3220 function isSame (input
, units
) {
3221 var localInput
= isMoment(input
) ? input
: createLocal(input
),
3223 if (!(this.isValid() && localInput
.isValid())) {
3226 units
= normalizeUnits(units
|| 'millisecond');
3227 if (units
=== 'millisecond') {
3228 return this.valueOf() === localInput
.valueOf();
3230 inputMs
= localInput
.valueOf();
3231 return this.clone().startOf(units
).valueOf() <= inputMs
&& inputMs
<= this.clone().endOf(units
).valueOf();
3235 function isSameOrAfter (input
, units
) {
3236 return this.isSame(input
, units
) || this.isAfter(input
,units
);
3239 function isSameOrBefore (input
, units
) {
3240 return this.isSame(input
, units
) || this.isBefore(input
,units
);
3243 function diff (input
, units
, asFloat
) {
3248 if (!this.isValid()) {
3252 that
= cloneWithOffset(input
, this);
3254 if (!that
.isValid()) {
3258 zoneDelta
= (that
.utcOffset() - this.utcOffset()) * 6e4
;
3260 units
= normalizeUnits(units
);
3263 case 'year': output
= monthDiff(this, that
) / 12; break;
3264 case 'month': output
= monthDiff(this, that
); break;
3265 case 'quarter': output
= monthDiff(this, that
) / 3; break;
3266 case 'second': output
= (this - that
) / 1e3
; break; // 1000
3267 case 'minute': output
= (this - that
) / 6e4
; break; // 1000 * 60
3268 case 'hour': output
= (this - that
) / 36e5
; break; // 1000 * 60 * 60
3269 case 'day': output
= (this - that
- zoneDelta
) / 864e5
; break; // 1000 * 60 * 60 * 24, negate dst
3270 case 'week': output
= (this - that
- zoneDelta
) / 6048e5
; break; // 1000 * 60 * 60 * 24 * 7, negate dst
3271 default: output
= this - that
;
3274 return asFloat
? output
: absFloor(output
);
3277 function monthDiff (a
, b
) {
3278 // difference in months
3279 var wholeMonthDiff
= ((b
.year() - a
.year()) * 12) + (b
.month() - a
.month()),
3280 // b is in (anchor - 1 month, anchor + 1 month)
3281 anchor
= a
.clone().add(wholeMonthDiff
, 'months'),
3284 if (b
- anchor
< 0) {
3285 anchor2
= a
.clone().add(wholeMonthDiff
- 1, 'months');
3286 // linear across the month
3287 adjust
= (b
- anchor
) / (anchor
- anchor2
);
3289 anchor2
= a
.clone().add(wholeMonthDiff
+ 1, 'months');
3290 // linear across the month
3291 adjust
= (b
- anchor
) / (anchor2
- anchor
);
3294 //check for negative zero, return zero if negative zero
3295 return -(wholeMonthDiff
+ adjust
) || 0;
3298 hooks
.defaultFormat
= 'YYYY-MM-DDTHH:mm:ssZ';
3299 hooks
.defaultFormatUtc
= 'YYYY-MM-DDTHH:mm:ss[Z]';
3301 function toString () {
3302 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
3305 function toISOString(keepOffset
) {
3306 if (!this.isValid()) {
3309 var utc
= keepOffset
!== true;
3310 var m
= utc
? this.clone().utc() : this;
3311 if (m
.year() < 0 || m
.year() > 9999) {
3312 return formatMoment(m
, utc
? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ');
3314 if (isFunction(Date
.prototype.toISOString
)) {
3315 // native implementation is ~50x faster, use it when we can
3317 return this.toDate().toISOString();
3319 return new Date(this.valueOf() + this.utcOffset() * 60 * 1000).toISOString().replace('Z', formatMoment(m
, 'Z'));
3322 return formatMoment(m
, utc
? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ');
3326 * Return a human readable representation of a moment that can
3327 * also be evaluated to get a new moment which is the same
3329 * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
3331 function inspect () {
3332 if (!this.isValid()) {
3333 return 'moment.invalid(/* ' + this._i
+ ' */)';
3335 var func
= 'moment';
3337 if (!this.isLocal()) {
3338 func
= this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
3341 var prefix
= '[' + func
+ '("]';
3342 var year
= (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
3343 var datetime
= '-MM-DD[T]HH:mm:ss.SSS';
3344 var suffix
= zone
+ '[")]';
3346 return this.format(prefix
+ year
+ datetime
+ suffix
);
3349 function format (inputString
) {
3351 inputString
= this.isUtc() ? hooks
.defaultFormatUtc
: hooks
.defaultFormat
;
3353 var output
= formatMoment(this, inputString
);
3354 return this.localeData().postformat(output
);
3357 function from (time
, withoutSuffix
) {
3358 if (this.isValid() &&
3359 ((isMoment(time
) && time
.isValid()) ||
3360 createLocal(time
).isValid())) {
3361 return createDuration({to
: this, from: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3363 return this.localeData().invalidDate();
3367 function fromNow (withoutSuffix
) {
3368 return this.from(createLocal(), withoutSuffix
);
3371 function to (time
, withoutSuffix
) {
3372 if (this.isValid() &&
3373 ((isMoment(time
) && time
.isValid()) ||
3374 createLocal(time
).isValid())) {
3375 return createDuration({from: this, to
: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3377 return this.localeData().invalidDate();
3381 function toNow (withoutSuffix
) {
3382 return this.to(createLocal(), withoutSuffix
);
3385 // If passed a locale key, it will set the locale for this
3386 // instance. Otherwise, it will return the locale configuration
3387 // variables for this instance.
3388 function locale (key
) {
3391 if (key
=== undefined) {
3392 return this._locale
._abbr
;
3394 newLocaleData
= getLocale(key
);
3395 if (newLocaleData
!= null) {
3396 this._locale
= newLocaleData
;
3402 var lang
= deprecate(
3403 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
3405 if (key
=== undefined) {
3406 return this.localeData();
3408 return this.locale(key
);
3413 function localeData () {
3414 return this._locale
;
3417 function startOf (units
) {
3418 units
= normalizeUnits(units
);
3419 // the following switch intentionally omits break keywords
3420 // to utilize falling through the cases.
3442 this.milliseconds(0);
3445 // weeks are a special case
3446 if (units
=== 'week') {
3449 if (units
=== 'isoWeek') {
3453 // quarters are also special
3454 if (units
=== 'quarter') {
3455 this.month(Math
.floor(this.month() / 3) * 3);
3461 function endOf (units
) {
3462 units
= normalizeUnits(units
);
3463 if (units
=== undefined || units
=== 'millisecond') {
3467 // 'date' is an alias for 'day', so it should be considered as such.
3468 if (units
=== 'date') {
3472 return this.startOf(units
).add(1, (units
=== 'isoWeek' ? 'week' : units
)).subtract(1, 'ms');
3475 function valueOf () {
3476 return this._d
.valueOf() - ((this._offset
|| 0) * 60000);
3480 return Math
.floor(this.valueOf() / 1000);
3483 function toDate () {
3484 return new Date(this.valueOf());
3487 function toArray () {
3489 return [m
.year(), m
.month(), m
.date(), m
.hour(), m
.minute(), m
.second(), m
.millisecond()];
3492 function toObject () {
3499 minutes
: m
.minutes(),
3500 seconds
: m
.seconds(),
3501 milliseconds
: m
.milliseconds()
3505 function toJSON () {
3506 // new Date(NaN).toJSON() === null
3507 return this.isValid() ? this.toISOString() : null;
3510 function isValid
$2 () {
3511 return isValid(this);
3514 function parsingFlags () {
3515 return extend({}, getParsingFlags(this));
3518 function invalidAt () {
3519 return getParsingFlags(this).overflow
;
3522 function creationData() {
3526 locale
: this._locale
,
3528 strict
: this._strict
3534 addFormatToken(0, ['gg', 2], 0, function () {
3535 return this.weekYear() % 100;
3538 addFormatToken(0, ['GG', 2], 0, function () {
3539 return this.isoWeekYear() % 100;
3542 function addWeekYearFormatToken (token
, getter
) {
3543 addFormatToken(0, [token
, token
.length
], 0, getter
);
3546 addWeekYearFormatToken('gggg', 'weekYear');
3547 addWeekYearFormatToken('ggggg', 'weekYear');
3548 addWeekYearFormatToken('GGGG', 'isoWeekYear');
3549 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
3553 addUnitAlias('weekYear', 'gg');
3554 addUnitAlias('isoWeekYear', 'GG');
3558 addUnitPriority('weekYear', 1);
3559 addUnitPriority('isoWeekYear', 1);
3564 addRegexToken('G', matchSigned
);
3565 addRegexToken('g', matchSigned
);
3566 addRegexToken('GG', match1to2
, match2
);
3567 addRegexToken('gg', match1to2
, match2
);
3568 addRegexToken('GGGG', match1to4
, match4
);
3569 addRegexToken('gggg', match1to4
, match4
);
3570 addRegexToken('GGGGG', match1to6
, match6
);
3571 addRegexToken('ggggg', match1to6
, match6
);
3573 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input
, week
, config
, token
) {
3574 week
[token
.substr(0, 2)] = toInt(input
);
3577 addWeekParseToken(['gg', 'GG'], function (input
, week
, config
, token
) {
3578 week
[token
] = hooks
.parseTwoDigitYear(input
);
3583 function getSetWeekYear (input
) {
3584 return getSetWeekYearHelper
.call(this,
3588 this.localeData()._week
.dow
,
3589 this.localeData()._week
.doy
);
3592 function getSetISOWeekYear (input
) {
3593 return getSetWeekYearHelper
.call(this,
3594 input
, this.isoWeek(), this.isoWeekday(), 1, 4);
3597 function getISOWeeksInYear () {
3598 return weeksInYear(this.year(), 1, 4);
3601 function getWeeksInYear () {
3602 var weekInfo
= this.localeData()._week
;
3603 return weeksInYear(this.year(), weekInfo
.dow
, weekInfo
.doy
);
3606 function getSetWeekYearHelper(input
, week
, weekday
, dow
, doy
) {
3608 if (input
== null) {
3609 return weekOfYear(this, dow
, doy
).year
;
3611 weeksTarget
= weeksInYear(input
, dow
, doy
);
3612 if (week
> weeksTarget
) {
3615 return setWeekAll
.call(this, input
, week
, weekday
, dow
, doy
);
3619 function setWeekAll(weekYear
, week
, weekday
, dow
, doy
) {
3620 var dayOfYearData
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
),
3621 date
= createUTCDate(dayOfYearData
.year
, 0, dayOfYearData
.dayOfYear
);
3623 this.year(date
.getUTCFullYear());
3624 this.month(date
.getUTCMonth());
3625 this.date(date
.getUTCDate());
3631 addFormatToken('Q', 0, 'Qo', 'quarter');
3635 addUnitAlias('quarter', 'Q');
3639 addUnitPriority('quarter', 7);
3643 addRegexToken('Q', match1
);
3644 addParseToken('Q', function (input
, array
) {
3645 array
[MONTH
] = (toInt(input
) - 1) * 3;
3650 function getSetQuarter (input
) {
3651 return input
== null ? Math
.ceil((this.month() + 1) / 3) : this.month((input
- 1) * 3 + this.month() % 3);
3656 addFormatToken('D', ['DD', 2], 'Do', 'date');
3660 addUnitAlias('date', 'D');
3663 addUnitPriority('date', 9);
3667 addRegexToken('D', match1to2
);
3668 addRegexToken('DD', match1to2
, match2
);
3669 addRegexToken('Do', function (isStrict
, locale
) {
3670 // TODO: Remove "ordinalParse" fallback in next major release.
3672 (locale
._dayOfMonthOrdinalParse
|| locale
._ordinalParse
) :
3673 locale
._dayOfMonthOrdinalParseLenient
;
3676 addParseToken(['D', 'DD'], DATE
);
3677 addParseToken('Do', function (input
, array
) {
3678 array
[DATE
] = toInt(input
.match(match1to2
)[0]);
3683 var getSetDayOfMonth
= makeGetSet('Date', true);
3687 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
3691 addUnitAlias('dayOfYear', 'DDD');
3694 addUnitPriority('dayOfYear', 4);
3698 addRegexToken('DDD', match1to3
);
3699 addRegexToken('DDDD', match3
);
3700 addParseToken(['DDD', 'DDDD'], function (input
, array
, config
) {
3701 config
._dayOfYear
= toInt(input
);
3708 function getSetDayOfYear (input
) {
3709 var dayOfYear
= Math
.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
) + 1;
3710 return input
== null ? dayOfYear
: this.add((input
- dayOfYear
), 'd');
3715 addFormatToken('m', ['mm', 2], 0, 'minute');
3719 addUnitAlias('minute', 'm');
3723 addUnitPriority('minute', 14);
3727 addRegexToken('m', match1to2
);
3728 addRegexToken('mm', match1to2
, match2
);
3729 addParseToken(['m', 'mm'], MINUTE
);
3733 var getSetMinute
= makeGetSet('Minutes', false);
3737 addFormatToken('s', ['ss', 2], 0, 'second');
3741 addUnitAlias('second', 's');
3745 addUnitPriority('second', 15);
3749 addRegexToken('s', match1to2
);
3750 addRegexToken('ss', match1to2
, match2
);
3751 addParseToken(['s', 'ss'], SECOND
);
3755 var getSetSecond
= makeGetSet('Seconds', false);
3759 addFormatToken('S', 0, 0, function () {
3760 return ~~(this.millisecond() / 100);
3763 addFormatToken(0, ['SS', 2], 0, function () {
3764 return ~~(this.millisecond() / 10);
3767 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
3768 addFormatToken(0, ['SSSS', 4], 0, function () {
3769 return this.millisecond() * 10;
3771 addFormatToken(0, ['SSSSS', 5], 0, function () {
3772 return this.millisecond() * 100;
3774 addFormatToken(0, ['SSSSSS', 6], 0, function () {
3775 return this.millisecond() * 1000;
3777 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
3778 return this.millisecond() * 10000;
3780 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
3781 return this.millisecond() * 100000;
3783 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
3784 return this.millisecond() * 1000000;
3790 addUnitAlias('millisecond', 'ms');
3794 addUnitPriority('millisecond', 16);
3798 addRegexToken('S', match1to3
, match1
);
3799 addRegexToken('SS', match1to3
, match2
);
3800 addRegexToken('SSS', match1to3
, match3
);
3803 for (token
= 'SSSS'; token
.length
<= 9; token
+= 'S') {
3804 addRegexToken(token
, matchUnsigned
);
3807 function parseMs(input
, array
) {
3808 array
[MILLISECOND
] = toInt(('0.' + input
) * 1000);
3811 for (token
= 'S'; token
.length
<= 9; token
+= 'S') {
3812 addParseToken(token
, parseMs
);
3816 var getSetMillisecond
= makeGetSet('Milliseconds', false);
3820 addFormatToken('z', 0, 0, 'zoneAbbr');
3821 addFormatToken('zz', 0, 0, 'zoneName');
3825 function getZoneAbbr () {
3826 return this._isUTC
? 'UTC' : '';
3829 function getZoneName () {
3830 return this._isUTC
? 'Coordinated Universal Time' : '';
3833 var proto
= Moment
.prototype;
3836 proto
.calendar
= calendar
$1;
3837 proto
.clone
= clone
;
3839 proto
.endOf
= endOf
;
3840 proto
.format
= format
;
3842 proto
.fromNow
= fromNow
;
3844 proto
.toNow
= toNow
;
3845 proto
.get = stringGet
;
3846 proto
.invalidAt
= invalidAt
;
3847 proto
.isAfter
= isAfter
;
3848 proto
.isBefore
= isBefore
;
3849 proto
.isBetween
= isBetween
;
3850 proto
.isSame
= isSame
;
3851 proto
.isSameOrAfter
= isSameOrAfter
;
3852 proto
.isSameOrBefore
= isSameOrBefore
;
3853 proto
.isValid
= isValid
$2;
3855 proto
.locale
= locale
;
3856 proto
.localeData
= localeData
;
3857 proto
.max
= prototypeMax
;
3858 proto
.min
= prototypeMin
;
3859 proto
.parsingFlags
= parsingFlags
;
3860 proto
.set = stringSet
;
3861 proto
.startOf
= startOf
;
3862 proto
.subtract
= subtract
;
3863 proto
.toArray
= toArray
;
3864 proto
.toObject
= toObject
;
3865 proto
.toDate
= toDate
;
3866 proto
.toISOString
= toISOString
;
3867 proto
.inspect
= inspect
;
3868 proto
.toJSON
= toJSON
;
3869 proto
.toString
= toString
;
3871 proto
.valueOf
= valueOf
;
3872 proto
.creationData
= creationData
;
3873 proto
.year
= getSetYear
;
3874 proto
.isLeapYear
= getIsLeapYear
;
3875 proto
.weekYear
= getSetWeekYear
;
3876 proto
.isoWeekYear
= getSetISOWeekYear
;
3877 proto
.quarter
= proto
.quarters
= getSetQuarter
;
3878 proto
.month
= getSetMonth
;
3879 proto
.daysInMonth
= getDaysInMonth
;
3880 proto
.week
= proto
.weeks
= getSetWeek
;
3881 proto
.isoWeek
= proto
.isoWeeks
= getSetISOWeek
;
3882 proto
.weeksInYear
= getWeeksInYear
;
3883 proto
.isoWeeksInYear
= getISOWeeksInYear
;
3884 proto
.date
= getSetDayOfMonth
;
3885 proto
.day
= proto
.days
= getSetDayOfWeek
;
3886 proto
.weekday
= getSetLocaleDayOfWeek
;
3887 proto
.isoWeekday
= getSetISODayOfWeek
;
3888 proto
.dayOfYear
= getSetDayOfYear
;
3889 proto
.hour
= proto
.hours
= getSetHour
;
3890 proto
.minute
= proto
.minutes
= getSetMinute
;
3891 proto
.second
= proto
.seconds
= getSetSecond
;
3892 proto
.millisecond
= proto
.milliseconds
= getSetMillisecond
;
3893 proto
.utcOffset
= getSetOffset
;
3894 proto
.utc
= setOffsetToUTC
;
3895 proto
.local
= setOffsetToLocal
;
3896 proto
.parseZone
= setOffsetToParsedOffset
;
3897 proto
.hasAlignedHourOffset
= hasAlignedHourOffset
;
3898 proto
.isDST
= isDaylightSavingTime
;
3899 proto
.isLocal
= isLocal
;
3900 proto
.isUtcOffset
= isUtcOffset
;
3901 proto
.isUtc
= isUtc
;
3902 proto
.isUTC
= isUtc
;
3903 proto
.zoneAbbr
= getZoneAbbr
;
3904 proto
.zoneName
= getZoneName
;
3905 proto
.dates
= deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth
);
3906 proto
.months
= deprecate('months accessor is deprecated. Use month instead', getSetMonth
);
3907 proto
.years
= deprecate('years accessor is deprecated. Use year instead', getSetYear
);
3908 proto
.zone
= deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone
);
3909 proto
.isDSTShifted
= deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted
);
3911 function createUnix (input
) {
3912 return createLocal(input
* 1000);
3915 function createInZone () {
3916 return createLocal
.apply(null, arguments
).parseZone();
3919 function preParsePostFormat (string
) {
3923 var proto
$1 = Locale
.prototype;
3925 proto
$1.calendar
= calendar
;
3926 proto
$1.longDateFormat
= longDateFormat
;
3927 proto
$1.invalidDate
= invalidDate
;
3928 proto
$1.ordinal
= ordinal
;
3929 proto
$1.preparse
= preParsePostFormat
;
3930 proto
$1.postformat
= preParsePostFormat
;
3931 proto
$1.relativeTime
= relativeTime
;
3932 proto
$1.pastFuture
= pastFuture
;
3935 proto
$1.months
= localeMonths
;
3936 proto
$1.monthsShort
= localeMonthsShort
;
3937 proto
$1.monthsParse
= localeMonthsParse
;
3938 proto
$1.monthsRegex
= monthsRegex
;
3939 proto
$1.monthsShortRegex
= monthsShortRegex
;
3940 proto
$1.week
= localeWeek
;
3941 proto
$1.firstDayOfYear
= localeFirstDayOfYear
;
3942 proto
$1.firstDayOfWeek
= localeFirstDayOfWeek
;
3944 proto
$1.weekdays
= localeWeekdays
;
3945 proto
$1.weekdaysMin
= localeWeekdaysMin
;
3946 proto
$1.weekdaysShort
= localeWeekdaysShort
;
3947 proto
$1.weekdaysParse
= localeWeekdaysParse
;
3949 proto
$1.weekdaysRegex
= weekdaysRegex
;
3950 proto
$1.weekdaysShortRegex
= weekdaysShortRegex
;
3951 proto
$1.weekdaysMinRegex
= weekdaysMinRegex
;
3953 proto
$1.isPM
= localeIsPM
;
3954 proto
$1.meridiem
= localeMeridiem
;
3956 function get$1 (format
, index
, field
, setter
) {
3957 var locale
= getLocale();
3958 var utc
= createUTC().set(setter
, index
);
3959 return locale
[field
](utc
, format
);
3962 function listMonthsImpl (format
, index
, field
) {
3963 if (isNumber(format
)) {
3968 format
= format
|| '';
3970 if (index
!= null) {
3971 return get$1(format
, index
, field
, 'month');
3976 for (i
= 0; i
< 12; i
++) {
3977 out
[i
] = get$1(format
, i
, field
, 'month');
3990 function listWeekdaysImpl (localeSorted
, format
, index
, field
) {
3991 if (typeof localeSorted
=== 'boolean') {
3992 if (isNumber(format
)) {
3997 format
= format
|| '';
3999 format
= localeSorted
;
4001 localeSorted
= false;
4003 if (isNumber(format
)) {
4008 format
= format
|| '';
4011 var locale
= getLocale(),
4012 shift
= localeSorted
? locale
._week
.dow
: 0;
4014 if (index
!= null) {
4015 return get$1(format
, (index
+ shift
) % 7, field
, 'day');
4020 for (i
= 0; i
< 7; i
++) {
4021 out
[i
] = get$1(format
, (i
+ shift
) % 7, field
, 'day');
4026 function listMonths (format
, index
) {
4027 return listMonthsImpl(format
, index
, 'months');
4030 function listMonthsShort (format
, index
) {
4031 return listMonthsImpl(format
, index
, 'monthsShort');
4034 function listWeekdays (localeSorted
, format
, index
) {
4035 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdays');
4038 function listWeekdaysShort (localeSorted
, format
, index
) {
4039 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysShort');
4042 function listWeekdaysMin (localeSorted
, format
, index
) {
4043 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysMin');
4046 getSetGlobalLocale('en', {
4047 dayOfMonthOrdinalParse
: /\d{1,2}(th|st|nd|rd)/,
4048 ordinal : function (number
) {
4049 var b
= number
% 10,
4050 output
= (toInt(number
% 100 / 10) === 1) ? 'th' :
4053 (b
=== 3) ? 'rd' : 'th';
4054 return number
+ output
;
4058 // Side effect imports
4060 hooks
.lang
= deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale
);
4061 hooks
.langData
= deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale
);
4063 var mathAbs
= Math
.abs
;
4066 var data
= this._data
;
4068 this._milliseconds
= mathAbs(this._milliseconds
);
4069 this._days
= mathAbs(this._days
);
4070 this._months
= mathAbs(this._months
);
4072 data
.milliseconds
= mathAbs(data
.milliseconds
);
4073 data
.seconds
= mathAbs(data
.seconds
);
4074 data
.minutes
= mathAbs(data
.minutes
);
4075 data
.hours
= mathAbs(data
.hours
);
4076 data
.months
= mathAbs(data
.months
);
4077 data
.years
= mathAbs(data
.years
);
4082 function addSubtract
$1 (duration
, input
, value
, direction
) {
4083 var other
= createDuration(input
, value
);
4085 duration
._milliseconds
+= direction
* other
._milliseconds
;
4086 duration
._days
+= direction
* other
._days
;
4087 duration
._months
+= direction
* other
._months
;
4089 return duration
._bubble();
4092 // supports only 2.0-style add(1, 's') or add(duration)
4093 function add
$1 (input
, value
) {
4094 return addSubtract
$1(this, input
, value
, 1);
4097 // supports only 2.0-style subtract(1, 's') or subtract(duration)
4098 function subtract
$1 (input
, value
) {
4099 return addSubtract
$1(this, input
, value
, -1);
4102 function absCeil (number
) {
4104 return Math
.floor(number
);
4106 return Math
.ceil(number
);
4110 function bubble () {
4111 var milliseconds
= this._milliseconds
;
4112 var days
= this._days
;
4113 var months
= this._months
;
4114 var data
= this._data
;
4115 var seconds
, minutes
, hours
, years
, monthsFromDays
;
4117 // if we have a mix of positive and negative values, bubble down first
4118 // check: https://github.com/moment/moment/issues/2166
4119 if (!((milliseconds
>= 0 && days
>= 0 && months
>= 0) ||
4120 (milliseconds
<= 0 && days
<= 0 && months
<= 0))) {
4121 milliseconds
+= absCeil(monthsToDays(months
) + days
) * 864e5
;
4126 // The following code bubbles up values, see the tests for
4127 // examples of what that means.
4128 data
.milliseconds
= milliseconds
% 1000;
4130 seconds
= absFloor(milliseconds
/ 1000);
4131 data
.seconds
= seconds
% 60;
4133 minutes
= absFloor(seconds
/ 60);
4134 data
.minutes
= minutes
% 60;
4136 hours
= absFloor(minutes
/ 60);
4137 data
.hours
= hours
% 24;
4139 days
+= absFloor(hours
/ 24);
4141 // convert days to months
4142 monthsFromDays
= absFloor(daysToMonths(days
));
4143 months
+= monthsFromDays
;
4144 days
-= absCeil(monthsToDays(monthsFromDays
));
4146 // 12 months -> 1 year
4147 years
= absFloor(months
/ 12);
4151 data
.months
= months
;
4157 function daysToMonths (days
) {
4158 // 400 years have 146097 days (taking into account leap year rules)
4159 // 400 years have 12 months === 4800
4160 return days
* 4800 / 146097;
4163 function monthsToDays (months
) {
4164 // the reverse of daysToMonths
4165 return months
* 146097 / 4800;
4168 function as (units
) {
4169 if (!this.isValid()) {
4174 var milliseconds
= this._milliseconds
;
4176 units
= normalizeUnits(units
);
4178 if (units
=== 'month' || units
=== 'year') {
4179 days
= this._days
+ milliseconds
/ 864e5
;
4180 months
= this._months
+ daysToMonths(days
);
4181 return units
=== 'month' ? months
: months
/ 12;
4183 // handle milliseconds separately because of floating point math errors (issue #1867)
4184 days
= this._days
+ Math
.round(monthsToDays(this._months
));
4186 case 'week' : return days
/ 7 + milliseconds
/ 6048e5
;
4187 case 'day' : return days
+ milliseconds
/ 864e5
;
4188 case 'hour' : return days
* 24 + milliseconds
/ 36e5
;
4189 case 'minute' : return days
* 1440 + milliseconds
/ 6e4
;
4190 case 'second' : return days
* 86400 + milliseconds
/ 1000;
4191 // Math.floor prevents floating point math errors here
4192 case 'millisecond': return Math
.floor(days
* 864e5
) + milliseconds
;
4193 default: throw new Error('Unknown unit ' + units
);
4198 // TODO: Use this.as('ms')?
4199 function valueOf
$1 () {
4200 if (!this.isValid()) {
4204 this._milliseconds
+
4205 this._days
* 864e5
+
4206 (this._months
% 12) * 2592e6
+
4207 toInt(this._months
/ 12) * 31536e6
4211 function makeAs (alias
) {
4212 return function () {
4213 return this.as(alias
);
4217 var asMilliseconds
= makeAs('ms');
4218 var asSeconds
= makeAs('s');
4219 var asMinutes
= makeAs('m');
4220 var asHours
= makeAs('h');
4221 var asDays
= makeAs('d');
4222 var asWeeks
= makeAs('w');
4223 var asMonths
= makeAs('M');
4224 var asYears
= makeAs('y');
4226 function clone
$1 () {
4227 return createDuration(this);
4230 function get$2 (units
) {
4231 units
= normalizeUnits(units
);
4232 return this.isValid() ? this[units
+ 's']() : NaN
;
4235 function makeGetter(name
) {
4236 return function () {
4237 return this.isValid() ? this._data
[name
] : NaN
;
4241 var milliseconds
= makeGetter('milliseconds');
4242 var seconds
= makeGetter('seconds');
4243 var minutes
= makeGetter('minutes');
4244 var hours
= makeGetter('hours');
4245 var days
= makeGetter('days');
4246 var months
= makeGetter('months');
4247 var years
= makeGetter('years');
4250 return absFloor(this.days() / 7);
4253 var round
= Math
.round
;
4255 ss
: 44, // a few seconds to seconds
4256 s
: 45, // seconds to minute
4257 m
: 45, // minutes to hour
4258 h
: 22, // hours to day
4259 d
: 26, // days to month
4260 M
: 11 // months to year
4263 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
4264 function substituteTimeAgo(string
, number
, withoutSuffix
, isFuture
, locale
) {
4265 return locale
.relativeTime(number
|| 1, !!withoutSuffix
, string
, isFuture
);
4268 function relativeTime
$1 (posNegDuration
, withoutSuffix
, locale
) {
4269 var duration
= createDuration(posNegDuration
).abs();
4270 var seconds
= round(duration
.as('s'));
4271 var minutes
= round(duration
.as('m'));
4272 var hours
= round(duration
.as('h'));
4273 var days
= round(duration
.as('d'));
4274 var months
= round(duration
.as('M'));
4275 var years
= round(duration
.as('y'));
4277 var a
= seconds
<= thresholds
.ss
&& ['s', seconds
] ||
4278 seconds
< thresholds
.s
&& ['ss', seconds
] ||
4279 minutes
<= 1 && ['m'] ||
4280 minutes
< thresholds
.m
&& ['mm', minutes
] ||
4281 hours
<= 1 && ['h'] ||
4282 hours
< thresholds
.h
&& ['hh', hours
] ||
4283 days
<= 1 && ['d'] ||
4284 days
< thresholds
.d
&& ['dd', days
] ||
4285 months
<= 1 && ['M'] ||
4286 months
< thresholds
.M
&& ['MM', months
] ||
4287 years
<= 1 && ['y'] || ['yy', years
];
4289 a
[2] = withoutSuffix
;
4290 a
[3] = +posNegDuration
> 0;
4292 return substituteTimeAgo
.apply(null, a
);
4295 // This function allows you to set the rounding function for relative time strings
4296 function getSetRelativeTimeRounding (roundingFunction
) {
4297 if (roundingFunction
=== undefined) {
4300 if (typeof(roundingFunction
) === 'function') {
4301 round
= roundingFunction
;
4307 // This function allows you to set a threshold for relative time strings
4308 function getSetRelativeTimeThreshold (threshold
, limit
) {
4309 if (thresholds
[threshold
] === undefined) {
4312 if (limit
=== undefined) {
4313 return thresholds
[threshold
];
4315 thresholds
[threshold
] = limit
;
4316 if (threshold
=== 's') {
4317 thresholds
.ss
= limit
- 1;
4322 function humanize (withSuffix
) {
4323 if (!this.isValid()) {
4324 return this.localeData().invalidDate();
4327 var locale
= this.localeData();
4328 var output
= relativeTime
$1(this, !withSuffix
, locale
);
4331 output
= locale
.pastFuture(+this, output
);
4334 return locale
.postformat(output
);
4337 var abs
$1 = Math
.abs
;
4340 return ((x
> 0) - (x
< 0)) || +x
;
4343 function toISOString
$1() {
4344 // for ISO strings we do not use the normal bubbling rules:
4345 // * milliseconds bubble up until they become hours
4346 // * days do not bubble at all
4347 // * months bubble up until they become years
4348 // This is because there is no context-free conversion between hours and days
4349 // (think of clock changes)
4350 // and also not between days and months (28-31 days per month)
4351 if (!this.isValid()) {
4352 return this.localeData().invalidDate();
4355 var seconds
= abs
$1(this._milliseconds
) / 1000;
4356 var days
= abs
$1(this._days
);
4357 var months
= abs
$1(this._months
);
4358 var minutes
, hours
, years
;
4360 // 3600 seconds -> 60 minutes -> 1 hour
4361 minutes
= absFloor(seconds
/ 60);
4362 hours
= absFloor(minutes
/ 60);
4366 // 12 months -> 1 year
4367 years
= absFloor(months
/ 12);
4371 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
4377 var s
= seconds
? seconds
.toFixed(3).replace(/\.?0+$/, '') : '';
4378 var total
= this.asSeconds();
4381 // this is the same as C#'s (Noda) and python (isodate)...
4382 // but not other JS (goog.date)
4386 var totalSign
= total
< 0 ? '-' : '';
4387 var ymSign
= sign(this._months
) !== sign(total
) ? '-' : '';
4388 var daysSign
= sign(this._days
) !== sign(total
) ? '-' : '';
4389 var hmsSign
= sign(this._milliseconds
) !== sign(total
) ? '-' : '';
4391 return totalSign
+ 'P' +
4392 (Y
? ymSign
+ Y
+ 'Y' : '') +
4393 (M
? ymSign
+ M
+ 'M' : '') +
4394 (D
? daysSign
+ D
+ 'D' : '') +
4395 ((h
|| m
|| s
) ? 'T' : '') +
4396 (h
? hmsSign
+ h
+ 'H' : '') +
4397 (m
? hmsSign
+ m
+ 'M' : '') +
4398 (s
? hmsSign
+ s
+ 'S' : '');
4401 var proto
$2 = Duration
.prototype;
4403 proto
$2.isValid
= isValid
$1;
4405 proto
$2.add
= add
$1;
4406 proto
$2.subtract
= subtract
$1;
4408 proto
$2.asMilliseconds
= asMilliseconds
;
4409 proto
$2.asSeconds
= asSeconds
;
4410 proto
$2.asMinutes
= asMinutes
;
4411 proto
$2.asHours
= asHours
;
4412 proto
$2.asDays
= asDays
;
4413 proto
$2.asWeeks
= asWeeks
;
4414 proto
$2.asMonths
= asMonths
;
4415 proto
$2.asYears
= asYears
;
4416 proto
$2.valueOf
= valueOf
$1;
4417 proto
$2._bubble
= bubble
;
4418 proto
$2.clone
= clone
$1;
4419 proto
$2.get = get$2;
4420 proto
$2.milliseconds
= milliseconds
;
4421 proto
$2.seconds
= seconds
;
4422 proto
$2.minutes
= minutes
;
4423 proto
$2.hours
= hours
;
4424 proto
$2.days
= days
;
4425 proto
$2.weeks
= weeks
;
4426 proto
$2.months
= months
;
4427 proto
$2.years
= years
;
4428 proto
$2.humanize
= humanize
;
4429 proto
$2.toISOString
= toISOString
$1;
4430 proto
$2.toString
= toISOString
$1;
4431 proto
$2.toJSON
= toISOString
$1;
4432 proto
$2.locale
= locale
;
4433 proto
$2.localeData
= localeData
;
4435 proto
$2.toIsoString
= deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString
$1);
4436 proto
$2.lang
= lang
;
4438 // Side effect imports
4442 addFormatToken('X', 0, 0, 'unix');
4443 addFormatToken('x', 0, 0, 'valueOf');
4447 addRegexToken('x', matchSigned
);
4448 addRegexToken('X', matchTimestamp
);
4449 addParseToken('X', function (input
, array
, config
) {
4450 config
._d
= new Date(parseFloat(input
, 10) * 1000);
4452 addParseToken('x', function (input
, array
, config
) {
4453 config
._d
= new Date(toInt(input
));
4456 // Side effect imports
4459 hooks
.version
= '2.22.2';
4461 setHookCallback(createLocal
);
4467 hooks
.utc
= createUTC
;
4468 hooks
.unix
= createUnix
;
4469 hooks
.months
= listMonths
;
4470 hooks
.isDate
= isDate
;
4471 hooks
.locale
= getSetGlobalLocale
;
4472 hooks
.invalid
= createInvalid
;
4473 hooks
.duration
= createDuration
;
4474 hooks
.isMoment
= isMoment
;
4475 hooks
.weekdays
= listWeekdays
;
4476 hooks
.parseZone
= createInZone
;
4477 hooks
.localeData
= getLocale
;
4478 hooks
.isDuration
= isDuration
;
4479 hooks
.monthsShort
= listMonthsShort
;
4480 hooks
.weekdaysMin
= listWeekdaysMin
;
4481 hooks
.defineLocale
= defineLocale
;
4482 hooks
.updateLocale
= updateLocale
;
4483 hooks
.locales
= listLocales
;
4484 hooks
.weekdaysShort
= listWeekdaysShort
;
4485 hooks
.normalizeUnits
= normalizeUnits
;
4486 hooks
.relativeTimeRounding
= getSetRelativeTimeRounding
;
4487 hooks
.relativeTimeThreshold
= getSetRelativeTimeThreshold
;
4488 hooks
.calendarFormat
= getCalendarFormat
;
4489 hooks
.prototype = proto
;
4491 // currently HTML5 input type only supports 24-hour formats
4493 DATETIME_LOCAL
: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
4494 DATETIME_LOCAL_SECONDS
: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
4495 DATETIME_LOCAL_MS
: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
4496 DATE
: 'YYYY-MM-DD', // <input type="date" />
4497 TIME
: 'HH:mm', // <input type="time" />
4498 TIME_SECONDS
: 'HH:mm:ss', // <input type="time" step="1" />
4499 TIME_MS
: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
4500 WEEK
: 'YYYY-[W]WW', // <input type="week" />
4501 MONTH
: 'YYYY-MM' // <input type="month" />