3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
7 ;(function (global
, factory
) {
8 typeof exports
=== 'object' && typeof module
!== 'undefined' ? module
.exports
= factory() :
9 typeof define
=== 'function' && define
.amd
? define(factory
) :
10 global
.moment
= factory()
11 }(this, (function () { 'use strict';
16 return hookCallback
.apply(null, arguments
);
19 // This is done to register the method called with moment()
20 // without creating circular dependencies.
21 function setHookCallback (callback
) {
22 hookCallback
= callback
;
25 function isArray(input
) {
26 return input
instanceof Array
|| Object
.prototype.toString
.call(input
) === '[object Array]';
29 function isObject(input
) {
30 // IE8 will treat undefined and null as object if it wasn't for
32 return input
!= null && Object
.prototype.toString
.call(input
) === '[object Object]';
35 function isObjectEmpty(obj
) {
36 if (Object
.getOwnPropertyNames
) {
37 return (Object
.getOwnPropertyNames(obj
).length
=== 0);
41 if (obj
.hasOwnProperty(k
)) {
49 function isUndefined(input
) {
50 return input
=== void 0;
53 function isNumber(input
) {
54 return typeof input
=== 'number' || Object
.prototype.toString
.call(input
) === '[object Number]';
57 function isDate(input
) {
58 return input
instanceof Date
|| Object
.prototype.toString
.call(input
) === '[object Date]';
61 function map(arr
, fn
) {
63 for (i
= 0; i
< arr
.length
; ++i
) {
64 res
.push(fn(arr
[i
], i
));
69 function hasOwnProp(a
, b
) {
70 return Object
.prototype.hasOwnProperty
.call(a
, b
);
73 function extend(a
, b
) {
75 if (hasOwnProp(b
, i
)) {
80 if (hasOwnProp(b
, 'toString')) {
81 a
.toString
= b
.toString
;
84 if (hasOwnProp(b
, 'valueOf')) {
85 a
.valueOf
= b
.valueOf
;
91 function createUTC (input
, format
, locale
, strict
) {
92 return createLocalOrUTC(input
, format
, locale
, strict
, true).utc();
95 function defaultParsingFlags() {
96 // We need to deep clone this object.
105 invalidFormat
: false,
106 userInvalidated
: false,
108 parsedDateParts
: [],
111 weekdayMismatch
: false
115 function getParsingFlags(m
) {
117 m
._pf
= defaultParsingFlags();
123 if (Array
.prototype.some
) {
124 some
= Array
.prototype.some
;
126 some = function (fun
) {
127 var t
= Object(this);
128 var len
= t
.length
>>> 0;
130 for (var i
= 0; i
< len
; i
++) {
131 if (i
in t
&& fun
.call(this, t
[i
], i
, t
)) {
140 function isValid(m
) {
141 if (m
._isValid
== null) {
142 var flags
= getParsingFlags(m
);
143 var parsedParts
= some
.call(flags
.parsedDateParts
, function (i
) {
146 var isNowValid
= !isNaN(m
._d
.getTime()) &&
147 flags
.overflow
< 0 &&
149 !flags
.invalidMonth
&&
150 !flags
.invalidWeekday
&&
151 !flags
.weekdayMismatch
&&
153 !flags
.invalidFormat
&&
154 !flags
.userInvalidated
&&
155 (!flags
.meridiem
|| (flags
.meridiem
&& parsedParts
));
158 isNowValid
= isNowValid
&&
159 flags
.charsLeftOver
=== 0 &&
160 flags
.unusedTokens
.length
=== 0 &&
161 flags
.bigHour
=== undefined;
164 if (Object
.isFrozen
== null || !Object
.isFrozen(m
)) {
165 m
._isValid
= isNowValid
;
174 function createInvalid (flags
) {
175 var m
= createUTC(NaN
);
177 extend(getParsingFlags(m
), flags
);
180 getParsingFlags(m
).userInvalidated
= true;
186 // Plugins that add properties should also add the key here (null value),
187 // so we can properly clone ourselves.
188 var momentProperties
= hooks
.momentProperties
= [];
190 function copyConfig(to
, from) {
193 if (!isUndefined(from._isAMomentObject
)) {
194 to
._isAMomentObject
= from._isAMomentObject
;
196 if (!isUndefined(from._i
)) {
199 if (!isUndefined(from._f
)) {
202 if (!isUndefined(from._l
)) {
205 if (!isUndefined(from._strict
)) {
206 to
._strict
= from._strict
;
208 if (!isUndefined(from._tzm
)) {
211 if (!isUndefined(from._isUTC
)) {
212 to
._isUTC
= from._isUTC
;
214 if (!isUndefined(from._offset
)) {
215 to
._offset
= from._offset
;
217 if (!isUndefined(from._pf
)) {
218 to
._pf
= getParsingFlags(from);
220 if (!isUndefined(from._locale
)) {
221 to
._locale
= from._locale
;
224 if (momentProperties
.length
> 0) {
225 for (i
= 0; i
< momentProperties
.length
; i
++) {
226 prop
= momentProperties
[i
];
228 if (!isUndefined(val
)) {
237 var updateInProgress
= false;
239 // Moment prototype object
240 function Moment(config
) {
241 copyConfig(this, config
);
242 this._d
= new Date(config
._d
!= null ? config
._d
.getTime() : NaN
);
243 if (!this.isValid()) {
244 this._d
= new Date(NaN
);
246 // Prevent infinite loop in case updateOffset creates new moment
248 if (updateInProgress
=== false) {
249 updateInProgress
= true;
250 hooks
.updateOffset(this);
251 updateInProgress
= false;
255 function isMoment (obj
) {
256 return obj
instanceof Moment
|| (obj
!= null && obj
._isAMomentObject
!= null);
259 function absFloor (number
) {
262 return Math
.ceil(number
) || 0;
264 return Math
.floor(number
);
268 function toInt(argumentForCoercion
) {
269 var coercedNumber
= +argumentForCoercion
,
272 if (coercedNumber
!== 0 && isFinite(coercedNumber
)) {
273 value
= absFloor(coercedNumber
);
279 // compare two arrays, return the number of differences
280 function compareArrays(array1
, array2
, dontConvert
) {
281 var len
= Math
.min(array1
.length
, array2
.length
),
282 lengthDiff
= Math
.abs(array1
.length
- array2
.length
),
285 for (i
= 0; i
< len
; i
++) {
286 if ((dontConvert
&& array1
[i
] !== array2
[i
]) ||
287 (!dontConvert
&& toInt(array1
[i
]) !== toInt(array2
[i
]))) {
291 return diffs
+ lengthDiff
;
295 if (hooks
.suppressDeprecationWarnings
=== false &&
296 (typeof console
!== 'undefined') && console
.warn
) {
297 console
.warn('Deprecation warning: ' + msg
);
301 function deprecate(msg
, fn
) {
302 var firstTime
= true;
304 return extend(function () {
305 if (hooks
.deprecationHandler
!= null) {
306 hooks
.deprecationHandler(null, msg
);
311 for (var i
= 0; i
< arguments
.length
; i
++) {
313 if (typeof arguments
[i
] === 'object') {
314 arg
+= '\n[' + i
+ '] ';
315 for (var key
in arguments
[0]) {
316 arg
+= key
+ ': ' + arguments
[0][key
] + ', ';
318 arg
= arg
.slice(0, -2); // Remove trailing comma and space
324 warn(msg
+ '\nArguments: ' + Array
.prototype.slice
.call(args
).join('') + '\n' + (new Error()).stack
);
327 return fn
.apply(this, arguments
);
331 var deprecations
= {};
333 function deprecateSimple(name
, msg
) {
334 if (hooks
.deprecationHandler
!= null) {
335 hooks
.deprecationHandler(name
, msg
);
337 if (!deprecations
[name
]) {
339 deprecations
[name
] = true;
343 hooks
.suppressDeprecationWarnings
= false;
344 hooks
.deprecationHandler
= null;
346 function isFunction(input
) {
347 return input
instanceof Function
|| Object
.prototype.toString
.call(input
) === '[object Function]';
350 function set (config
) {
354 if (isFunction(prop
)) {
357 this['_' + i
] = prop
;
360 this._config
= config
;
361 // Lenient ordinal parsing accepts just a number in addition to
362 // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
363 // TODO: Remove "ordinalParse" fallback in next major release.
364 this._dayOfMonthOrdinalParseLenient
= new RegExp(
365 (this._dayOfMonthOrdinalParse
.source
|| this._ordinalParse
.source
) +
366 '|' + (/\d{1,2}/).source
);
369 function mergeConfigs(parentConfig
, childConfig
) {
370 var res
= extend({}, parentConfig
), prop
;
371 for (prop
in childConfig
) {
372 if (hasOwnProp(childConfig
, prop
)) {
373 if (isObject(parentConfig
[prop
]) && isObject(childConfig
[prop
])) {
375 extend(res
[prop
], parentConfig
[prop
]);
376 extend(res
[prop
], childConfig
[prop
]);
377 } else if (childConfig
[prop
] != null) {
378 res
[prop
] = childConfig
[prop
];
384 for (prop
in parentConfig
) {
385 if (hasOwnProp(parentConfig
, prop
) &&
386 !hasOwnProp(childConfig
, prop
) &&
387 isObject(parentConfig
[prop
])) {
388 // make sure changes to properties don't modify parent config
389 res
[prop
] = extend({}, res
[prop
]);
395 function Locale(config
) {
396 if (config
!= null) {
406 keys = function (obj
) {
409 if (hasOwnProp(obj
, i
)) {
417 var defaultCalendar
= {
418 sameDay
: '[Today at] LT',
419 nextDay
: '[Tomorrow at] LT',
420 nextWeek
: 'dddd [at] LT',
421 lastDay
: '[Yesterday at] LT',
422 lastWeek
: '[Last] dddd [at] LT',
426 function calendar (key
, mom
, now
) {
427 var output
= this._calendar
[key
] || this._calendar
['sameElse'];
428 return isFunction(output
) ? output
.call(mom
, now
) : output
;
431 var defaultLongDateFormat
= {
436 LLL
: 'MMMM D, YYYY h:mm A',
437 LLLL
: 'dddd, MMMM D, YYYY h:mm A'
440 function longDateFormat (key
) {
441 var format
= this._longDateFormat
[key
],
442 formatUpper
= this._longDateFormat
[key
.toUpperCase()];
444 if (format
|| !formatUpper
) {
448 this._longDateFormat
[key
] = formatUpper
.replace(/MMMM|MM|DD|dddd/g, function (val
) {
452 return this._longDateFormat
[key
];
455 var defaultInvalidDate
= 'Invalid date';
457 function invalidDate () {
458 return this._invalidDate
;
461 var defaultOrdinal
= '%d';
462 var defaultDayOfMonthOrdinalParse
= /\d{1,2}/;
464 function ordinal (number
) {
465 return this._ordinal
.replace('%d', number
);
468 var defaultRelativeTime
= {
485 function relativeTime (number
, withoutSuffix
, string
, isFuture
) {
486 var output
= this._relativeTime
[string
];
487 return (isFunction(output
)) ?
488 output(number
, withoutSuffix
, string
, isFuture
) :
489 output
.replace(/%d/i, number
);
492 function pastFuture (diff
, output
) {
493 var format
= this._relativeTime
[diff
> 0 ? 'future' : 'past'];
494 return isFunction(format
) ? format(output
) : format
.replace(/%s/i, output
);
499 function addUnitAlias (unit
, shorthand
) {
500 var lowerCase
= unit
.toLowerCase();
501 aliases
[lowerCase
] = aliases
[lowerCase
+ 's'] = aliases
[shorthand
] = unit
;
504 function normalizeUnits(units
) {
505 return typeof units
=== 'string' ? aliases
[units
] || aliases
[units
.toLowerCase()] : undefined;
508 function normalizeObjectUnits(inputObject
) {
509 var normalizedInput
= {},
513 for (prop
in inputObject
) {
514 if (hasOwnProp(inputObject
, prop
)) {
515 normalizedProp
= normalizeUnits(prop
);
516 if (normalizedProp
) {
517 normalizedInput
[normalizedProp
] = inputObject
[prop
];
522 return normalizedInput
;
527 function addUnitPriority(unit
, priority
) {
528 priorities
[unit
] = priority
;
531 function getPrioritizedUnits(unitsObj
) {
533 for (var u
in unitsObj
) {
534 units
.push({unit
: u
, priority
: priorities
[u
]});
536 units
.sort(function (a
, b
) {
537 return a
.priority
- b
.priority
;
542 function zeroFill(number
, targetLength
, forceSign
) {
543 var absNumber
= '' + Math
.abs(number
),
544 zerosToFill
= targetLength
- absNumber
.length
,
546 return (sign
? (forceSign
? '+' : '') : '-') +
547 Math
.pow(10, Math
.max(0, zerosToFill
)).toString().substr(1) + absNumber
;
550 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;
552 var localFormattingTokens
= /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
554 var formatFunctions
= {};
556 var formatTokenFunctions
= {};
561 // callback: function () { this.month() + 1 }
562 function addFormatToken (token
, padded
, ordinal
, callback
) {
564 if (typeof callback
=== 'string') {
566 return this[callback
]();
570 formatTokenFunctions
[token
] = func
;
573 formatTokenFunctions
[padded
[0]] = function () {
574 return zeroFill(func
.apply(this, arguments
), padded
[1], padded
[2]);
578 formatTokenFunctions
[ordinal
] = function () {
579 return this.localeData().ordinal(func
.apply(this, arguments
), token
);
584 function removeFormattingTokens(input
) {
585 if (input
.match(/\[[\s\S]/)) {
586 return input
.replace(/^\[|\]$/g, '');
588 return input
.replace(/\\/g
, '');
591 function makeFormatFunction(format
) {
592 var array
= format
.match(formattingTokens
), i
, length
;
594 for (i
= 0, length
= array
.length
; i
< length
; i
++) {
595 if (formatTokenFunctions
[array
[i
]]) {
596 array
[i
] = formatTokenFunctions
[array
[i
]];
598 array
[i
] = removeFormattingTokens(array
[i
]);
602 return function (mom
) {
604 for (i
= 0; i
< length
; i
++) {
605 output
+= isFunction(array
[i
]) ? array
[i
].call(mom
, format
) : array
[i
];
611 // format date using native date object
612 function formatMoment(m
, format
) {
614 return m
.localeData().invalidDate();
617 format
= expandFormat(format
, m
.localeData());
618 formatFunctions
[format
] = formatFunctions
[format
] || makeFormatFunction(format
);
620 return formatFunctions
[format
](m
);
623 function expandFormat(format
, locale
) {
626 function replaceLongDateFormatTokens(input
) {
627 return locale
.longDateFormat(input
) || input
;
630 localFormattingTokens
.lastIndex
= 0;
631 while (i
>= 0 && localFormattingTokens
.test(format
)) {
632 format
= format
.replace(localFormattingTokens
, replaceLongDateFormatTokens
);
633 localFormattingTokens
.lastIndex
= 0;
640 var match1
= /\d/; // 0 - 9
641 var match2
= /\d\d/; // 00 - 99
642 var match3
= /\d{3}/; // 000 - 999
643 var match4
= /\d{4}/; // 0000 - 9999
644 var match6
= /[+-]?\d{6}/; // -999999 - 999999
645 var match1to2
= /\d\d?/; // 0 - 99
646 var match3to4
= /\d\d\d\d?/; // 999 - 9999
647 var match5to6
= /\d\d\d\d\d\d?/; // 99999 - 999999
648 var match1to3
= /\d{1,3}/; // 0 - 999
649 var match1to4
= /\d{1,4}/; // 0 - 9999
650 var match1to6
= /[+-]?\d{1,6}/; // -999999 - 999999
652 var matchUnsigned
= /\d+/; // 0 - inf
653 var matchSigned
= /[+-]?\d+/; // -inf - inf
655 var matchOffset
= /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
656 var matchShortOffset
= /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
658 var matchTimestamp
= /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
660 // any word (or two) characters or numbers including two/three word month in arabic.
661 // includes scottish gaelic two word and hyphenated months
662 var matchWord
= /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;
667 function addRegexToken (token
, regex
, strictRegex
) {
668 regexes
[token
] = isFunction(regex
) ? regex : function (isStrict
, localeData
) {
669 return (isStrict
&& strictRegex
) ? strictRegex
: regex
;
673 function getParseRegexForToken (token
, config
) {
674 if (!hasOwnProp(regexes
, token
)) {
675 return new RegExp(unescapeFormat(token
));
678 return regexes
[token
](config
._strict
, config
._locale
);
681 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
682 function unescapeFormat(s
) {
683 return regexEscape(s
.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched
, p1
, p2
, p3
, p4
) {
684 return p1
|| p2
|| p3
|| p4
;
688 function regexEscape(s
) {
689 return s
.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
694 function addParseToken (token
, callback
) {
695 var i
, func
= callback
;
696 if (typeof token
=== 'string') {
699 if (isNumber(callback
)) {
700 func = function (input
, array
) {
701 array
[callback
] = toInt(input
);
704 for (i
= 0; i
< token
.length
; i
++) {
705 tokens
[token
[i
]] = func
;
709 function addWeekParseToken (token
, callback
) {
710 addParseToken(token
, function (input
, array
, config
, token
) {
711 config
._w
= config
._w
|| {};
712 callback(input
, config
._w
, config
, token
);
716 function addTimeToArrayFromToken(token
, input
, config
) {
717 if (input
!= null && hasOwnProp(tokens
, token
)) {
718 tokens
[token
](input
, config
._a
, config
, token
);
734 addFormatToken('Y', 0, 0, function () {
736 return y
<= 9999 ? '' + y
: '+' + y
;
739 addFormatToken(0, ['YY', 2], 0, function () {
740 return this.year() % 100;
743 addFormatToken(0, ['YYYY', 4], 0, 'year');
744 addFormatToken(0, ['YYYYY', 5], 0, 'year');
745 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
749 addUnitAlias('year', 'y');
753 addUnitPriority('year', 1);
757 addRegexToken('Y', matchSigned
);
758 addRegexToken('YY', match1to2
, match2
);
759 addRegexToken('YYYY', match1to4
, match4
);
760 addRegexToken('YYYYY', match1to6
, match6
);
761 addRegexToken('YYYYYY', match1to6
, match6
);
763 addParseToken(['YYYYY', 'YYYYYY'], YEAR
);
764 addParseToken('YYYY', function (input
, array
) {
765 array
[YEAR
] = input
.length
=== 2 ? hooks
.parseTwoDigitYear(input
) : toInt(input
);
767 addParseToken('YY', function (input
, array
) {
768 array
[YEAR
] = hooks
.parseTwoDigitYear(input
);
770 addParseToken('Y', function (input
, array
) {
771 array
[YEAR
] = parseInt(input
, 10);
776 function daysInYear(year
) {
777 return isLeapYear(year
) ? 366 : 365;
780 function isLeapYear(year
) {
781 return (year
% 4 === 0 && year
% 100 !== 0) || year
% 400 === 0;
786 hooks
.parseTwoDigitYear = function (input
) {
787 return toInt(input
) + (toInt(input
) > 68 ? 1900 : 2000);
792 var getSetYear
= makeGetSet('FullYear', true);
794 function getIsLeapYear () {
795 return isLeapYear(this.year());
798 function makeGetSet (unit
, keepTime
) {
799 return function (value
) {
801 set$1(this, unit
, value
);
802 hooks
.updateOffset(this, keepTime
);
805 return get(this, unit
);
810 function get (mom
, unit
) {
811 return mom
.isValid() ?
812 mom
._d
['get' + (mom
._isUTC
? 'UTC' : '') + unit
]() : NaN
;
815 function set$1 (mom
, unit
, value
) {
816 if (mom
.isValid() && !isNaN(value
)) {
817 if (unit
=== 'FullYear' && isLeapYear(mom
.year()) && mom
.month() === 1 && mom
.date() === 29) {
818 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + unit
](value
, mom
.month(), daysInMonth(value
, mom
.month()));
821 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + unit
](value
);
828 function stringGet (units
) {
829 units
= normalizeUnits(units
);
830 if (isFunction(this[units
])) {
831 return this[units
]();
837 function stringSet (units
, value
) {
838 if (typeof units
=== 'object') {
839 units
= normalizeObjectUnits(units
);
840 var prioritized
= getPrioritizedUnits(units
);
841 for (var i
= 0; i
< prioritized
.length
; i
++) {
842 this[prioritized
[i
].unit
](units
[prioritized
[i
].unit
]);
845 units
= normalizeUnits(units
);
846 if (isFunction(this[units
])) {
847 return this[units
](value
);
854 return ((n
% x
) + x
) % x
;
859 if (Array
.prototype.indexOf
) {
860 indexOf
= Array
.prototype.indexOf
;
862 indexOf = function (o
) {
865 for (i
= 0; i
< this.length
; ++i
) {
874 function daysInMonth(year
, month
) {
875 if (isNaN(year
) || isNaN(month
)) {
878 var modMonth
= mod(month
, 12);
879 year
+= (month
- modMonth
) / 12;
880 return modMonth
=== 1 ? (isLeapYear(year
) ? 29 : 28) : (31 - modMonth
% 7 % 2);
885 addFormatToken('M', ['MM', 2], 'Mo', function () {
886 return this.month() + 1;
889 addFormatToken('MMM', 0, 0, function (format
) {
890 return this.localeData().monthsShort(this, format
);
893 addFormatToken('MMMM', 0, 0, function (format
) {
894 return this.localeData().months(this, format
);
899 addUnitAlias('month', 'M');
903 addUnitPriority('month', 8);
907 addRegexToken('M', match1to2
);
908 addRegexToken('MM', match1to2
, match2
);
909 addRegexToken('MMM', function (isStrict
, locale
) {
910 return locale
.monthsShortRegex(isStrict
);
912 addRegexToken('MMMM', function (isStrict
, locale
) {
913 return locale
.monthsRegex(isStrict
);
916 addParseToken(['M', 'MM'], function (input
, array
) {
917 array
[MONTH
] = toInt(input
) - 1;
920 addParseToken(['MMM', 'MMMM'], function (input
, array
, config
, token
) {
921 var month
= config
._locale
.monthsParse(input
, token
, config
._strict
);
922 // if we didn't find a month name, mark the date as invalid.
924 array
[MONTH
] = month
;
926 getParsingFlags(config
).invalidMonth
= input
;
932 var MONTHS_IN_FORMAT
= /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
933 var defaultLocaleMonths
= 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
934 function localeMonths (m
, format
) {
936 return isArray(this._months
) ? this._months
:
937 this._months
['standalone'];
939 return isArray(this._months
) ? this._months
[m
.month()] :
940 this._months
[(this._months
.isFormat
|| MONTHS_IN_FORMAT
).test(format
) ? 'format' : 'standalone'][m
.month()];
943 var defaultLocaleMonthsShort
= 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
944 function localeMonthsShort (m
, format
) {
946 return isArray(this._monthsShort
) ? this._monthsShort
:
947 this._monthsShort
['standalone'];
949 return isArray(this._monthsShort
) ? this._monthsShort
[m
.month()] :
950 this._monthsShort
[MONTHS_IN_FORMAT
.test(format
) ? 'format' : 'standalone'][m
.month()];
953 function handleStrictParse(monthName
, format
, strict
) {
954 var i
, ii
, mom
, llc
= monthName
.toLocaleLowerCase();
955 if (!this._monthsParse
) {
957 this._monthsParse
= [];
958 this._longMonthsParse
= [];
959 this._shortMonthsParse
= [];
960 for (i
= 0; i
< 12; ++i
) {
961 mom
= createUTC([2000, i
]);
962 this._shortMonthsParse
[i
] = this.monthsShort(mom
, '').toLocaleLowerCase();
963 this._longMonthsParse
[i
] = this.months(mom
, '').toLocaleLowerCase();
968 if (format
=== 'MMM') {
969 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
970 return ii
!== -1 ? ii
: null;
972 ii
= indexOf
.call(this._longMonthsParse
, llc
);
973 return ii
!== -1 ? ii
: null;
976 if (format
=== 'MMM') {
977 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
981 ii
= indexOf
.call(this._longMonthsParse
, llc
);
982 return ii
!== -1 ? ii
: null;
984 ii
= indexOf
.call(this._longMonthsParse
, llc
);
988 ii
= indexOf
.call(this._shortMonthsParse
, llc
);
989 return ii
!== -1 ? ii
: null;
994 function localeMonthsParse (monthName
, format
, strict
) {
997 if (this._monthsParseExact
) {
998 return handleStrictParse
.call(this, monthName
, format
, strict
);
1001 if (!this._monthsParse
) {
1002 this._monthsParse
= [];
1003 this._longMonthsParse
= [];
1004 this._shortMonthsParse
= [];
1007 // TODO: add sorting
1008 // Sorting makes sure if one month (or abbr) is a prefix of another
1009 // see sorting in computeMonthsParse
1010 for (i
= 0; i
< 12; i
++) {
1011 // make the regex if we don't have it already
1012 mom
= createUTC([2000, i
]);
1013 if (strict
&& !this._longMonthsParse
[i
]) {
1014 this._longMonthsParse
[i
] = new RegExp('^' + this.months(mom
, '').replace('.', '') + '$', 'i');
1015 this._shortMonthsParse
[i
] = new RegExp('^' + this.monthsShort(mom
, '').replace('.', '') + '$', 'i');
1017 if (!strict
&& !this._monthsParse
[i
]) {
1018 regex
= '^' + this.months(mom
, '') + '|^' + this.monthsShort(mom
, '');
1019 this._monthsParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
1022 if (strict
&& format
=== 'MMMM' && this._longMonthsParse
[i
].test(monthName
)) {
1024 } else if (strict
&& format
=== 'MMM' && this._shortMonthsParse
[i
].test(monthName
)) {
1026 } else if (!strict
&& this._monthsParse
[i
].test(monthName
)) {
1034 function setMonth (mom
, value
) {
1037 if (!mom
.isValid()) {
1042 if (typeof value
=== 'string') {
1043 if (/^\d+$/.test(value
)) {
1044 value
= toInt(value
);
1046 value
= mom
.localeData().monthsParse(value
);
1047 // TODO: Another silent failure?
1048 if (!isNumber(value
)) {
1054 dayOfMonth
= Math
.min(mom
.date(), daysInMonth(mom
.year(), value
));
1055 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + 'Month'](value
, dayOfMonth
);
1059 function getSetMonth (value
) {
1060 if (value
!= null) {
1061 setMonth(this, value
);
1062 hooks
.updateOffset(this, true);
1065 return get(this, 'Month');
1069 function getDaysInMonth () {
1070 return daysInMonth(this.year(), this.month());
1073 var defaultMonthsShortRegex
= matchWord
;
1074 function monthsShortRegex (isStrict
) {
1075 if (this._monthsParseExact
) {
1076 if (!hasOwnProp(this, '_monthsRegex')) {
1077 computeMonthsParse
.call(this);
1080 return this._monthsShortStrictRegex
;
1082 return this._monthsShortRegex
;
1085 if (!hasOwnProp(this, '_monthsShortRegex')) {
1086 this._monthsShortRegex
= defaultMonthsShortRegex
;
1088 return this._monthsShortStrictRegex
&& isStrict
?
1089 this._monthsShortStrictRegex
: this._monthsShortRegex
;
1093 var defaultMonthsRegex
= matchWord
;
1094 function monthsRegex (isStrict
) {
1095 if (this._monthsParseExact
) {
1096 if (!hasOwnProp(this, '_monthsRegex')) {
1097 computeMonthsParse
.call(this);
1100 return this._monthsStrictRegex
;
1102 return this._monthsRegex
;
1105 if (!hasOwnProp(this, '_monthsRegex')) {
1106 this._monthsRegex
= defaultMonthsRegex
;
1108 return this._monthsStrictRegex
&& isStrict
?
1109 this._monthsStrictRegex
: this._monthsRegex
;
1113 function computeMonthsParse () {
1114 function cmpLenRev(a
, b
) {
1115 return b
.length
- a
.length
;
1118 var shortPieces
= [], longPieces
= [], mixedPieces
= [],
1120 for (i
= 0; i
< 12; i
++) {
1121 // make the regex if we don't have it already
1122 mom
= createUTC([2000, i
]);
1123 shortPieces
.push(this.monthsShort(mom
, ''));
1124 longPieces
.push(this.months(mom
, ''));
1125 mixedPieces
.push(this.months(mom
, ''));
1126 mixedPieces
.push(this.monthsShort(mom
, ''));
1128 // Sorting makes sure if one month (or abbr) is a prefix of another it
1129 // will match the longer piece.
1130 shortPieces
.sort(cmpLenRev
);
1131 longPieces
.sort(cmpLenRev
);
1132 mixedPieces
.sort(cmpLenRev
);
1133 for (i
= 0; i
< 12; i
++) {
1134 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1135 longPieces
[i
] = regexEscape(longPieces
[i
]);
1137 for (i
= 0; i
< 24; i
++) {
1138 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1141 this._monthsRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1142 this._monthsShortRegex
= this._monthsRegex
;
1143 this._monthsStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1144 this._monthsShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1147 function createDate (y
, m
, d
, h
, M
, s
, ms
) {
1148 // can't just apply() to create a date:
1149 // https://stackoverflow.com/q/181348
1150 var date
= new Date(y
, m
, d
, h
, M
, s
, ms
);
1152 // the date constructor remaps years 0-99 to 1900-1999
1153 if (y
< 100 && y
>= 0 && isFinite(date
.getFullYear())) {
1154 date
.setFullYear(y
);
1159 function createUTCDate (y
) {
1160 var date
= new Date(Date
.UTC
.apply(null, arguments
));
1162 // the Date.UTC function remaps years 0-99 to 1900-1999
1163 if (y
< 100 && y
>= 0 && isFinite(date
.getUTCFullYear())) {
1164 date
.setUTCFullYear(y
);
1169 // start-of-first-week - start-of-year
1170 function firstWeekOffset(year
, dow
, doy
) {
1171 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1172 fwd
= 7 + dow
- doy
,
1173 // first-week day local weekday -- which local weekday is fwd
1174 fwdlw
= (7 + createUTCDate(year
, 0, fwd
).getUTCDay() - dow
) % 7;
1176 return -fwdlw
+ fwd
- 1;
1179 // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1180 function dayOfYearFromWeeks(year
, week
, weekday
, dow
, doy
) {
1181 var localWeekday
= (7 + weekday
- dow
) % 7,
1182 weekOffset
= firstWeekOffset(year
, dow
, doy
),
1183 dayOfYear
= 1 + 7 * (week
- 1) + localWeekday
+ weekOffset
,
1184 resYear
, resDayOfYear
;
1186 if (dayOfYear
<= 0) {
1188 resDayOfYear
= daysInYear(resYear
) + dayOfYear
;
1189 } else if (dayOfYear
> daysInYear(year
)) {
1191 resDayOfYear
= dayOfYear
- daysInYear(year
);
1194 resDayOfYear
= dayOfYear
;
1199 dayOfYear
: resDayOfYear
1203 function weekOfYear(mom
, dow
, doy
) {
1204 var weekOffset
= firstWeekOffset(mom
.year(), dow
, doy
),
1205 week
= Math
.floor((mom
.dayOfYear() - weekOffset
- 1) / 7) + 1,
1209 resYear
= mom
.year() - 1;
1210 resWeek
= week
+ weeksInYear(resYear
, dow
, doy
);
1211 } else if (week
> weeksInYear(mom
.year(), dow
, doy
)) {
1212 resWeek
= week
- weeksInYear(mom
.year(), dow
, doy
);
1213 resYear
= mom
.year() + 1;
1215 resYear
= mom
.year();
1225 function weeksInYear(year
, dow
, doy
) {
1226 var weekOffset
= firstWeekOffset(year
, dow
, doy
),
1227 weekOffsetNext
= firstWeekOffset(year
+ 1, dow
, doy
);
1228 return (daysInYear(year
) - weekOffset
+ weekOffsetNext
) / 7;
1233 addFormatToken('w', ['ww', 2], 'wo', 'week');
1234 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
1238 addUnitAlias('week', 'w');
1239 addUnitAlias('isoWeek', 'W');
1243 addUnitPriority('week', 5);
1244 addUnitPriority('isoWeek', 5);
1248 addRegexToken('w', match1to2
);
1249 addRegexToken('ww', match1to2
, match2
);
1250 addRegexToken('W', match1to2
);
1251 addRegexToken('WW', match1to2
, match2
);
1253 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input
, week
, config
, token
) {
1254 week
[token
.substr(0, 1)] = toInt(input
);
1261 function localeWeek (mom
) {
1262 return weekOfYear(mom
, this._week
.dow
, this._week
.doy
).week
;
1265 var defaultLocaleWeek
= {
1266 dow
: 0, // Sunday is the first day of the week.
1267 doy
: 6 // The week that contains Jan 1st is the first week of the year.
1270 function localeFirstDayOfWeek () {
1271 return this._week
.dow
;
1274 function localeFirstDayOfYear () {
1275 return this._week
.doy
;
1280 function getSetWeek (input
) {
1281 var week
= this.localeData().week(this);
1282 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1285 function getSetISOWeek (input
) {
1286 var week
= weekOfYear(this, 1, 4).week
;
1287 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1292 addFormatToken('d', 0, 'do', 'day');
1294 addFormatToken('dd', 0, 0, function (format
) {
1295 return this.localeData().weekdaysMin(this, format
);
1298 addFormatToken('ddd', 0, 0, function (format
) {
1299 return this.localeData().weekdaysShort(this, format
);
1302 addFormatToken('dddd', 0, 0, function (format
) {
1303 return this.localeData().weekdays(this, format
);
1306 addFormatToken('e', 0, 0, 'weekday');
1307 addFormatToken('E', 0, 0, 'isoWeekday');
1311 addUnitAlias('day', 'd');
1312 addUnitAlias('weekday', 'e');
1313 addUnitAlias('isoWeekday', 'E');
1316 addUnitPriority('day', 11);
1317 addUnitPriority('weekday', 11);
1318 addUnitPriority('isoWeekday', 11);
1322 addRegexToken('d', match1to2
);
1323 addRegexToken('e', match1to2
);
1324 addRegexToken('E', match1to2
);
1325 addRegexToken('dd', function (isStrict
, locale
) {
1326 return locale
.weekdaysMinRegex(isStrict
);
1328 addRegexToken('ddd', function (isStrict
, locale
) {
1329 return locale
.weekdaysShortRegex(isStrict
);
1331 addRegexToken('dddd', function (isStrict
, locale
) {
1332 return locale
.weekdaysRegex(isStrict
);
1335 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input
, week
, config
, token
) {
1336 var weekday
= config
._locale
.weekdaysParse(input
, token
, config
._strict
);
1337 // if we didn't get a weekday name, mark the date as invalid
1338 if (weekday
!= null) {
1341 getParsingFlags(config
).invalidWeekday
= input
;
1345 addWeekParseToken(['d', 'e', 'E'], function (input
, week
, config
, token
) {
1346 week
[token
] = toInt(input
);
1351 function parseWeekday(input
, locale
) {
1352 if (typeof input
!== 'string') {
1356 if (!isNaN(input
)) {
1357 return parseInt(input
, 10);
1360 input
= locale
.weekdaysParse(input
);
1361 if (typeof input
=== 'number') {
1368 function parseIsoWeekday(input
, locale
) {
1369 if (typeof input
=== 'string') {
1370 return locale
.weekdaysParse(input
) % 7 || 7;
1372 return isNaN(input
) ? null : input
;
1377 var defaultLocaleWeekdays
= 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
1378 function localeWeekdays (m
, format
) {
1380 return isArray(this._weekdays
) ? this._weekdays
:
1381 this._weekdays
['standalone'];
1383 return isArray(this._weekdays
) ? this._weekdays
[m
.day()] :
1384 this._weekdays
[this._weekdays
.isFormat
.test(format
) ? 'format' : 'standalone'][m
.day()];
1387 var defaultLocaleWeekdaysShort
= 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
1388 function localeWeekdaysShort (m
) {
1389 return (m
) ? this._weekdaysShort
[m
.day()] : this._weekdaysShort
;
1392 var defaultLocaleWeekdaysMin
= 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
1393 function localeWeekdaysMin (m
) {
1394 return (m
) ? this._weekdaysMin
[m
.day()] : this._weekdaysMin
;
1397 function handleStrictParse
$1(weekdayName
, format
, strict
) {
1398 var i
, ii
, mom
, llc
= weekdayName
.toLocaleLowerCase();
1399 if (!this._weekdaysParse
) {
1400 this._weekdaysParse
= [];
1401 this._shortWeekdaysParse
= [];
1402 this._minWeekdaysParse
= [];
1404 for (i
= 0; i
< 7; ++i
) {
1405 mom
= createUTC([2000, 1]).day(i
);
1406 this._minWeekdaysParse
[i
] = this.weekdaysMin(mom
, '').toLocaleLowerCase();
1407 this._shortWeekdaysParse
[i
] = this.weekdaysShort(mom
, '').toLocaleLowerCase();
1408 this._weekdaysParse
[i
] = this.weekdays(mom
, '').toLocaleLowerCase();
1413 if (format
=== 'dddd') {
1414 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1415 return ii
!== -1 ? ii
: null;
1416 } else if (format
=== 'ddd') {
1417 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1418 return ii
!== -1 ? ii
: null;
1420 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1421 return ii
!== -1 ? ii
: null;
1424 if (format
=== 'dddd') {
1425 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1429 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1433 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1434 return ii
!== -1 ? ii
: null;
1435 } else if (format
=== 'ddd') {
1436 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1440 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1444 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1445 return ii
!== -1 ? ii
: null;
1447 ii
= indexOf
.call(this._minWeekdaysParse
, llc
);
1451 ii
= indexOf
.call(this._weekdaysParse
, llc
);
1455 ii
= indexOf
.call(this._shortWeekdaysParse
, llc
);
1456 return ii
!== -1 ? ii
: null;
1461 function localeWeekdaysParse (weekdayName
, format
, strict
) {
1464 if (this._weekdaysParseExact
) {
1465 return handleStrictParse
$1.call(this, weekdayName
, format
, strict
);
1468 if (!this._weekdaysParse
) {
1469 this._weekdaysParse
= [];
1470 this._minWeekdaysParse
= [];
1471 this._shortWeekdaysParse
= [];
1472 this._fullWeekdaysParse
= [];
1475 for (i
= 0; i
< 7; i
++) {
1476 // make the regex if we don't have it already
1478 mom
= createUTC([2000, 1]).day(i
);
1479 if (strict
&& !this._fullWeekdaysParse
[i
]) {
1480 this._fullWeekdaysParse
[i
] = new RegExp('^' + this.weekdays(mom
, '').replace('.', '\.?') + '$', 'i');
1481 this._shortWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysShort(mom
, '').replace('.', '\.?') + '$', 'i');
1482 this._minWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysMin(mom
, '').replace('.', '\.?') + '$', 'i');
1484 if (!this._weekdaysParse
[i
]) {
1485 regex
= '^' + this.weekdays(mom
, '') + '|^' + this.weekdaysShort(mom
, '') + '|^' + this.weekdaysMin(mom
, '');
1486 this._weekdaysParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
1489 if (strict
&& format
=== 'dddd' && this._fullWeekdaysParse
[i
].test(weekdayName
)) {
1491 } else if (strict
&& format
=== 'ddd' && this._shortWeekdaysParse
[i
].test(weekdayName
)) {
1493 } else if (strict
&& format
=== 'dd' && this._minWeekdaysParse
[i
].test(weekdayName
)) {
1495 } else if (!strict
&& this._weekdaysParse
[i
].test(weekdayName
)) {
1503 function getSetDayOfWeek (input
) {
1504 if (!this.isValid()) {
1505 return input
!= null ? this : NaN
;
1507 var day
= this._isUTC
? this._d
.getUTCDay() : this._d
.getDay();
1508 if (input
!= null) {
1509 input
= parseWeekday(input
, this.localeData());
1510 return this.add(input
- day
, 'd');
1516 function getSetLocaleDayOfWeek (input
) {
1517 if (!this.isValid()) {
1518 return input
!= null ? this : NaN
;
1520 var weekday
= (this.day() + 7 - this.localeData()._week
.dow
) % 7;
1521 return input
== null ? weekday
: this.add(input
- weekday
, 'd');
1524 function getSetISODayOfWeek (input
) {
1525 if (!this.isValid()) {
1526 return input
!= null ? this : NaN
;
1529 // behaves the same as moment#day except
1530 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
1531 // as a setter, sunday should belong to the previous week.
1533 if (input
!= null) {
1534 var weekday
= parseIsoWeekday(input
, this.localeData());
1535 return this.day(this.day() % 7 ? weekday
: weekday
- 7);
1537 return this.day() || 7;
1541 var defaultWeekdaysRegex
= matchWord
;
1542 function weekdaysRegex (isStrict
) {
1543 if (this._weekdaysParseExact
) {
1544 if (!hasOwnProp(this, '_weekdaysRegex')) {
1545 computeWeekdaysParse
.call(this);
1548 return this._weekdaysStrictRegex
;
1550 return this._weekdaysRegex
;
1553 if (!hasOwnProp(this, '_weekdaysRegex')) {
1554 this._weekdaysRegex
= defaultWeekdaysRegex
;
1556 return this._weekdaysStrictRegex
&& isStrict
?
1557 this._weekdaysStrictRegex
: this._weekdaysRegex
;
1561 var defaultWeekdaysShortRegex
= matchWord
;
1562 function weekdaysShortRegex (isStrict
) {
1563 if (this._weekdaysParseExact
) {
1564 if (!hasOwnProp(this, '_weekdaysRegex')) {
1565 computeWeekdaysParse
.call(this);
1568 return this._weekdaysShortStrictRegex
;
1570 return this._weekdaysShortRegex
;
1573 if (!hasOwnProp(this, '_weekdaysShortRegex')) {
1574 this._weekdaysShortRegex
= defaultWeekdaysShortRegex
;
1576 return this._weekdaysShortStrictRegex
&& isStrict
?
1577 this._weekdaysShortStrictRegex
: this._weekdaysShortRegex
;
1581 var defaultWeekdaysMinRegex
= matchWord
;
1582 function weekdaysMinRegex (isStrict
) {
1583 if (this._weekdaysParseExact
) {
1584 if (!hasOwnProp(this, '_weekdaysRegex')) {
1585 computeWeekdaysParse
.call(this);
1588 return this._weekdaysMinStrictRegex
;
1590 return this._weekdaysMinRegex
;
1593 if (!hasOwnProp(this, '_weekdaysMinRegex')) {
1594 this._weekdaysMinRegex
= defaultWeekdaysMinRegex
;
1596 return this._weekdaysMinStrictRegex
&& isStrict
?
1597 this._weekdaysMinStrictRegex
: this._weekdaysMinRegex
;
1602 function computeWeekdaysParse () {
1603 function cmpLenRev(a
, b
) {
1604 return b
.length
- a
.length
;
1607 var minPieces
= [], shortPieces
= [], longPieces
= [], mixedPieces
= [],
1608 i
, mom
, minp
, shortp
, longp
;
1609 for (i
= 0; i
< 7; i
++) {
1610 // make the regex if we don't have it already
1611 mom
= createUTC([2000, 1]).day(i
);
1612 minp
= this.weekdaysMin(mom
, '');
1613 shortp
= this.weekdaysShort(mom
, '');
1614 longp
= this.weekdays(mom
, '');
1615 minPieces
.push(minp
);
1616 shortPieces
.push(shortp
);
1617 longPieces
.push(longp
);
1618 mixedPieces
.push(minp
);
1619 mixedPieces
.push(shortp
);
1620 mixedPieces
.push(longp
);
1622 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
1623 // will match the longer piece.
1624 minPieces
.sort(cmpLenRev
);
1625 shortPieces
.sort(cmpLenRev
);
1626 longPieces
.sort(cmpLenRev
);
1627 mixedPieces
.sort(cmpLenRev
);
1628 for (i
= 0; i
< 7; i
++) {
1629 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1630 longPieces
[i
] = regexEscape(longPieces
[i
]);
1631 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1634 this._weekdaysRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1635 this._weekdaysShortRegex
= this._weekdaysRegex
;
1636 this._weekdaysMinRegex
= this._weekdaysRegex
;
1638 this._weekdaysStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1639 this._weekdaysShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1640 this._weekdaysMinStrictRegex
= new RegExp('^(' + minPieces
.join('|') + ')', 'i');
1645 function hFormat() {
1646 return this.hours() % 12 || 12;
1649 function kFormat() {
1650 return this.hours() || 24;
1653 addFormatToken('H', ['HH', 2], 0, 'hour');
1654 addFormatToken('h', ['hh', 2], 0, hFormat
);
1655 addFormatToken('k', ['kk', 2], 0, kFormat
);
1657 addFormatToken('hmm', 0, 0, function () {
1658 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2);
1661 addFormatToken('hmmss', 0, 0, function () {
1662 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2) +
1663 zeroFill(this.seconds(), 2);
1666 addFormatToken('Hmm', 0, 0, function () {
1667 return '' + this.hours() + zeroFill(this.minutes(), 2);
1670 addFormatToken('Hmmss', 0, 0, function () {
1671 return '' + this.hours() + zeroFill(this.minutes(), 2) +
1672 zeroFill(this.seconds(), 2);
1675 function meridiem (token
, lowercase
) {
1676 addFormatToken(token
, 0, 0, function () {
1677 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase
);
1681 meridiem('a', true);
1682 meridiem('A', false);
1686 addUnitAlias('hour', 'h');
1689 addUnitPriority('hour', 13);
1693 function matchMeridiem (isStrict
, locale
) {
1694 return locale
._meridiemParse
;
1697 addRegexToken('a', matchMeridiem
);
1698 addRegexToken('A', matchMeridiem
);
1699 addRegexToken('H', match1to2
);
1700 addRegexToken('h', match1to2
);
1701 addRegexToken('k', match1to2
);
1702 addRegexToken('HH', match1to2
, match2
);
1703 addRegexToken('hh', match1to2
, match2
);
1704 addRegexToken('kk', match1to2
, match2
);
1706 addRegexToken('hmm', match3to4
);
1707 addRegexToken('hmmss', match5to6
);
1708 addRegexToken('Hmm', match3to4
);
1709 addRegexToken('Hmmss', match5to6
);
1711 addParseToken(['H', 'HH'], HOUR
);
1712 addParseToken(['k', 'kk'], function (input
, array
, config
) {
1713 var kInput
= toInt(input
);
1714 array
[HOUR
] = kInput
=== 24 ? 0 : kInput
;
1716 addParseToken(['a', 'A'], function (input
, array
, config
) {
1717 config
._isPm
= config
._locale
.isPM(input
);
1718 config
._meridiem
= input
;
1720 addParseToken(['h', 'hh'], function (input
, array
, config
) {
1721 array
[HOUR
] = toInt(input
);
1722 getParsingFlags(config
).bigHour
= true;
1724 addParseToken('hmm', function (input
, array
, config
) {
1725 var pos
= input
.length
- 2;
1726 array
[HOUR
] = toInt(input
.substr(0, pos
));
1727 array
[MINUTE
] = toInt(input
.substr(pos
));
1728 getParsingFlags(config
).bigHour
= true;
1730 addParseToken('hmmss', function (input
, array
, config
) {
1731 var pos1
= input
.length
- 4;
1732 var pos2
= input
.length
- 2;
1733 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1734 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1735 array
[SECOND
] = toInt(input
.substr(pos2
));
1736 getParsingFlags(config
).bigHour
= true;
1738 addParseToken('Hmm', function (input
, array
, config
) {
1739 var pos
= input
.length
- 2;
1740 array
[HOUR
] = toInt(input
.substr(0, pos
));
1741 array
[MINUTE
] = toInt(input
.substr(pos
));
1743 addParseToken('Hmmss', function (input
, array
, config
) {
1744 var pos1
= input
.length
- 4;
1745 var pos2
= input
.length
- 2;
1746 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1747 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1748 array
[SECOND
] = toInt(input
.substr(pos2
));
1753 function localeIsPM (input
) {
1754 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
1755 // Using charAt should be more compatible.
1756 return ((input
+ '').toLowerCase().charAt(0) === 'p');
1759 var defaultLocaleMeridiemParse
= /[ap]\.?m?\.?/i;
1760 function localeMeridiem (hours
, minutes
, isLower
) {
1762 return isLower
? 'pm' : 'PM';
1764 return isLower
? 'am' : 'AM';
1771 // Setting the hour should keep the time, because the user explicitly
1772 // specified which hour he wants. So trying to maintain the same hour (in
1773 // a new timezone) makes sense. Adding/subtracting hours does not follow
1775 var getSetHour
= makeGetSet('Hours', true);
1782 calendar
: defaultCalendar
,
1783 longDateFormat
: defaultLongDateFormat
,
1784 invalidDate
: defaultInvalidDate
,
1785 ordinal
: defaultOrdinal
,
1786 dayOfMonthOrdinalParse
: defaultDayOfMonthOrdinalParse
,
1787 relativeTime
: defaultRelativeTime
,
1789 months
: defaultLocaleMonths
,
1790 monthsShort
: defaultLocaleMonthsShort
,
1792 week
: defaultLocaleWeek
,
1794 weekdays
: defaultLocaleWeekdays
,
1795 weekdaysMin
: defaultLocaleWeekdaysMin
,
1796 weekdaysShort
: defaultLocaleWeekdaysShort
,
1798 meridiemParse
: defaultLocaleMeridiemParse
1801 // internal storage for locale config files
1803 var localeFamilies
= {};
1806 function normalizeLocale(key
) {
1807 return key
? key
.toLowerCase().replace('_', '-') : key
;
1810 // pick the locale from the array
1811 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
1812 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
1813 function chooseLocale(names
) {
1814 var i
= 0, j
, next
, locale
, split
;
1816 while (i
< names
.length
) {
1817 split
= normalizeLocale(names
[i
]).split('-');
1819 next
= normalizeLocale(names
[i
+ 1]);
1820 next
= next
? next
.split('-') : null;
1822 locale
= loadLocale(split
.slice(0, j
).join('-'));
1826 if (next
&& next
.length
>= j
&& compareArrays(split
, next
, true) >= j
- 1) {
1827 //the next array item is better than a shallower substring of this one
1837 function loadLocale(name
) {
1838 var oldLocale
= null;
1839 // TODO: Find a better way to register and load all the locales in Node
1840 if (!locales
[name
] && (typeof module
!== 'undefined') &&
1841 module
&& module
.exports
) {
1843 oldLocale
= globalLocale
._abbr
;
1844 var aliasedRequire
= require
;
1845 aliasedRequire('./locale/' + name
);
1846 getSetGlobalLocale(oldLocale
);
1849 return locales
[name
];
1852 // This function will load locale and then set the global locale. If
1853 // no arguments are passed in, it will simply return the current global
1855 function getSetGlobalLocale (key
, values
) {
1858 if (isUndefined(values
)) {
1859 data
= getLocale(key
);
1862 data
= defineLocale(key
, values
);
1866 // moment.duration._locale = moment._locale = data;
1867 globalLocale
= data
;
1871 return globalLocale
._abbr
;
1874 function defineLocale (name
, config
) {
1875 if (config
!== null) {
1876 var parentConfig
= baseConfig
;
1878 if (locales
[name
] != null) {
1879 deprecateSimple('defineLocaleOverride',
1880 'use moment.updateLocale(localeName, config) to change ' +
1881 'an existing locale. moment.defineLocale(localeName, ' +
1882 'config) should only be used for creating a new locale ' +
1883 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
1884 parentConfig
= locales
[name
]._config
;
1885 } else if (config
.parentLocale
!= null) {
1886 if (locales
[config
.parentLocale
] != null) {
1887 parentConfig
= locales
[config
.parentLocale
]._config
;
1889 if (!localeFamilies
[config
.parentLocale
]) {
1890 localeFamilies
[config
.parentLocale
] = [];
1892 localeFamilies
[config
.parentLocale
].push({
1899 locales
[name
] = new Locale(mergeConfigs(parentConfig
, config
));
1901 if (localeFamilies
[name
]) {
1902 localeFamilies
[name
].forEach(function (x
) {
1903 defineLocale(x
.name
, x
.config
);
1907 // backwards compat for now: also set the locale
1908 // make sure we set the locale AFTER all child locales have been
1909 // created, so we won't end up with the child locale set.
1910 getSetGlobalLocale(name
);
1913 return locales
[name
];
1915 // useful for testing
1916 delete locales
[name
];
1921 function updateLocale(name
, config
) {
1922 if (config
!= null) {
1923 var locale
, tmpLocale
, parentConfig
= baseConfig
;
1925 tmpLocale
= loadLocale(name
);
1926 if (tmpLocale
!= null) {
1927 parentConfig
= tmpLocale
._config
;
1929 config
= mergeConfigs(parentConfig
, config
);
1930 locale
= new Locale(config
);
1931 locale
.parentLocale
= locales
[name
];
1932 locales
[name
] = locale
;
1934 // backwards compat for now: also set the locale
1935 getSetGlobalLocale(name
);
1937 // pass null for config to unupdate, useful for tests
1938 if (locales
[name
] != null) {
1939 if (locales
[name
].parentLocale
!= null) {
1940 locales
[name
] = locales
[name
].parentLocale
;
1941 } else if (locales
[name
] != null) {
1942 delete locales
[name
];
1946 return locales
[name
];
1949 // returns locale data
1950 function getLocale (key
) {
1953 if (key
&& key
._locale
&& key
._locale
._abbr
) {
1954 key
= key
._locale
._abbr
;
1958 return globalLocale
;
1961 if (!isArray(key
)) {
1962 //short-circuit everything else
1963 locale
= loadLocale(key
);
1970 return chooseLocale(key
);
1973 function listLocales() {
1974 return keys(locales
);
1977 function checkOverflow (m
) {
1981 if (a
&& getParsingFlags(m
).overflow
=== -2) {
1983 a
[MONTH
] < 0 || a
[MONTH
] > 11 ? MONTH
:
1984 a
[DATE
] < 1 || a
[DATE
] > daysInMonth(a
[YEAR
], a
[MONTH
]) ? DATE
:
1985 a
[HOUR
] < 0 || a
[HOUR
] > 24 || (a
[HOUR
] === 24 && (a
[MINUTE
] !== 0 || a
[SECOND
] !== 0 || a
[MILLISECOND
] !== 0)) ? HOUR
:
1986 a
[MINUTE
] < 0 || a
[MINUTE
] > 59 ? MINUTE
:
1987 a
[SECOND
] < 0 || a
[SECOND
] > 59 ? SECOND
:
1988 a
[MILLISECOND
] < 0 || a
[MILLISECOND
] > 999 ? MILLISECOND
:
1991 if (getParsingFlags(m
)._overflowDayOfYear
&& (overflow
< YEAR
|| overflow
> DATE
)) {
1994 if (getParsingFlags(m
)._overflowWeeks
&& overflow
=== -1) {
1997 if (getParsingFlags(m
)._overflowWeekday
&& overflow
=== -1) {
2001 getParsingFlags(m
).overflow
= overflow
;
2007 // Pick the first defined of two or three arguments.
2008 function defaults(a
, b
, c
) {
2018 function currentDateArray(config
) {
2019 // hooks is actually the exported moment object
2020 var nowValue
= new Date(hooks
.now());
2021 if (config
._useUTC
) {
2022 return [nowValue
.getUTCFullYear(), nowValue
.getUTCMonth(), nowValue
.getUTCDate()];
2024 return [nowValue
.getFullYear(), nowValue
.getMonth(), nowValue
.getDate()];
2027 // convert an array to a date.
2028 // the array should mirror the parameters below
2029 // note: all values past the year are optional and will default to the lowest possible value.
2030 // [year, month, day , hour, minute, second, millisecond]
2031 function configFromArray (config
) {
2032 var i
, date
, input
= [], currentDate
, yearToUse
;
2038 currentDate
= currentDateArray(config
);
2040 //compute day of the year from weeks and weekdays
2041 if (config
._w
&& config
._a
[DATE
] == null && config
._a
[MONTH
] == null) {
2042 dayOfYearFromWeekInfo(config
);
2045 //if the day of the year is set, figure out what it is
2046 if (config
._dayOfYear
!= null) {
2047 yearToUse
= defaults(config
._a
[YEAR
], currentDate
[YEAR
]);
2049 if (config
._dayOfYear
> daysInYear(yearToUse
) || config
._dayOfYear
=== 0) {
2050 getParsingFlags(config
)._overflowDayOfYear
= true;
2053 date
= createUTCDate(yearToUse
, 0, config
._dayOfYear
);
2054 config
._a
[MONTH
] = date
.getUTCMonth();
2055 config
._a
[DATE
] = date
.getUTCDate();
2058 // Default to current date.
2059 // * if no year, month, day of month are given, default to today
2060 // * if day of month is given, default month and year
2061 // * if month is given, default only year
2062 // * if year is given, don't default anything
2063 for (i
= 0; i
< 3 && config
._a
[i
] == null; ++i
) {
2064 config
._a
[i
] = input
[i
] = currentDate
[i
];
2067 // Zero out whatever was not defaulted, including time
2068 for (; i
< 7; i
++) {
2069 config
._a
[i
] = input
[i
] = (config
._a
[i
] == null) ? (i
=== 2 ? 1 : 0) : config
._a
[i
];
2072 // Check for 24:00:00.000
2073 if (config
._a
[HOUR
] === 24 &&
2074 config
._a
[MINUTE
] === 0 &&
2075 config
._a
[SECOND
] === 0 &&
2076 config
._a
[MILLISECOND
] === 0) {
2077 config
._nextDay
= true;
2078 config
._a
[HOUR
] = 0;
2081 config
._d
= (config
._useUTC
? createUTCDate
: createDate
).apply(null, input
);
2082 // Apply timezone offset from input. The actual utcOffset can be changed
2084 if (config
._tzm
!= null) {
2085 config
._d
.setUTCMinutes(config
._d
.getUTCMinutes() - config
._tzm
);
2088 if (config
._nextDay
) {
2089 config
._a
[HOUR
] = 24;
2092 // check for mismatching day of week
2093 if (config
._w
&& typeof config
._w
.d
!== 'undefined' && config
._w
.d
!== config
._d
.getDay()) {
2094 getParsingFlags(config
).weekdayMismatch
= true;
2098 function dayOfYearFromWeekInfo(config
) {
2099 var w
, weekYear
, week
, weekday
, dow
, doy
, temp
, weekdayOverflow
;
2102 if (w
.GG
!= null || w
.W
!= null || w
.E
!= null) {
2106 // TODO: We need to take the current isoWeekYear, but that depends on
2107 // how we interpret now (local, utc, fixed offset). So create
2108 // a now version of current config (take local/utc/offset flags, and
2110 weekYear
= defaults(w
.GG
, config
._a
[YEAR
], weekOfYear(createLocal(), 1, 4).year
);
2111 week
= defaults(w
.W
, 1);
2112 weekday
= defaults(w
.E
, 1);
2113 if (weekday
< 1 || weekday
> 7) {
2114 weekdayOverflow
= true;
2117 dow
= config
._locale
._week
.dow
;
2118 doy
= config
._locale
._week
.doy
;
2120 var curWeek
= weekOfYear(createLocal(), dow
, doy
);
2122 weekYear
= defaults(w
.gg
, config
._a
[YEAR
], curWeek
.year
);
2124 // Default to current week.
2125 week
= defaults(w
.w
, curWeek
.week
);
2128 // weekday -- low day numbers are considered next week
2130 if (weekday
< 0 || weekday
> 6) {
2131 weekdayOverflow
= true;
2133 } else if (w
.e
!= null) {
2134 // local weekday -- counting starts from begining of week
2135 weekday
= w
.e
+ dow
;
2136 if (w
.e
< 0 || w
.e
> 6) {
2137 weekdayOverflow
= true;
2140 // default to begining of week
2144 if (week
< 1 || week
> weeksInYear(weekYear
, dow
, doy
)) {
2145 getParsingFlags(config
)._overflowWeeks
= true;
2146 } else if (weekdayOverflow
!= null) {
2147 getParsingFlags(config
)._overflowWeekday
= true;
2149 temp
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
);
2150 config
._a
[YEAR
] = temp
.year
;
2151 config
._dayOfYear
= temp
.dayOfYear
;
2156 // 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)
2157 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)?)?$/;
2158 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)?)?$/;
2160 var tzRegex
= /Z|[+-]\d\d(?::?\d\d)?/;
2163 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
2164 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
2165 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
2166 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
2167 ['YYYY-DDD', /\d{4}-\d{3}/],
2168 ['YYYY-MM', /\d{4}-\d\d/, false],
2169 ['YYYYYYMMDD', /[+-]\d{10}/],
2170 ['YYYYMMDD', /\d{8}/],
2171 // YYYYMM is NOT allowed by the standard
2172 ['GGGG[W]WWE', /\d{4}W\d{3}/],
2173 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
2174 ['YYYYDDD', /\d{7}/]
2177 // iso time formats and regexes
2179 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
2180 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
2181 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
2182 ['HH:mm', /\d\d:\d\d/],
2183 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
2184 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
2185 ['HHmmss', /\d\d\d\d\d\d/],
2186 ['HHmm', /\d\d\d\d/],
2190 var aspNetJsonRegex
= /^\/?Date\((\-?\d+)/i;
2192 // date from iso format
2193 function configFromISO(config
) {
2196 match
= extendedIsoRegex
.exec(string
) || basicIsoRegex
.exec(string
),
2197 allowTime
, dateFormat
, timeFormat
, tzFormat
;
2200 getParsingFlags(config
).iso
= true;
2202 for (i
= 0, l
= isoDates
.length
; i
< l
; i
++) {
2203 if (isoDates
[i
][1].exec(match
[1])) {
2204 dateFormat
= isoDates
[i
][0];
2205 allowTime
= isoDates
[i
][2] !== false;
2209 if (dateFormat
== null) {
2210 config
._isValid
= false;
2214 for (i
= 0, l
= isoTimes
.length
; i
< l
; i
++) {
2215 if (isoTimes
[i
][1].exec(match
[3])) {
2216 // match[2] should be 'T' or space
2217 timeFormat
= (match
[2] || ' ') + isoTimes
[i
][0];
2221 if (timeFormat
== null) {
2222 config
._isValid
= false;
2226 if (!allowTime
&& timeFormat
!= null) {
2227 config
._isValid
= false;
2231 if (tzRegex
.exec(match
[4])) {
2234 config
._isValid
= false;
2238 config
._f
= dateFormat
+ (timeFormat
|| '') + (tzFormat
|| '');
2239 configFromStringAndFormat(config
);
2241 config
._isValid
= false;
2245 // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
2246 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}))$/;
2248 function extractFromRFC2822Strings(yearStr
, monthStr
, dayStr
, hourStr
, minuteStr
, secondStr
) {
2250 untruncateYear(yearStr
),
2251 defaultLocaleMonthsShort
.indexOf(monthStr
),
2252 parseInt(dayStr
, 10),
2253 parseInt(hourStr
, 10),
2254 parseInt(minuteStr
, 10)
2258 result
.push(parseInt(secondStr
, 10));
2264 function untruncateYear(yearStr
) {
2265 var year
= parseInt(yearStr
, 10);
2268 } else if (year
<= 999) {
2274 function preprocessRFC2822(s
) {
2275 // Remove comments and folding whitespace and replace multiple-spaces with a single space
2276 return s
.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
2279 function checkWeekday(weekdayStr
, parsedInput
, config
) {
2281 // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
2282 var weekdayProvided
= defaultLocaleWeekdaysShort
.indexOf(weekdayStr
),
2283 weekdayActual
= new Date(parsedInput
[0], parsedInput
[1], parsedInput
[2]).getDay();
2284 if (weekdayProvided
!== weekdayActual
) {
2285 getParsingFlags(config
).weekdayMismatch
= true;
2286 config
._isValid
= false;
2306 function calculateOffset(obsOffset
, militaryOffset
, numOffset
) {
2308 return obsOffsets
[obsOffset
];
2309 } else if (militaryOffset
) {
2310 // the only allowed military tz is Z
2313 var hm
= parseInt(numOffset
, 10);
2314 var m
= hm
% 100, h
= (hm
- m
) / 100;
2319 // date and time from ref 2822 format
2320 function configFromRFC2822(config
) {
2321 var match
= rfc2822
.exec(preprocessRFC2822(config
._i
));
2323 var parsedArray
= extractFromRFC2822Strings(match
[4], match
[3], match
[2], match
[5], match
[6], match
[7]);
2324 if (!checkWeekday(match
[1], parsedArray
, config
)) {
2328 config
._a
= parsedArray
;
2329 config
._tzm
= calculateOffset(match
[8], match
[9], match
[10]);
2331 config
._d
= createUTCDate
.apply(null, config
._a
);
2332 config
._d
.setUTCMinutes(config
._d
.getUTCMinutes() - config
._tzm
);
2334 getParsingFlags(config
).rfc2822
= true;
2336 config
._isValid
= false;
2340 // date from iso format or fallback
2341 function configFromString(config
) {
2342 var matched
= aspNetJsonRegex
.exec(config
._i
);
2344 if (matched
!== null) {
2345 config
._d
= new Date(+matched
[1]);
2349 configFromISO(config
);
2350 if (config
._isValid
=== false) {
2351 delete config
._isValid
;
2356 configFromRFC2822(config
);
2357 if (config
._isValid
=== false) {
2358 delete config
._isValid
;
2363 // Final attempt, use Input Fallback
2364 hooks
.createFromInputFallback(config
);
2367 hooks
.createFromInputFallback
= deprecate(
2368 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
2369 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
2370 'discouraged and will be removed in an upcoming major release. Please refer to ' +
2371 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
2373 config
._d
= new Date(config
._i
+ (config
._useUTC
? ' UTC' : ''));
2377 // constant that refers to the ISO standard
2378 hooks
.ISO_8601 = function () {};
2380 // constant that refers to the RFC 2822 form
2381 hooks
.RFC_2822 = function () {};
2383 // date from string and format string
2384 function configFromStringAndFormat(config
) {
2385 // TODO: Move this to another part of the creation flow to prevent circular deps
2386 if (config
._f
=== hooks
.ISO_8601
) {
2387 configFromISO(config
);
2390 if (config
._f
=== hooks
.RFC_2822
) {
2391 configFromRFC2822(config
);
2395 getParsingFlags(config
).empty
= true;
2397 // This array is used to make a Date, either with `new Date` or `Date.UTC`
2398 var string
= '' + config
._i
,
2399 i
, parsedInput
, tokens
, token
, skipped
,
2400 stringLength
= string
.length
,
2401 totalParsedInputLength
= 0;
2403 tokens
= expandFormat(config
._f
, config
._locale
).match(formattingTokens
) || [];
2405 for (i
= 0; i
< tokens
.length
; i
++) {
2407 parsedInput
= (string
.match(getParseRegexForToken(token
, config
)) || [])[0];
2408 // console.log('token', token, 'parsedInput', parsedInput,
2409 // 'regex', getParseRegexForToken(token, config));
2411 skipped
= string
.substr(0, string
.indexOf(parsedInput
));
2412 if (skipped
.length
> 0) {
2413 getParsingFlags(config
).unusedInput
.push(skipped
);
2415 string
= string
.slice(string
.indexOf(parsedInput
) + parsedInput
.length
);
2416 totalParsedInputLength
+= parsedInput
.length
;
2418 // don't parse if it's not a known token
2419 if (formatTokenFunctions
[token
]) {
2421 getParsingFlags(config
).empty
= false;
2424 getParsingFlags(config
).unusedTokens
.push(token
);
2426 addTimeToArrayFromToken(token
, parsedInput
, config
);
2428 else if (config
._strict
&& !parsedInput
) {
2429 getParsingFlags(config
).unusedTokens
.push(token
);
2433 // add remaining unparsed input length to the string
2434 getParsingFlags(config
).charsLeftOver
= stringLength
- totalParsedInputLength
;
2435 if (string
.length
> 0) {
2436 getParsingFlags(config
).unusedInput
.push(string
);
2439 // clear _12h flag if hour is <= 12
2440 if (config
._a
[HOUR
] <= 12 &&
2441 getParsingFlags(config
).bigHour
=== true &&
2442 config
._a
[HOUR
] > 0) {
2443 getParsingFlags(config
).bigHour
= undefined;
2446 getParsingFlags(config
).parsedDateParts
= config
._a
.slice(0);
2447 getParsingFlags(config
).meridiem
= config
._meridiem
;
2449 config
._a
[HOUR
] = meridiemFixWrap(config
._locale
, config
._a
[HOUR
], config
._meridiem
);
2451 configFromArray(config
);
2452 checkOverflow(config
);
2456 function meridiemFixWrap (locale
, hour
, meridiem
) {
2459 if (meridiem
== null) {
2463 if (locale
.meridiemHour
!= null) {
2464 return locale
.meridiemHour(hour
, meridiem
);
2465 } else if (locale
.isPM
!= null) {
2467 isPm
= locale
.isPM(meridiem
);
2468 if (isPm
&& hour
< 12) {
2471 if (!isPm
&& hour
=== 12) {
2476 // this is not supposed to happen
2481 // date from string and array of format strings
2482 function configFromStringAndArray(config
) {
2490 if (config
._f
.length
=== 0) {
2491 getParsingFlags(config
).invalidFormat
= true;
2492 config
._d
= new Date(NaN
);
2496 for (i
= 0; i
< config
._f
.length
; i
++) {
2498 tempConfig
= copyConfig({}, config
);
2499 if (config
._useUTC
!= null) {
2500 tempConfig
._useUTC
= config
._useUTC
;
2502 tempConfig
._f
= config
._f
[i
];
2503 configFromStringAndFormat(tempConfig
);
2505 if (!isValid(tempConfig
)) {
2509 // if there is any input that was not parsed add a penalty for that format
2510 currentScore
+= getParsingFlags(tempConfig
).charsLeftOver
;
2513 currentScore
+= getParsingFlags(tempConfig
).unusedTokens
.length
* 10;
2515 getParsingFlags(tempConfig
).score
= currentScore
;
2517 if (scoreToBeat
== null || currentScore
< scoreToBeat
) {
2518 scoreToBeat
= currentScore
;
2519 bestMoment
= tempConfig
;
2523 extend(config
, bestMoment
|| tempConfig
);
2526 function configFromObject(config
) {
2531 var i
= normalizeObjectUnits(config
._i
);
2532 config
._a
= map([i
.year
, i
.month
, i
.day
|| i
.date
, i
.hour
, i
.minute
, i
.second
, i
.millisecond
], function (obj
) {
2533 return obj
&& parseInt(obj
, 10);
2536 configFromArray(config
);
2539 function createFromConfig (config
) {
2540 var res
= new Moment(checkOverflow(prepareConfig(config
)));
2542 // Adding is smart enough around DST
2544 res
._nextDay
= undefined;
2550 function prepareConfig (config
) {
2551 var input
= config
._i
,
2554 config
._locale
= config
._locale
|| getLocale(config
._l
);
2556 if (input
=== null || (format
=== undefined && input
=== '')) {
2557 return createInvalid({nullInput
: true});
2560 if (typeof input
=== 'string') {
2561 config
._i
= input
= config
._locale
.preparse(input
);
2564 if (isMoment(input
)) {
2565 return new Moment(checkOverflow(input
));
2566 } else if (isDate(input
)) {
2568 } else if (isArray(format
)) {
2569 configFromStringAndArray(config
);
2570 } else if (format
) {
2571 configFromStringAndFormat(config
);
2573 configFromInput(config
);
2576 if (!isValid(config
)) {
2583 function configFromInput(config
) {
2584 var input
= config
._i
;
2585 if (isUndefined(input
)) {
2586 config
._d
= new Date(hooks
.now());
2587 } else if (isDate(input
)) {
2588 config
._d
= new Date(input
.valueOf());
2589 } else if (typeof input
=== 'string') {
2590 configFromString(config
);
2591 } else if (isArray(input
)) {
2592 config
._a
= map(input
.slice(0), function (obj
) {
2593 return parseInt(obj
, 10);
2595 configFromArray(config
);
2596 } else if (isObject(input
)) {
2597 configFromObject(config
);
2598 } else if (isNumber(input
)) {
2599 // from milliseconds
2600 config
._d
= new Date(input
);
2602 hooks
.createFromInputFallback(config
);
2606 function createLocalOrUTC (input
, format
, locale
, strict
, isUTC
) {
2609 if (locale
=== true || locale
=== false) {
2614 if ((isObject(input
) && isObjectEmpty(input
)) ||
2615 (isArray(input
) && input
.length
=== 0)) {
2618 // object construction must be done this way.
2619 // https://github.com/moment/moment/issues/1423
2620 c
._isAMomentObject
= true;
2621 c
._useUTC
= c
._isUTC
= isUTC
;
2627 return createFromConfig(c
);
2630 function createLocal (input
, format
, locale
, strict
) {
2631 return createLocalOrUTC(input
, format
, locale
, strict
, false);
2634 var prototypeMin
= deprecate(
2635 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
2637 var other
= createLocal
.apply(null, arguments
);
2638 if (this.isValid() && other
.isValid()) {
2639 return other
< this ? this : other
;
2641 return createInvalid();
2646 var prototypeMax
= deprecate(
2647 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
2649 var other
= createLocal
.apply(null, arguments
);
2650 if (this.isValid() && other
.isValid()) {
2651 return other
> this ? this : other
;
2653 return createInvalid();
2658 // Pick a moment m from moments so that m[fn](other) is true for all
2659 // other. This relies on the function fn to be transitive.
2661 // moments should either be an array of moment objects or an array, whose
2662 // first element is an array of moment objects.
2663 function pickBy(fn
, moments
) {
2665 if (moments
.length
=== 1 && isArray(moments
[0])) {
2666 moments
= moments
[0];
2668 if (!moments
.length
) {
2669 return createLocal();
2672 for (i
= 1; i
< moments
.length
; ++i
) {
2673 if (!moments
[i
].isValid() || moments
[i
][fn
](res
)) {
2680 // TODO: Use [].sort instead?
2682 var args
= [].slice
.call(arguments
, 0);
2684 return pickBy('isBefore', args
);
2688 var args
= [].slice
.call(arguments
, 0);
2690 return pickBy('isAfter', args
);
2693 var now = function () {
2694 return Date
.now
? Date
.now() : +(new Date());
2697 var ordering
= ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
2699 function isDurationValid(m
) {
2700 for (var key
in m
) {
2701 if (!(indexOf
.call(ordering
, key
) !== -1 && (m
[key
] == null || !isNaN(m
[key
])))) {
2706 var unitHasDecimal
= false;
2707 for (var i
= 0; i
< ordering
.length
; ++i
) {
2708 if (m
[ordering
[i
]]) {
2709 if (unitHasDecimal
) {
2710 return false; // only allow non-integers for smallest unit
2712 if (parseFloat(m
[ordering
[i
]]) !== toInt(m
[ordering
[i
]])) {
2713 unitHasDecimal
= true;
2721 function isValid
$1() {
2722 return this._isValid
;
2725 function createInvalid
$1() {
2726 return createDuration(NaN
);
2729 function Duration (duration
) {
2730 var normalizedInput
= normalizeObjectUnits(duration
),
2731 years
= normalizedInput
.year
|| 0,
2732 quarters
= normalizedInput
.quarter
|| 0,
2733 months
= normalizedInput
.month
|| 0,
2734 weeks
= normalizedInput
.week
|| 0,
2735 days
= normalizedInput
.day
|| 0,
2736 hours
= normalizedInput
.hour
|| 0,
2737 minutes
= normalizedInput
.minute
|| 0,
2738 seconds
= normalizedInput
.second
|| 0,
2739 milliseconds
= normalizedInput
.millisecond
|| 0;
2741 this._isValid
= isDurationValid(normalizedInput
);
2743 // representation for dateAddRemove
2744 this._milliseconds
= +milliseconds
+
2745 seconds
* 1e3
+ // 1000
2746 minutes
* 6e4
+ // 1000 * 60
2747 hours
* 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
2748 // Because of dateAddRemove treats 24 hours as different from a
2749 // day when working around DST, we need to store them separately
2750 this._days
= +days
+
2752 // It is impossible to translate months into days without knowing
2753 // which months you are are talking about, so we have to store
2755 this._months
= +months
+
2761 this._locale
= getLocale();
2766 function isDuration (obj
) {
2767 return obj
instanceof Duration
;
2770 function absRound (number
) {
2772 return Math
.round(-1 * number
) * -1;
2774 return Math
.round(number
);
2780 function offset (token
, separator
) {
2781 addFormatToken(token
, 0, 0, function () {
2782 var offset
= this.utcOffset();
2788 return sign
+ zeroFill(~~(offset
/ 60), 2) + separator
+ zeroFill(~~(offset
) % 60, 2);
2797 addRegexToken('Z', matchShortOffset
);
2798 addRegexToken('ZZ', matchShortOffset
);
2799 addParseToken(['Z', 'ZZ'], function (input
, array
, config
) {
2800 config
._useUTC
= true;
2801 config
._tzm
= offsetFromString(matchShortOffset
, input
);
2807 // '+10:00' > ['10', '00']
2808 // '-1530' > ['-15', '30']
2809 var chunkOffset
= /([\+\-]|\d\d)/gi;
2811 function offsetFromString(matcher
, string
) {
2812 var matches
= (string
|| '').match(matcher
);
2814 if (matches
=== null) {
2818 var chunk
= matches
[matches
.length
- 1] || [];
2819 var parts
= (chunk
+ '').match(chunkOffset
) || ['-', 0, 0];
2820 var minutes
= +(parts
[1] * 60) + toInt(parts
[2]);
2822 return minutes
=== 0 ?
2824 parts
[0] === '+' ? minutes
: -minutes
;
2827 // Return a moment from input, that is local/utc/zone equivalent to model.
2828 function cloneWithOffset(input
, model
) {
2831 res
= model
.clone();
2832 diff
= (isMoment(input
) || isDate(input
) ? input
.valueOf() : createLocal(input
).valueOf()) - res
.valueOf();
2833 // Use low-level api, because this fn is low-level api.
2834 res
._d
.setTime(res
._d
.valueOf() + diff
);
2835 hooks
.updateOffset(res
, false);
2838 return createLocal(input
).local();
2842 function getDateOffset (m
) {
2843 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
2844 // https://github.com/moment/moment/pull/1871
2845 return -Math
.round(m
._d
.getTimezoneOffset() / 15) * 15;
2850 // This function will be called whenever a moment is mutated.
2851 // It is intended to keep the offset in sync with the timezone.
2852 hooks
.updateOffset = function () {};
2856 // keepLocalTime = true means only change the timezone, without
2857 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
2858 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
2859 // +0200, so we adjust the time as needed, to be valid.
2861 // Keeping the time actually adds/subtracts (one hour)
2862 // from the actual represented time. That is why we call updateOffset
2863 // a second time. In case it wants us to change the offset again
2864 // _changeInProgress == true case, then we have to adjust, because
2865 // there is no such time in the given timezone.
2866 function getSetOffset (input
, keepLocalTime
, keepMinutes
) {
2867 var offset
= this._offset
|| 0,
2869 if (!this.isValid()) {
2870 return input
!= null ? this : NaN
;
2872 if (input
!= null) {
2873 if (typeof input
=== 'string') {
2874 input
= offsetFromString(matchShortOffset
, input
);
2875 if (input
=== null) {
2878 } else if (Math
.abs(input
) < 16 && !keepMinutes
) {
2881 if (!this._isUTC
&& keepLocalTime
) {
2882 localAdjust
= getDateOffset(this);
2884 this._offset
= input
;
2886 if (localAdjust
!= null) {
2887 this.add(localAdjust
, 'm');
2889 if (offset
!== input
) {
2890 if (!keepLocalTime
|| this._changeInProgress
) {
2891 addSubtract(this, createDuration(input
- offset
, 'm'), 1, false);
2892 } else if (!this._changeInProgress
) {
2893 this._changeInProgress
= true;
2894 hooks
.updateOffset(this, true);
2895 this._changeInProgress
= null;
2900 return this._isUTC
? offset
: getDateOffset(this);
2904 function getSetZone (input
, keepLocalTime
) {
2905 if (input
!= null) {
2906 if (typeof input
!== 'string') {
2910 this.utcOffset(input
, keepLocalTime
);
2914 return -this.utcOffset();
2918 function setOffsetToUTC (keepLocalTime
) {
2919 return this.utcOffset(0, keepLocalTime
);
2922 function setOffsetToLocal (keepLocalTime
) {
2924 this.utcOffset(0, keepLocalTime
);
2925 this._isUTC
= false;
2927 if (keepLocalTime
) {
2928 this.subtract(getDateOffset(this), 'm');
2934 function setOffsetToParsedOffset () {
2935 if (this._tzm
!= null) {
2936 this.utcOffset(this._tzm
, false, true);
2937 } else if (typeof this._i
=== 'string') {
2938 var tZone
= offsetFromString(matchOffset
, this._i
);
2939 if (tZone
!= null) {
2940 this.utcOffset(tZone
);
2943 this.utcOffset(0, true);
2949 function hasAlignedHourOffset (input
) {
2950 if (!this.isValid()) {
2953 input
= input
? createLocal(input
).utcOffset() : 0;
2955 return (this.utcOffset() - input
) % 60 === 0;
2958 function isDaylightSavingTime () {
2960 this.utcOffset() > this.clone().month(0).utcOffset() ||
2961 this.utcOffset() > this.clone().month(5).utcOffset()
2965 function isDaylightSavingTimeShifted () {
2966 if (!isUndefined(this._isDSTShifted
)) {
2967 return this._isDSTShifted
;
2972 copyConfig(c
, this);
2973 c
= prepareConfig(c
);
2976 var other
= c
._isUTC
? createUTC(c
._a
) : createLocal(c
._a
);
2977 this._isDSTShifted
= this.isValid() &&
2978 compareArrays(c
._a
, other
.toArray()) > 0;
2980 this._isDSTShifted
= false;
2983 return this._isDSTShifted
;
2986 function isLocal () {
2987 return this.isValid() ? !this._isUTC
: false;
2990 function isUtcOffset () {
2991 return this.isValid() ? this._isUTC
: false;
2995 return this.isValid() ? this._isUTC
&& this._offset
=== 0 : false;
2998 // ASP.NET json date format regex
2999 var aspNetRegex
= /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
3001 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
3002 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
3003 // and further modified to allow for strings containing both week and day
3004 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)?)?$/;
3006 function createDuration (input
, key
) {
3007 var duration
= input
,
3008 // matching against regexp is expensive, do it on demand
3014 if (isDuration(input
)) {
3016 ms
: input
._milliseconds
,
3020 } else if (isNumber(input
)) {
3023 duration
[key
] = input
;
3025 duration
.milliseconds
= input
;
3027 } else if (!!(match
= aspNetRegex
.exec(input
))) {
3028 sign
= (match
[1] === '-') ? -1 : 1;
3031 d
: toInt(match
[DATE
]) * sign
,
3032 h
: toInt(match
[HOUR
]) * sign
,
3033 m
: toInt(match
[MINUTE
]) * sign
,
3034 s
: toInt(match
[SECOND
]) * sign
,
3035 ms
: toInt(absRound(match
[MILLISECOND
] * 1000)) * sign
// the millisecond decimal point is included in the match
3037 } else if (!!(match
= isoRegex
.exec(input
))) {
3038 sign
= (match
[1] === '-') ? -1 : (match
[1] === '+') ? 1 : 1;
3040 y
: parseIso(match
[2], sign
),
3041 M
: parseIso(match
[3], sign
),
3042 w
: parseIso(match
[4], sign
),
3043 d
: parseIso(match
[5], sign
),
3044 h
: parseIso(match
[6], sign
),
3045 m
: parseIso(match
[7], sign
),
3046 s
: parseIso(match
[8], sign
)
3048 } else if (duration
== null) {// checks for null or undefined
3050 } else if (typeof duration
=== 'object' && ('from' in duration
|| 'to' in duration
)) {
3051 diffRes
= momentsDifference(createLocal(duration
.from), createLocal(duration
.to
));
3054 duration
.ms
= diffRes
.milliseconds
;
3055 duration
.M
= diffRes
.months
;
3058 ret
= new Duration(duration
);
3060 if (isDuration(input
) && hasOwnProp(input
, '_locale')) {
3061 ret
._locale
= input
._locale
;
3067 createDuration
.fn
= Duration
.prototype;
3068 createDuration
.invalid
= createInvalid
$1;
3070 function parseIso (inp
, sign
) {
3071 // We'd normally use ~~inp for this, but unfortunately it also
3072 // converts floats to ints.
3073 // inp may be undefined, so careful calling replace on it.
3074 var res
= inp
&& parseFloat(inp
.replace(',', '.'));
3075 // apply sign while we're at it
3076 return (isNaN(res
) ? 0 : res
) * sign
;
3079 function positiveMomentsDifference(base
, other
) {
3080 var res
= {milliseconds
: 0, months
: 0};
3082 res
.months
= other
.month() - base
.month() +
3083 (other
.year() - base
.year()) * 12;
3084 if (base
.clone().add(res
.months
, 'M').isAfter(other
)) {
3088 res
.milliseconds
= +other
- +(base
.clone().add(res
.months
, 'M'));
3093 function momentsDifference(base
, other
) {
3095 if (!(base
.isValid() && other
.isValid())) {
3096 return {milliseconds
: 0, months
: 0};
3099 other
= cloneWithOffset(other
, base
);
3100 if (base
.isBefore(other
)) {
3101 res
= positiveMomentsDifference(base
, other
);
3103 res
= positiveMomentsDifference(other
, base
);
3104 res
.milliseconds
= -res
.milliseconds
;
3105 res
.months
= -res
.months
;
3111 // TODO: remove 'name' arg after deprecation is removed
3112 function createAdder(direction
, name
) {
3113 return function (val
, period
) {
3115 //invert the arguments, but complain about it
3116 if (period
!== null && !isNaN(+period
)) {
3117 deprecateSimple(name
, 'moment().' + name
+ '(period, number) is deprecated. Please use moment().' + name
+ '(number, period). ' +
3118 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
3119 tmp
= val
; val
= period
; period
= tmp
;
3122 val
= typeof val
=== 'string' ? +val
: val
;
3123 dur
= createDuration(val
, period
);
3124 addSubtract(this, dur
, direction
);
3129 function addSubtract (mom
, duration
, isAdding
, updateOffset
) {
3130 var milliseconds
= duration
._milliseconds
,
3131 days
= absRound(duration
._days
),
3132 months
= absRound(duration
._months
);
3134 if (!mom
.isValid()) {
3139 updateOffset
= updateOffset
== null ? true : updateOffset
;
3142 setMonth(mom
, get(mom
, 'Month') + months
* isAdding
);
3145 set$1(mom
, 'Date', get(mom
, 'Date') + days
* isAdding
);
3148 mom
._d
.setTime(mom
._d
.valueOf() + milliseconds
* isAdding
);
3151 hooks
.updateOffset(mom
, days
|| months
);
3155 var add
= createAdder(1, 'add');
3156 var subtract
= createAdder(-1, 'subtract');
3158 function getCalendarFormat(myMoment
, now
) {
3159 var diff
= myMoment
.diff(now
, 'days', true);
3160 return diff
< -6 ? 'sameElse' :
3161 diff
< -1 ? 'lastWeek' :
3162 diff
< 0 ? 'lastDay' :
3163 diff
< 1 ? 'sameDay' :
3164 diff
< 2 ? 'nextDay' :
3165 diff
< 7 ? 'nextWeek' : 'sameElse';
3168 function calendar
$1 (time
, formats
) {
3169 // We want to compare the start of today, vs this.
3170 // Getting start-of-today depends on whether we're local/utc/offset or not.
3171 var now
= time
|| createLocal(),
3172 sod
= cloneWithOffset(now
, this).startOf('day'),
3173 format
= hooks
.calendarFormat(this, sod
) || 'sameElse';
3175 var output
= formats
&& (isFunction(formats
[format
]) ? formats
[format
].call(this, now
) : formats
[format
]);
3177 return this.format(output
|| this.localeData().calendar(format
, this, createLocal(now
)));
3181 return new Moment(this);
3184 function isAfter (input
, units
) {
3185 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3186 if (!(this.isValid() && localInput
.isValid())) {
3189 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3190 if (units
=== 'millisecond') {
3191 return this.valueOf() > localInput
.valueOf();
3193 return localInput
.valueOf() < this.clone().startOf(units
).valueOf();
3197 function isBefore (input
, units
) {
3198 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3199 if (!(this.isValid() && localInput
.isValid())) {
3202 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3203 if (units
=== 'millisecond') {
3204 return this.valueOf() < localInput
.valueOf();
3206 return this.clone().endOf(units
).valueOf() < localInput
.valueOf();
3210 function isBetween (from, to
, units
, inclusivity
) {
3211 inclusivity
= inclusivity
|| '()';
3212 return (inclusivity
[0] === '(' ? this.isAfter(from, units
) : !this.isBefore(from, units
)) &&
3213 (inclusivity
[1] === ')' ? this.isBefore(to
, units
) : !this.isAfter(to
, units
));
3216 function isSame (input
, units
) {
3217 var localInput
= isMoment(input
) ? input
: createLocal(input
),
3219 if (!(this.isValid() && localInput
.isValid())) {
3222 units
= normalizeUnits(units
|| 'millisecond');
3223 if (units
=== 'millisecond') {
3224 return this.valueOf() === localInput
.valueOf();
3226 inputMs
= localInput
.valueOf();
3227 return this.clone().startOf(units
).valueOf() <= inputMs
&& inputMs
<= this.clone().endOf(units
).valueOf();
3231 function isSameOrAfter (input
, units
) {
3232 return this.isSame(input
, units
) || this.isAfter(input
,units
);
3235 function isSameOrBefore (input
, units
) {
3236 return this.isSame(input
, units
) || this.isBefore(input
,units
);
3239 function diff (input
, units
, asFloat
) {
3244 if (!this.isValid()) {
3248 that
= cloneWithOffset(input
, this);
3250 if (!that
.isValid()) {
3254 zoneDelta
= (that
.utcOffset() - this.utcOffset()) * 6e4
;
3256 units
= normalizeUnits(units
);
3259 case 'year': output
= monthDiff(this, that
) / 12; break;
3260 case 'month': output
= monthDiff(this, that
); break;
3261 case 'quarter': output
= monthDiff(this, that
) / 3; break;
3262 case 'second': output
= (this - that
) / 1e3
; break; // 1000
3263 case 'minute': output
= (this - that
) / 6e4
; break; // 1000 * 60
3264 case 'hour': output
= (this - that
) / 36e5
; break; // 1000 * 60 * 60
3265 case 'day': output
= (this - that
- zoneDelta
) / 864e5
; break; // 1000 * 60 * 60 * 24, negate dst
3266 case 'week': output
= (this - that
- zoneDelta
) / 6048e5
; break; // 1000 * 60 * 60 * 24 * 7, negate dst
3267 default: output
= this - that
;
3270 return asFloat
? output
: absFloor(output
);
3273 function monthDiff (a
, b
) {
3274 // difference in months
3275 var wholeMonthDiff
= ((b
.year() - a
.year()) * 12) + (b
.month() - a
.month()),
3276 // b is in (anchor - 1 month, anchor + 1 month)
3277 anchor
= a
.clone().add(wholeMonthDiff
, 'months'),
3280 if (b
- anchor
< 0) {
3281 anchor2
= a
.clone().add(wholeMonthDiff
- 1, 'months');
3282 // linear across the month
3283 adjust
= (b
- anchor
) / (anchor
- anchor2
);
3285 anchor2
= a
.clone().add(wholeMonthDiff
+ 1, 'months');
3286 // linear across the month
3287 adjust
= (b
- anchor
) / (anchor2
- anchor
);
3290 //check for negative zero, return zero if negative zero
3291 return -(wholeMonthDiff
+ adjust
) || 0;
3294 hooks
.defaultFormat
= 'YYYY-MM-DDTHH:mm:ssZ';
3295 hooks
.defaultFormatUtc
= 'YYYY-MM-DDTHH:mm:ss[Z]';
3297 function toString () {
3298 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
3301 function toISOString() {
3302 if (!this.isValid()) {
3305 var m
= this.clone().utc();
3306 if (m
.year() < 0 || m
.year() > 9999) {
3307 return formatMoment(m
, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
3309 if (isFunction(Date
.prototype.toISOString
)) {
3310 // native implementation is ~50x faster, use it when we can
3311 return this.toDate().toISOString();
3313 return formatMoment(m
, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
3317 * Return a human readable representation of a moment that can
3318 * also be evaluated to get a new moment which is the same
3320 * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
3322 function inspect () {
3323 if (!this.isValid()) {
3324 return 'moment.invalid(/* ' + this._i
+ ' */)';
3326 var func
= 'moment';
3328 if (!this.isLocal()) {
3329 func
= this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
3332 var prefix
= '[' + func
+ '("]';
3333 var year
= (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
3334 var datetime
= '-MM-DD[T]HH:mm:ss.SSS';
3335 var suffix
= zone
+ '[")]';
3337 return this.format(prefix
+ year
+ datetime
+ suffix
);
3340 function format (inputString
) {
3342 inputString
= this.isUtc() ? hooks
.defaultFormatUtc
: hooks
.defaultFormat
;
3344 var output
= formatMoment(this, inputString
);
3345 return this.localeData().postformat(output
);
3348 function from (time
, withoutSuffix
) {
3349 if (this.isValid() &&
3350 ((isMoment(time
) && time
.isValid()) ||
3351 createLocal(time
).isValid())) {
3352 return createDuration({to
: this, from: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3354 return this.localeData().invalidDate();
3358 function fromNow (withoutSuffix
) {
3359 return this.from(createLocal(), withoutSuffix
);
3362 function to (time
, withoutSuffix
) {
3363 if (this.isValid() &&
3364 ((isMoment(time
) && time
.isValid()) ||
3365 createLocal(time
).isValid())) {
3366 return createDuration({from: this, to
: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3368 return this.localeData().invalidDate();
3372 function toNow (withoutSuffix
) {
3373 return this.to(createLocal(), withoutSuffix
);
3376 // If passed a locale key, it will set the locale for this
3377 // instance. Otherwise, it will return the locale configuration
3378 // variables for this instance.
3379 function locale (key
) {
3382 if (key
=== undefined) {
3383 return this._locale
._abbr
;
3385 newLocaleData
= getLocale(key
);
3386 if (newLocaleData
!= null) {
3387 this._locale
= newLocaleData
;
3393 var lang
= deprecate(
3394 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
3396 if (key
=== undefined) {
3397 return this.localeData();
3399 return this.locale(key
);
3404 function localeData () {
3405 return this._locale
;
3408 function startOf (units
) {
3409 units
= normalizeUnits(units
);
3410 // the following switch intentionally omits break keywords
3411 // to utilize falling through the cases.
3433 this.milliseconds(0);
3436 // weeks are a special case
3437 if (units
=== 'week') {
3440 if (units
=== 'isoWeek') {
3444 // quarters are also special
3445 if (units
=== 'quarter') {
3446 this.month(Math
.floor(this.month() / 3) * 3);
3452 function endOf (units
) {
3453 units
= normalizeUnits(units
);
3454 if (units
=== undefined || units
=== 'millisecond') {
3458 // 'date' is an alias for 'day', so it should be considered as such.
3459 if (units
=== 'date') {
3463 return this.startOf(units
).add(1, (units
=== 'isoWeek' ? 'week' : units
)).subtract(1, 'ms');
3466 function valueOf () {
3467 return this._d
.valueOf() - ((this._offset
|| 0) * 60000);
3471 return Math
.floor(this.valueOf() / 1000);
3474 function toDate () {
3475 return new Date(this.valueOf());
3478 function toArray () {
3480 return [m
.year(), m
.month(), m
.date(), m
.hour(), m
.minute(), m
.second(), m
.millisecond()];
3483 function toObject () {
3490 minutes
: m
.minutes(),
3491 seconds
: m
.seconds(),
3492 milliseconds
: m
.milliseconds()
3496 function toJSON () {
3497 // new Date(NaN).toJSON() === null
3498 return this.isValid() ? this.toISOString() : null;
3501 function isValid
$2 () {
3502 return isValid(this);
3505 function parsingFlags () {
3506 return extend({}, getParsingFlags(this));
3509 function invalidAt () {
3510 return getParsingFlags(this).overflow
;
3513 function creationData() {
3517 locale
: this._locale
,
3519 strict
: this._strict
3525 addFormatToken(0, ['gg', 2], 0, function () {
3526 return this.weekYear() % 100;
3529 addFormatToken(0, ['GG', 2], 0, function () {
3530 return this.isoWeekYear() % 100;
3533 function addWeekYearFormatToken (token
, getter
) {
3534 addFormatToken(0, [token
, token
.length
], 0, getter
);
3537 addWeekYearFormatToken('gggg', 'weekYear');
3538 addWeekYearFormatToken('ggggg', 'weekYear');
3539 addWeekYearFormatToken('GGGG', 'isoWeekYear');
3540 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
3544 addUnitAlias('weekYear', 'gg');
3545 addUnitAlias('isoWeekYear', 'GG');
3549 addUnitPriority('weekYear', 1);
3550 addUnitPriority('isoWeekYear', 1);
3555 addRegexToken('G', matchSigned
);
3556 addRegexToken('g', matchSigned
);
3557 addRegexToken('GG', match1to2
, match2
);
3558 addRegexToken('gg', match1to2
, match2
);
3559 addRegexToken('GGGG', match1to4
, match4
);
3560 addRegexToken('gggg', match1to4
, match4
);
3561 addRegexToken('GGGGG', match1to6
, match6
);
3562 addRegexToken('ggggg', match1to6
, match6
);
3564 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input
, week
, config
, token
) {
3565 week
[token
.substr(0, 2)] = toInt(input
);
3568 addWeekParseToken(['gg', 'GG'], function (input
, week
, config
, token
) {
3569 week
[token
] = hooks
.parseTwoDigitYear(input
);
3574 function getSetWeekYear (input
) {
3575 return getSetWeekYearHelper
.call(this,
3579 this.localeData()._week
.dow
,
3580 this.localeData()._week
.doy
);
3583 function getSetISOWeekYear (input
) {
3584 return getSetWeekYearHelper
.call(this,
3585 input
, this.isoWeek(), this.isoWeekday(), 1, 4);
3588 function getISOWeeksInYear () {
3589 return weeksInYear(this.year(), 1, 4);
3592 function getWeeksInYear () {
3593 var weekInfo
= this.localeData()._week
;
3594 return weeksInYear(this.year(), weekInfo
.dow
, weekInfo
.doy
);
3597 function getSetWeekYearHelper(input
, week
, weekday
, dow
, doy
) {
3599 if (input
== null) {
3600 return weekOfYear(this, dow
, doy
).year
;
3602 weeksTarget
= weeksInYear(input
, dow
, doy
);
3603 if (week
> weeksTarget
) {
3606 return setWeekAll
.call(this, input
, week
, weekday
, dow
, doy
);
3610 function setWeekAll(weekYear
, week
, weekday
, dow
, doy
) {
3611 var dayOfYearData
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
),
3612 date
= createUTCDate(dayOfYearData
.year
, 0, dayOfYearData
.dayOfYear
);
3614 this.year(date
.getUTCFullYear());
3615 this.month(date
.getUTCMonth());
3616 this.date(date
.getUTCDate());
3622 addFormatToken('Q', 0, 'Qo', 'quarter');
3626 addUnitAlias('quarter', 'Q');
3630 addUnitPriority('quarter', 7);
3634 addRegexToken('Q', match1
);
3635 addParseToken('Q', function (input
, array
) {
3636 array
[MONTH
] = (toInt(input
) - 1) * 3;
3641 function getSetQuarter (input
) {
3642 return input
== null ? Math
.ceil((this.month() + 1) / 3) : this.month((input
- 1) * 3 + this.month() % 3);
3647 addFormatToken('D', ['DD', 2], 'Do', 'date');
3651 addUnitAlias('date', 'D');
3654 addUnitPriority('date', 9);
3658 addRegexToken('D', match1to2
);
3659 addRegexToken('DD', match1to2
, match2
);
3660 addRegexToken('Do', function (isStrict
, locale
) {
3661 // TODO: Remove "ordinalParse" fallback in next major release.
3663 (locale
._dayOfMonthOrdinalParse
|| locale
._ordinalParse
) :
3664 locale
._dayOfMonthOrdinalParseLenient
;
3667 addParseToken(['D', 'DD'], DATE
);
3668 addParseToken('Do', function (input
, array
) {
3669 array
[DATE
] = toInt(input
.match(match1to2
)[0], 10);
3674 var getSetDayOfMonth
= makeGetSet('Date', true);
3678 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
3682 addUnitAlias('dayOfYear', 'DDD');
3685 addUnitPriority('dayOfYear', 4);
3689 addRegexToken('DDD', match1to3
);
3690 addRegexToken('DDDD', match3
);
3691 addParseToken(['DDD', 'DDDD'], function (input
, array
, config
) {
3692 config
._dayOfYear
= toInt(input
);
3699 function getSetDayOfYear (input
) {
3700 var dayOfYear
= Math
.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
) + 1;
3701 return input
== null ? dayOfYear
: this.add((input
- dayOfYear
), 'd');
3706 addFormatToken('m', ['mm', 2], 0, 'minute');
3710 addUnitAlias('minute', 'm');
3714 addUnitPriority('minute', 14);
3718 addRegexToken('m', match1to2
);
3719 addRegexToken('mm', match1to2
, match2
);
3720 addParseToken(['m', 'mm'], MINUTE
);
3724 var getSetMinute
= makeGetSet('Minutes', false);
3728 addFormatToken('s', ['ss', 2], 0, 'second');
3732 addUnitAlias('second', 's');
3736 addUnitPriority('second', 15);
3740 addRegexToken('s', match1to2
);
3741 addRegexToken('ss', match1to2
, match2
);
3742 addParseToken(['s', 'ss'], SECOND
);
3746 var getSetSecond
= makeGetSet('Seconds', false);
3750 addFormatToken('S', 0, 0, function () {
3751 return ~~(this.millisecond() / 100);
3754 addFormatToken(0, ['SS', 2], 0, function () {
3755 return ~~(this.millisecond() / 10);
3758 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
3759 addFormatToken(0, ['SSSS', 4], 0, function () {
3760 return this.millisecond() * 10;
3762 addFormatToken(0, ['SSSSS', 5], 0, function () {
3763 return this.millisecond() * 100;
3765 addFormatToken(0, ['SSSSSS', 6], 0, function () {
3766 return this.millisecond() * 1000;
3768 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
3769 return this.millisecond() * 10000;
3771 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
3772 return this.millisecond() * 100000;
3774 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
3775 return this.millisecond() * 1000000;
3781 addUnitAlias('millisecond', 'ms');
3785 addUnitPriority('millisecond', 16);
3789 addRegexToken('S', match1to3
, match1
);
3790 addRegexToken('SS', match1to3
, match2
);
3791 addRegexToken('SSS', match1to3
, match3
);
3794 for (token
= 'SSSS'; token
.length
<= 9; token
+= 'S') {
3795 addRegexToken(token
, matchUnsigned
);
3798 function parseMs(input
, array
) {
3799 array
[MILLISECOND
] = toInt(('0.' + input
) * 1000);
3802 for (token
= 'S'; token
.length
<= 9; token
+= 'S') {
3803 addParseToken(token
, parseMs
);
3807 var getSetMillisecond
= makeGetSet('Milliseconds', false);
3811 addFormatToken('z', 0, 0, 'zoneAbbr');
3812 addFormatToken('zz', 0, 0, 'zoneName');
3816 function getZoneAbbr () {
3817 return this._isUTC
? 'UTC' : '';
3820 function getZoneName () {
3821 return this._isUTC
? 'Coordinated Universal Time' : '';
3824 var proto
= Moment
.prototype;
3827 proto
.calendar
= calendar
$1;
3828 proto
.clone
= clone
;
3830 proto
.endOf
= endOf
;
3831 proto
.format
= format
;
3833 proto
.fromNow
= fromNow
;
3835 proto
.toNow
= toNow
;
3836 proto
.get = stringGet
;
3837 proto
.invalidAt
= invalidAt
;
3838 proto
.isAfter
= isAfter
;
3839 proto
.isBefore
= isBefore
;
3840 proto
.isBetween
= isBetween
;
3841 proto
.isSame
= isSame
;
3842 proto
.isSameOrAfter
= isSameOrAfter
;
3843 proto
.isSameOrBefore
= isSameOrBefore
;
3844 proto
.isValid
= isValid
$2;
3846 proto
.locale
= locale
;
3847 proto
.localeData
= localeData
;
3848 proto
.max
= prototypeMax
;
3849 proto
.min
= prototypeMin
;
3850 proto
.parsingFlags
= parsingFlags
;
3851 proto
.set = stringSet
;
3852 proto
.startOf
= startOf
;
3853 proto
.subtract
= subtract
;
3854 proto
.toArray
= toArray
;
3855 proto
.toObject
= toObject
;
3856 proto
.toDate
= toDate
;
3857 proto
.toISOString
= toISOString
;
3858 proto
.inspect
= inspect
;
3859 proto
.toJSON
= toJSON
;
3860 proto
.toString
= toString
;
3862 proto
.valueOf
= valueOf
;
3863 proto
.creationData
= creationData
;
3866 proto
.year
= getSetYear
;
3867 proto
.isLeapYear
= getIsLeapYear
;
3870 proto
.weekYear
= getSetWeekYear
;
3871 proto
.isoWeekYear
= getSetISOWeekYear
;
3874 proto
.quarter
= proto
.quarters
= getSetQuarter
;
3877 proto
.month
= getSetMonth
;
3878 proto
.daysInMonth
= getDaysInMonth
;
3881 proto
.week
= proto
.weeks
= getSetWeek
;
3882 proto
.isoWeek
= proto
.isoWeeks
= getSetISOWeek
;
3883 proto
.weeksInYear
= getWeeksInYear
;
3884 proto
.isoWeeksInYear
= getISOWeeksInYear
;
3887 proto
.date
= getSetDayOfMonth
;
3888 proto
.day
= proto
.days
= getSetDayOfWeek
;
3889 proto
.weekday
= getSetLocaleDayOfWeek
;
3890 proto
.isoWeekday
= getSetISODayOfWeek
;
3891 proto
.dayOfYear
= getSetDayOfYear
;
3894 proto
.hour
= proto
.hours
= getSetHour
;
3897 proto
.minute
= proto
.minutes
= getSetMinute
;
3900 proto
.second
= proto
.seconds
= getSetSecond
;
3903 proto
.millisecond
= proto
.milliseconds
= getSetMillisecond
;
3906 proto
.utcOffset
= getSetOffset
;
3907 proto
.utc
= setOffsetToUTC
;
3908 proto
.local
= setOffsetToLocal
;
3909 proto
.parseZone
= setOffsetToParsedOffset
;
3910 proto
.hasAlignedHourOffset
= hasAlignedHourOffset
;
3911 proto
.isDST
= isDaylightSavingTime
;
3912 proto
.isLocal
= isLocal
;
3913 proto
.isUtcOffset
= isUtcOffset
;
3914 proto
.isUtc
= isUtc
;
3915 proto
.isUTC
= isUtc
;
3918 proto
.zoneAbbr
= getZoneAbbr
;
3919 proto
.zoneName
= getZoneName
;
3922 proto
.dates
= deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth
);
3923 proto
.months
= deprecate('months accessor is deprecated. Use month instead', getSetMonth
);
3924 proto
.years
= deprecate('years accessor is deprecated. Use year instead', getSetYear
);
3925 proto
.zone
= deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone
);
3926 proto
.isDSTShifted
= deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted
);
3928 function createUnix (input
) {
3929 return createLocal(input
* 1000);
3932 function createInZone () {
3933 return createLocal
.apply(null, arguments
).parseZone();
3936 function preParsePostFormat (string
) {
3940 var proto
$1 = Locale
.prototype;
3942 proto
$1.calendar
= calendar
;
3943 proto
$1.longDateFormat
= longDateFormat
;
3944 proto
$1.invalidDate
= invalidDate
;
3945 proto
$1.ordinal
= ordinal
;
3946 proto
$1.preparse
= preParsePostFormat
;
3947 proto
$1.postformat
= preParsePostFormat
;
3948 proto
$1.relativeTime
= relativeTime
;
3949 proto
$1.pastFuture
= pastFuture
;
3953 proto
$1.months
= localeMonths
;
3954 proto
$1.monthsShort
= localeMonthsShort
;
3955 proto
$1.monthsParse
= localeMonthsParse
;
3956 proto
$1.monthsRegex
= monthsRegex
;
3957 proto
$1.monthsShortRegex
= monthsShortRegex
;
3960 proto
$1.week
= localeWeek
;
3961 proto
$1.firstDayOfYear
= localeFirstDayOfYear
;
3962 proto
$1.firstDayOfWeek
= localeFirstDayOfWeek
;
3965 proto
$1.weekdays
= localeWeekdays
;
3966 proto
$1.weekdaysMin
= localeWeekdaysMin
;
3967 proto
$1.weekdaysShort
= localeWeekdaysShort
;
3968 proto
$1.weekdaysParse
= localeWeekdaysParse
;
3970 proto
$1.weekdaysRegex
= weekdaysRegex
;
3971 proto
$1.weekdaysShortRegex
= weekdaysShortRegex
;
3972 proto
$1.weekdaysMinRegex
= weekdaysMinRegex
;
3975 proto
$1.isPM
= localeIsPM
;
3976 proto
$1.meridiem
= localeMeridiem
;
3978 function get$1 (format
, index
, field
, setter
) {
3979 var locale
= getLocale();
3980 var utc
= createUTC().set(setter
, index
);
3981 return locale
[field
](utc
, format
);
3984 function listMonthsImpl (format
, index
, field
) {
3985 if (isNumber(format
)) {
3990 format
= format
|| '';
3992 if (index
!= null) {
3993 return get$1(format
, index
, field
, 'month');
3998 for (i
= 0; i
< 12; i
++) {
3999 out
[i
] = get$1(format
, i
, field
, 'month');
4012 function listWeekdaysImpl (localeSorted
, format
, index
, field
) {
4013 if (typeof localeSorted
=== 'boolean') {
4014 if (isNumber(format
)) {
4019 format
= format
|| '';
4021 format
= localeSorted
;
4023 localeSorted
= false;
4025 if (isNumber(format
)) {
4030 format
= format
|| '';
4033 var locale
= getLocale(),
4034 shift
= localeSorted
? locale
._week
.dow
: 0;
4036 if (index
!= null) {
4037 return get$1(format
, (index
+ shift
) % 7, field
, 'day');
4042 for (i
= 0; i
< 7; i
++) {
4043 out
[i
] = get$1(format
, (i
+ shift
) % 7, field
, 'day');
4048 function listMonths (format
, index
) {
4049 return listMonthsImpl(format
, index
, 'months');
4052 function listMonthsShort (format
, index
) {
4053 return listMonthsImpl(format
, index
, 'monthsShort');
4056 function listWeekdays (localeSorted
, format
, index
) {
4057 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdays');
4060 function listWeekdaysShort (localeSorted
, format
, index
) {
4061 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysShort');
4064 function listWeekdaysMin (localeSorted
, format
, index
) {
4065 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysMin');
4068 getSetGlobalLocale('en', {
4069 dayOfMonthOrdinalParse
: /\d{1,2}(th|st|nd|rd)/,
4070 ordinal : function (number
) {
4071 var b
= number
% 10,
4072 output
= (toInt(number
% 100 / 10) === 1) ? 'th' :
4075 (b
=== 3) ? 'rd' : 'th';
4076 return number
+ output
;
4080 // Side effect imports
4081 hooks
.lang
= deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale
);
4082 hooks
.langData
= deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale
);
4084 var mathAbs
= Math
.abs
;
4087 var data
= this._data
;
4089 this._milliseconds
= mathAbs(this._milliseconds
);
4090 this._days
= mathAbs(this._days
);
4091 this._months
= mathAbs(this._months
);
4093 data
.milliseconds
= mathAbs(data
.milliseconds
);
4094 data
.seconds
= mathAbs(data
.seconds
);
4095 data
.minutes
= mathAbs(data
.minutes
);
4096 data
.hours
= mathAbs(data
.hours
);
4097 data
.months
= mathAbs(data
.months
);
4098 data
.years
= mathAbs(data
.years
);
4103 function addSubtract
$1 (duration
, input
, value
, direction
) {
4104 var other
= createDuration(input
, value
);
4106 duration
._milliseconds
+= direction
* other
._milliseconds
;
4107 duration
._days
+= direction
* other
._days
;
4108 duration
._months
+= direction
* other
._months
;
4110 return duration
._bubble();
4113 // supports only 2.0-style add(1, 's') or add(duration)
4114 function add
$1 (input
, value
) {
4115 return addSubtract
$1(this, input
, value
, 1);
4118 // supports only 2.0-style subtract(1, 's') or subtract(duration)
4119 function subtract
$1 (input
, value
) {
4120 return addSubtract
$1(this, input
, value
, -1);
4123 function absCeil (number
) {
4125 return Math
.floor(number
);
4127 return Math
.ceil(number
);
4131 function bubble () {
4132 var milliseconds
= this._milliseconds
;
4133 var days
= this._days
;
4134 var months
= this._months
;
4135 var data
= this._data
;
4136 var seconds
, minutes
, hours
, years
, monthsFromDays
;
4138 // if we have a mix of positive and negative values, bubble down first
4139 // check: https://github.com/moment/moment/issues/2166
4140 if (!((milliseconds
>= 0 && days
>= 0 && months
>= 0) ||
4141 (milliseconds
<= 0 && days
<= 0 && months
<= 0))) {
4142 milliseconds
+= absCeil(monthsToDays(months
) + days
) * 864e5
;
4147 // The following code bubbles up values, see the tests for
4148 // examples of what that means.
4149 data
.milliseconds
= milliseconds
% 1000;
4151 seconds
= absFloor(milliseconds
/ 1000);
4152 data
.seconds
= seconds
% 60;
4154 minutes
= absFloor(seconds
/ 60);
4155 data
.minutes
= minutes
% 60;
4157 hours
= absFloor(minutes
/ 60);
4158 data
.hours
= hours
% 24;
4160 days
+= absFloor(hours
/ 24);
4162 // convert days to months
4163 monthsFromDays
= absFloor(daysToMonths(days
));
4164 months
+= monthsFromDays
;
4165 days
-= absCeil(monthsToDays(monthsFromDays
));
4167 // 12 months -> 1 year
4168 years
= absFloor(months
/ 12);
4172 data
.months
= months
;
4178 function daysToMonths (days
) {
4179 // 400 years have 146097 days (taking into account leap year rules)
4180 // 400 years have 12 months === 4800
4181 return days
* 4800 / 146097;
4184 function monthsToDays (months
) {
4185 // the reverse of daysToMonths
4186 return months
* 146097 / 4800;
4189 function as (units
) {
4190 if (!this.isValid()) {
4195 var milliseconds
= this._milliseconds
;
4197 units
= normalizeUnits(units
);
4199 if (units
=== 'month' || units
=== 'year') {
4200 days
= this._days
+ milliseconds
/ 864e5
;
4201 months
= this._months
+ daysToMonths(days
);
4202 return units
=== 'month' ? months
: months
/ 12;
4204 // handle milliseconds separately because of floating point math errors (issue #1867)
4205 days
= this._days
+ Math
.round(monthsToDays(this._months
));
4207 case 'week' : return days
/ 7 + milliseconds
/ 6048e5
;
4208 case 'day' : return days
+ milliseconds
/ 864e5
;
4209 case 'hour' : return days
* 24 + milliseconds
/ 36e5
;
4210 case 'minute' : return days
* 1440 + milliseconds
/ 6e4
;
4211 case 'second' : return days
* 86400 + milliseconds
/ 1000;
4212 // Math.floor prevents floating point math errors here
4213 case 'millisecond': return Math
.floor(days
* 864e5
) + milliseconds
;
4214 default: throw new Error('Unknown unit ' + units
);
4219 // TODO: Use this.as('ms')?
4220 function valueOf
$1 () {
4221 if (!this.isValid()) {
4225 this._milliseconds
+
4226 this._days
* 864e5
+
4227 (this._months
% 12) * 2592e6
+
4228 toInt(this._months
/ 12) * 31536e6
4232 function makeAs (alias
) {
4233 return function () {
4234 return this.as(alias
);
4238 var asMilliseconds
= makeAs('ms');
4239 var asSeconds
= makeAs('s');
4240 var asMinutes
= makeAs('m');
4241 var asHours
= makeAs('h');
4242 var asDays
= makeAs('d');
4243 var asWeeks
= makeAs('w');
4244 var asMonths
= makeAs('M');
4245 var asYears
= makeAs('y');
4247 function clone
$1 () {
4248 return createDuration(this);
4251 function get$2 (units
) {
4252 units
= normalizeUnits(units
);
4253 return this.isValid() ? this[units
+ 's']() : NaN
;
4256 function makeGetter(name
) {
4257 return function () {
4258 return this.isValid() ? this._data
[name
] : NaN
;
4262 var milliseconds
= makeGetter('milliseconds');
4263 var seconds
= makeGetter('seconds');
4264 var minutes
= makeGetter('minutes');
4265 var hours
= makeGetter('hours');
4266 var days
= makeGetter('days');
4267 var months
= makeGetter('months');
4268 var years
= makeGetter('years');
4271 return absFloor(this.days() / 7);
4274 var round
= Math
.round
;
4276 ss
: 44, // a few seconds to seconds
4277 s
: 45, // seconds to minute
4278 m
: 45, // minutes to hour
4279 h
: 22, // hours to day
4280 d
: 26, // days to month
4281 M
: 11 // months to year
4284 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
4285 function substituteTimeAgo(string
, number
, withoutSuffix
, isFuture
, locale
) {
4286 return locale
.relativeTime(number
|| 1, !!withoutSuffix
, string
, isFuture
);
4289 function relativeTime
$1 (posNegDuration
, withoutSuffix
, locale
) {
4290 var duration
= createDuration(posNegDuration
).abs();
4291 var seconds
= round(duration
.as('s'));
4292 var minutes
= round(duration
.as('m'));
4293 var hours
= round(duration
.as('h'));
4294 var days
= round(duration
.as('d'));
4295 var months
= round(duration
.as('M'));
4296 var years
= round(duration
.as('y'));
4298 var a
= seconds
<= thresholds
.ss
&& ['s', seconds
] ||
4299 seconds
< thresholds
.s
&& ['ss', seconds
] ||
4300 minutes
<= 1 && ['m'] ||
4301 minutes
< thresholds
.m
&& ['mm', minutes
] ||
4302 hours
<= 1 && ['h'] ||
4303 hours
< thresholds
.h
&& ['hh', hours
] ||
4304 days
<= 1 && ['d'] ||
4305 days
< thresholds
.d
&& ['dd', days
] ||
4306 months
<= 1 && ['M'] ||
4307 months
< thresholds
.M
&& ['MM', months
] ||
4308 years
<= 1 && ['y'] || ['yy', years
];
4310 a
[2] = withoutSuffix
;
4311 a
[3] = +posNegDuration
> 0;
4313 return substituteTimeAgo
.apply(null, a
);
4316 // This function allows you to set the rounding function for relative time strings
4317 function getSetRelativeTimeRounding (roundingFunction
) {
4318 if (roundingFunction
=== undefined) {
4321 if (typeof(roundingFunction
) === 'function') {
4322 round
= roundingFunction
;
4328 // This function allows you to set a threshold for relative time strings
4329 function getSetRelativeTimeThreshold (threshold
, limit
) {
4330 if (thresholds
[threshold
] === undefined) {
4333 if (limit
=== undefined) {
4334 return thresholds
[threshold
];
4336 thresholds
[threshold
] = limit
;
4337 if (threshold
=== 's') {
4338 thresholds
.ss
= limit
- 1;
4343 function humanize (withSuffix
) {
4344 if (!this.isValid()) {
4345 return this.localeData().invalidDate();
4348 var locale
= this.localeData();
4349 var output
= relativeTime
$1(this, !withSuffix
, locale
);
4352 output
= locale
.pastFuture(+this, output
);
4355 return locale
.postformat(output
);
4358 var abs
$1 = Math
.abs
;
4361 return ((x
> 0) - (x
< 0)) || +x
;
4364 function toISOString
$1() {
4365 // for ISO strings we do not use the normal bubbling rules:
4366 // * milliseconds bubble up until they become hours
4367 // * days do not bubble at all
4368 // * months bubble up until they become years
4369 // This is because there is no context-free conversion between hours and days
4370 // (think of clock changes)
4371 // and also not between days and months (28-31 days per month)
4372 if (!this.isValid()) {
4373 return this.localeData().invalidDate();
4376 var seconds
= abs
$1(this._milliseconds
) / 1000;
4377 var days
= abs
$1(this._days
);
4378 var months
= abs
$1(this._months
);
4379 var minutes
, hours
, years
;
4381 // 3600 seconds -> 60 minutes -> 1 hour
4382 minutes
= absFloor(seconds
/ 60);
4383 hours
= absFloor(minutes
/ 60);
4387 // 12 months -> 1 year
4388 years
= absFloor(months
/ 12);
4392 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
4398 var s
= seconds
? seconds
.toFixed(3).replace(/\.?0+$/, '') : '';
4399 var total
= this.asSeconds();
4402 // this is the same as C#'s (Noda) and python (isodate)...
4403 // but not other JS (goog.date)
4407 var totalSign
= total
< 0 ? '-' : '';
4408 var ymSign
= sign(this._months
) !== sign(total
) ? '-' : '';
4409 var daysSign
= sign(this._days
) !== sign(total
) ? '-' : '';
4410 var hmsSign
= sign(this._milliseconds
) !== sign(total
) ? '-' : '';
4412 return totalSign
+ 'P' +
4413 (Y
? ymSign
+ Y
+ 'Y' : '') +
4414 (M
? ymSign
+ M
+ 'M' : '') +
4415 (D
? daysSign
+ D
+ 'D' : '') +
4416 ((h
|| m
|| s
) ? 'T' : '') +
4417 (h
? hmsSign
+ h
+ 'H' : '') +
4418 (m
? hmsSign
+ m
+ 'M' : '') +
4419 (s
? hmsSign
+ s
+ 'S' : '');
4422 var proto
$2 = Duration
.prototype;
4424 proto
$2.isValid
= isValid
$1;
4426 proto
$2.add
= add
$1;
4427 proto
$2.subtract
= subtract
$1;
4429 proto
$2.asMilliseconds
= asMilliseconds
;
4430 proto
$2.asSeconds
= asSeconds
;
4431 proto
$2.asMinutes
= asMinutes
;
4432 proto
$2.asHours
= asHours
;
4433 proto
$2.asDays
= asDays
;
4434 proto
$2.asWeeks
= asWeeks
;
4435 proto
$2.asMonths
= asMonths
;
4436 proto
$2.asYears
= asYears
;
4437 proto
$2.valueOf
= valueOf
$1;
4438 proto
$2._bubble
= bubble
;
4439 proto
$2.clone
= clone
$1;
4440 proto
$2.get = get$2;
4441 proto
$2.milliseconds
= milliseconds
;
4442 proto
$2.seconds
= seconds
;
4443 proto
$2.minutes
= minutes
;
4444 proto
$2.hours
= hours
;
4445 proto
$2.days
= days
;
4446 proto
$2.weeks
= weeks
;
4447 proto
$2.months
= months
;
4448 proto
$2.years
= years
;
4449 proto
$2.humanize
= humanize
;
4450 proto
$2.toISOString
= toISOString
$1;
4451 proto
$2.toString
= toISOString
$1;
4452 proto
$2.toJSON
= toISOString
$1;
4453 proto
$2.locale
= locale
;
4454 proto
$2.localeData
= localeData
;
4457 proto
$2.toIsoString
= deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString
$1);
4458 proto
$2.lang
= lang
;
4460 // Side effect imports
4464 addFormatToken('X', 0, 0, 'unix');
4465 addFormatToken('x', 0, 0, 'valueOf');
4469 addRegexToken('x', matchSigned
);
4470 addRegexToken('X', matchTimestamp
);
4471 addParseToken('X', function (input
, array
, config
) {
4472 config
._d
= new Date(parseFloat(input
, 10) * 1000);
4474 addParseToken('x', function (input
, array
, config
) {
4475 config
._d
= new Date(toInt(input
));
4478 // Side effect imports
4481 hooks
.version
= '2.19.3';
4483 setHookCallback(createLocal
);
4489 hooks
.utc
= createUTC
;
4490 hooks
.unix
= createUnix
;
4491 hooks
.months
= listMonths
;
4492 hooks
.isDate
= isDate
;
4493 hooks
.locale
= getSetGlobalLocale
;
4494 hooks
.invalid
= createInvalid
;
4495 hooks
.duration
= createDuration
;
4496 hooks
.isMoment
= isMoment
;
4497 hooks
.weekdays
= listWeekdays
;
4498 hooks
.parseZone
= createInZone
;
4499 hooks
.localeData
= getLocale
;
4500 hooks
.isDuration
= isDuration
;
4501 hooks
.monthsShort
= listMonthsShort
;
4502 hooks
.weekdaysMin
= listWeekdaysMin
;
4503 hooks
.defineLocale
= defineLocale
;
4504 hooks
.updateLocale
= updateLocale
;
4505 hooks
.locales
= listLocales
;
4506 hooks
.weekdaysShort
= listWeekdaysShort
;
4507 hooks
.normalizeUnits
= normalizeUnits
;
4508 hooks
.relativeTimeRounding
= getSetRelativeTimeRounding
;
4509 hooks
.relativeTimeThreshold
= getSetRelativeTimeThreshold
;
4510 hooks
.calendarFormat
= getCalendarFormat
;
4511 hooks
.prototype = proto
;