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
) {
38 // even if its not own property I'd still call it non-empty
44 function isUndefined(input
) {
45 return input
=== void 0;
48 function isNumber(input
) {
49 return typeof input
=== 'number' || Object
.prototype.toString
.call(input
) === '[object Number]';
52 function isDate(input
) {
53 return input
instanceof Date
|| Object
.prototype.toString
.call(input
) === '[object Date]';
56 function map(arr
, fn
) {
58 for (i
= 0; i
< arr
.length
; ++i
) {
59 res
.push(fn(arr
[i
], i
));
64 function hasOwnProp(a
, b
) {
65 return Object
.prototype.hasOwnProperty
.call(a
, b
);
68 function extend(a
, b
) {
70 if (hasOwnProp(b
, i
)) {
75 if (hasOwnProp(b
, 'toString')) {
76 a
.toString
= b
.toString
;
79 if (hasOwnProp(b
, 'valueOf')) {
80 a
.valueOf
= b
.valueOf
;
86 function createUTC (input
, format
, locale
, strict
) {
87 return createLocalOrUTC(input
, format
, locale
, strict
, true).utc();
90 function defaultParsingFlags() {
91 // We need to deep clone this object.
100 invalidFormat
: false,
101 userInvalidated
: false,
103 parsedDateParts
: [],
106 weekdayMismatch
: false
110 function getParsingFlags(m
) {
112 m
._pf
= defaultParsingFlags();
118 if (Array
.prototype.some
) {
119 some
= Array
.prototype.some
;
121 some = function (fun
) {
122 var t
= Object(this);
123 var len
= t
.length
>>> 0;
125 for (var i
= 0; i
< len
; i
++) {
126 if (i
in t
&& fun
.call(this, t
[i
], i
, t
)) {
137 function isValid(m
) {
138 if (m
._isValid
== null) {
139 var flags
= getParsingFlags(m
);
140 var parsedParts
= some
$1.call(flags
.parsedDateParts
, function (i
) {
143 var isNowValid
= !isNaN(m
._d
.getTime()) &&
144 flags
.overflow
< 0 &&
146 !flags
.invalidMonth
&&
147 !flags
.invalidWeekday
&&
149 !flags
.invalidFormat
&&
150 !flags
.userInvalidated
&&
151 (!flags
.meridiem
|| (flags
.meridiem
&& parsedParts
));
154 isNowValid
= isNowValid
&&
155 flags
.charsLeftOver
=== 0 &&
156 flags
.unusedTokens
.length
=== 0 &&
157 flags
.bigHour
=== undefined;
160 if (Object
.isFrozen
== null || !Object
.isFrozen(m
)) {
161 m
._isValid
= isNowValid
;
170 function createInvalid (flags
) {
171 var m
= createUTC(NaN
);
173 extend(getParsingFlags(m
), flags
);
176 getParsingFlags(m
).userInvalidated
= true;
182 // Plugins that add properties should also add the key here (null value),
183 // so we can properly clone ourselves.
184 var momentProperties
= hooks
.momentProperties
= [];
186 function copyConfig(to
, from) {
189 if (!isUndefined(from._isAMomentObject
)) {
190 to
._isAMomentObject
= from._isAMomentObject
;
192 if (!isUndefined(from._i
)) {
195 if (!isUndefined(from._f
)) {
198 if (!isUndefined(from._l
)) {
201 if (!isUndefined(from._strict
)) {
202 to
._strict
= from._strict
;
204 if (!isUndefined(from._tzm
)) {
207 if (!isUndefined(from._isUTC
)) {
208 to
._isUTC
= from._isUTC
;
210 if (!isUndefined(from._offset
)) {
211 to
._offset
= from._offset
;
213 if (!isUndefined(from._pf
)) {
214 to
._pf
= getParsingFlags(from);
216 if (!isUndefined(from._locale
)) {
217 to
._locale
= from._locale
;
220 if (momentProperties
.length
> 0) {
221 for (i
= 0; i
< momentProperties
.length
; i
++) {
222 prop
= momentProperties
[i
];
224 if (!isUndefined(val
)) {
233 var updateInProgress
= false;
235 // Moment prototype object
236 function Moment(config
) {
237 copyConfig(this, config
);
238 this._d
= new Date(config
._d
!= null ? config
._d
.getTime() : NaN
);
239 if (!this.isValid()) {
240 this._d
= new Date(NaN
);
242 // Prevent infinite loop in case updateOffset creates new moment
244 if (updateInProgress
=== false) {
245 updateInProgress
= true;
246 hooks
.updateOffset(this);
247 updateInProgress
= false;
251 function isMoment (obj
) {
252 return obj
instanceof Moment
|| (obj
!= null && obj
._isAMomentObject
!= null);
255 function absFloor (number
) {
258 return Math
.ceil(number
) || 0;
260 return Math
.floor(number
);
264 function toInt(argumentForCoercion
) {
265 var coercedNumber
= +argumentForCoercion
,
268 if (coercedNumber
!== 0 && isFinite(coercedNumber
)) {
269 value
= absFloor(coercedNumber
);
275 // compare two arrays, return the number of differences
276 function compareArrays(array1
, array2
, dontConvert
) {
277 var len
= Math
.min(array1
.length
, array2
.length
),
278 lengthDiff
= Math
.abs(array1
.length
- array2
.length
),
281 for (i
= 0; i
< len
; i
++) {
282 if ((dontConvert
&& array1
[i
] !== array2
[i
]) ||
283 (!dontConvert
&& toInt(array1
[i
]) !== toInt(array2
[i
]))) {
287 return diffs
+ lengthDiff
;
291 if (hooks
.suppressDeprecationWarnings
=== false &&
292 (typeof console
!== 'undefined') && console
.warn
) {
293 console
.warn('Deprecation warning: ' + msg
);
297 function deprecate(msg
, fn
) {
298 var firstTime
= true;
300 return extend(function () {
301 if (hooks
.deprecationHandler
!= null) {
302 hooks
.deprecationHandler(null, msg
);
307 for (var i
= 0; i
< arguments
.length
; i
++) {
309 if (typeof arguments
[i
] === 'object') {
310 arg
+= '\n[' + i
+ '] ';
311 for (var key
in arguments
[0]) {
312 arg
+= key
+ ': ' + arguments
[0][key
] + ', ';
314 arg
= arg
.slice(0, -2); // Remove trailing comma and space
320 warn(msg
+ '\nArguments: ' + Array
.prototype.slice
.call(args
).join('') + '\n' + (new Error()).stack
);
323 return fn
.apply(this, arguments
);
327 var deprecations
= {};
329 function deprecateSimple(name
, msg
) {
330 if (hooks
.deprecationHandler
!= null) {
331 hooks
.deprecationHandler(name
, msg
);
333 if (!deprecations
[name
]) {
335 deprecations
[name
] = true;
339 hooks
.suppressDeprecationWarnings
= false;
340 hooks
.deprecationHandler
= null;
342 function isFunction(input
) {
343 return input
instanceof Function
|| Object
.prototype.toString
.call(input
) === '[object Function]';
346 function set (config
) {
350 if (isFunction(prop
)) {
353 this['_' + i
] = prop
;
356 this._config
= config
;
357 // Lenient ordinal parsing accepts just a number in addition to
358 // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
359 // TODO: Remove "ordinalParse" fallback in next major release.
360 this._dayOfMonthOrdinalParseLenient
= new RegExp(
361 (this._dayOfMonthOrdinalParse
.source
|| this._ordinalParse
.source
) +
362 '|' + (/\d{1,2}/).source
);
365 function mergeConfigs(parentConfig
, childConfig
) {
366 var res
= extend({}, parentConfig
), prop
;
367 for (prop
in childConfig
) {
368 if (hasOwnProp(childConfig
, prop
)) {
369 if (isObject(parentConfig
[prop
]) && isObject(childConfig
[prop
])) {
371 extend(res
[prop
], parentConfig
[prop
]);
372 extend(res
[prop
], childConfig
[prop
]);
373 } else if (childConfig
[prop
] != null) {
374 res
[prop
] = childConfig
[prop
];
380 for (prop
in parentConfig
) {
381 if (hasOwnProp(parentConfig
, prop
) &&
382 !hasOwnProp(childConfig
, prop
) &&
383 isObject(parentConfig
[prop
])) {
384 // make sure changes to properties don't modify parent config
385 res
[prop
] = extend({}, res
[prop
]);
391 function Locale(config
) {
392 if (config
!= null) {
402 keys = function (obj
) {
405 if (hasOwnProp(obj
, i
)) {
415 var defaultCalendar
= {
416 sameDay
: '[Today at] LT',
417 nextDay
: '[Tomorrow at] LT',
418 nextWeek
: 'dddd [at] LT',
419 lastDay
: '[Yesterday at] LT',
420 lastWeek
: '[Last] dddd [at] LT',
424 function calendar (key
, mom
, now
) {
425 var output
= this._calendar
[key
] || this._calendar
['sameElse'];
426 return isFunction(output
) ? output
.call(mom
, now
) : output
;
429 var defaultLongDateFormat
= {
434 LLL
: 'MMMM D, YYYY h:mm A',
435 LLLL
: 'dddd, MMMM D, YYYY h:mm A'
438 function longDateFormat (key
) {
439 var format
= this._longDateFormat
[key
],
440 formatUpper
= this._longDateFormat
[key
.toUpperCase()];
442 if (format
|| !formatUpper
) {
446 this._longDateFormat
[key
] = formatUpper
.replace(/MMMM|MM|DD|dddd/g, function (val
) {
450 return this._longDateFormat
[key
];
453 var defaultInvalidDate
= 'Invalid date';
455 function invalidDate () {
456 return this._invalidDate
;
459 var defaultOrdinal
= '%d';
460 var defaultDayOfMonthOrdinalParse
= /\d{1,2}/;
462 function ordinal (number
) {
463 return this._ordinal
.replace('%d', number
);
466 var defaultRelativeTime
= {
483 function relativeTime (number
, withoutSuffix
, string
, isFuture
) {
484 var output
= this._relativeTime
[string
];
485 return (isFunction(output
)) ?
486 output(number
, withoutSuffix
, string
, isFuture
) :
487 output
.replace(/%d/i, number
);
490 function pastFuture (diff
, output
) {
491 var format
= this._relativeTime
[diff
> 0 ? 'future' : 'past'];
492 return isFunction(format
) ? format(output
) : format
.replace(/%s/i, output
);
497 function addUnitAlias (unit
, shorthand
) {
498 var lowerCase
= unit
.toLowerCase();
499 aliases
[lowerCase
] = aliases
[lowerCase
+ 's'] = aliases
[shorthand
] = unit
;
502 function normalizeUnits(units
) {
503 return typeof units
=== 'string' ? aliases
[units
] || aliases
[units
.toLowerCase()] : undefined;
506 function normalizeObjectUnits(inputObject
) {
507 var normalizedInput
= {},
511 for (prop
in inputObject
) {
512 if (hasOwnProp(inputObject
, prop
)) {
513 normalizedProp
= normalizeUnits(prop
);
514 if (normalizedProp
) {
515 normalizedInput
[normalizedProp
] = inputObject
[prop
];
520 return normalizedInput
;
525 function addUnitPriority(unit
, priority
) {
526 priorities
[unit
] = priority
;
529 function getPrioritizedUnits(unitsObj
) {
531 for (var u
in unitsObj
) {
532 units
.push({unit
: u
, priority
: priorities
[u
]});
534 units
.sort(function (a
, b
) {
535 return a
.priority
- b
.priority
;
540 function makeGetSet (unit
, keepTime
) {
541 return function (value
) {
543 set$1(this, unit
, value
);
544 hooks
.updateOffset(this, keepTime
);
547 return get(this, unit
);
552 function get (mom
, unit
) {
553 return mom
.isValid() ?
554 mom
._d
['get' + (mom
._isUTC
? 'UTC' : '') + unit
]() : NaN
;
557 function set$1 (mom
, unit
, value
) {
559 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + unit
](value
);
565 function stringGet (units
) {
566 units
= normalizeUnits(units
);
567 if (isFunction(this[units
])) {
568 return this[units
]();
574 function stringSet (units
, value
) {
575 if (typeof units
=== 'object') {
576 units
= normalizeObjectUnits(units
);
577 var prioritized
= getPrioritizedUnits(units
);
578 for (var i
= 0; i
< prioritized
.length
; i
++) {
579 this[prioritized
[i
].unit
](units
[prioritized
[i
].unit
]);
582 units
= normalizeUnits(units
);
583 if (isFunction(this[units
])) {
584 return this[units
](value
);
590 function zeroFill(number
, targetLength
, forceSign
) {
591 var absNumber
= '' + Math
.abs(number
),
592 zerosToFill
= targetLength
- absNumber
.length
,
594 return (sign
? (forceSign
? '+' : '') : '-') +
595 Math
.pow(10, Math
.max(0, zerosToFill
)).toString().substr(1) + absNumber
;
598 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;
600 var localFormattingTokens
= /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
602 var formatFunctions
= {};
604 var formatTokenFunctions
= {};
609 // callback: function () { this.month() + 1 }
610 function addFormatToken (token
, padded
, ordinal
, callback
) {
612 if (typeof callback
=== 'string') {
614 return this[callback
]();
618 formatTokenFunctions
[token
] = func
;
621 formatTokenFunctions
[padded
[0]] = function () {
622 return zeroFill(func
.apply(this, arguments
), padded
[1], padded
[2]);
626 formatTokenFunctions
[ordinal
] = function () {
627 return this.localeData().ordinal(func
.apply(this, arguments
), token
);
632 function removeFormattingTokens(input
) {
633 if (input
.match(/\[[\s\S]/)) {
634 return input
.replace(/^\[|\]$/g, '');
636 return input
.replace(/\\/g
, '');
639 function makeFormatFunction(format
) {
640 var array
= format
.match(formattingTokens
), i
, length
;
642 for (i
= 0, length
= array
.length
; i
< length
; i
++) {
643 if (formatTokenFunctions
[array
[i
]]) {
644 array
[i
] = formatTokenFunctions
[array
[i
]];
646 array
[i
] = removeFormattingTokens(array
[i
]);
650 return function (mom
) {
652 for (i
= 0; i
< length
; i
++) {
653 output
+= isFunction(array
[i
]) ? array
[i
].call(mom
, format
) : array
[i
];
659 // format date using native date object
660 function formatMoment(m
, format
) {
662 return m
.localeData().invalidDate();
665 format
= expandFormat(format
, m
.localeData());
666 formatFunctions
[format
] = formatFunctions
[format
] || makeFormatFunction(format
);
668 return formatFunctions
[format
](m
);
671 function expandFormat(format
, locale
) {
674 function replaceLongDateFormatTokens(input
) {
675 return locale
.longDateFormat(input
) || input
;
678 localFormattingTokens
.lastIndex
= 0;
679 while (i
>= 0 && localFormattingTokens
.test(format
)) {
680 format
= format
.replace(localFormattingTokens
, replaceLongDateFormatTokens
);
681 localFormattingTokens
.lastIndex
= 0;
688 var match1
= /\d/; // 0 - 9
689 var match2
= /\d\d/; // 00 - 99
690 var match3
= /\d{3}/; // 000 - 999
691 var match4
= /\d{4}/; // 0000 - 9999
692 var match6
= /[+-]?\d{6}/; // -999999 - 999999
693 var match1to2
= /\d\d?/; // 0 - 99
694 var match3to4
= /\d\d\d\d?/; // 999 - 9999
695 var match5to6
= /\d\d\d\d\d\d?/; // 99999 - 999999
696 var match1to3
= /\d{1,3}/; // 0 - 999
697 var match1to4
= /\d{1,4}/; // 0 - 9999
698 var match1to6
= /[+-]?\d{1,6}/; // -999999 - 999999
700 var matchUnsigned
= /\d+/; // 0 - inf
701 var matchSigned
= /[+-]?\d+/; // -inf - inf
703 var matchOffset
= /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
704 var matchShortOffset
= /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
706 var matchTimestamp
= /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
708 // any word (or two) characters or numbers including two/three word month in arabic.
709 // includes scottish gaelic two word and hyphenated months
710 var matchWord
= /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
715 function addRegexToken (token
, regex
, strictRegex
) {
716 regexes
[token
] = isFunction(regex
) ? regex : function (isStrict
, localeData
) {
717 return (isStrict
&& strictRegex
) ? strictRegex
: regex
;
721 function getParseRegexForToken (token
, config
) {
722 if (!hasOwnProp(regexes
, token
)) {
723 return new RegExp(unescapeFormat(token
));
726 return regexes
[token
](config
._strict
, config
._locale
);
729 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
730 function unescapeFormat(s
) {
731 return regexEscape(s
.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched
, p1
, p2
, p3
, p4
) {
732 return p1
|| p2
|| p3
|| p4
;
736 function regexEscape(s
) {
737 return s
.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
742 function addParseToken (token
, callback
) {
743 var i
, func
= callback
;
744 if (typeof token
=== 'string') {
747 if (isNumber(callback
)) {
748 func = function (input
, array
) {
749 array
[callback
] = toInt(input
);
752 for (i
= 0; i
< token
.length
; i
++) {
753 tokens
[token
[i
]] = func
;
757 function addWeekParseToken (token
, callback
) {
758 addParseToken(token
, function (input
, array
, config
, token
) {
759 config
._w
= config
._w
|| {};
760 callback(input
, config
._w
, config
, token
);
764 function addTimeToArrayFromToken(token
, input
, config
) {
765 if (input
!= null && hasOwnProp(tokens
, token
)) {
766 tokens
[token
](input
, config
._a
, config
, token
);
782 if (Array
.prototype.indexOf
) {
783 indexOf
= Array
.prototype.indexOf
;
785 indexOf = function (o
) {
788 for (i
= 0; i
< this.length
; ++i
) {
797 var indexOf
$1 = indexOf
;
799 function daysInMonth(year
, month
) {
800 return new Date(Date
.UTC(year
, month
+ 1, 0)).getUTCDate();
805 addFormatToken('M', ['MM', 2], 'Mo', function () {
806 return this.month() + 1;
809 addFormatToken('MMM', 0, 0, function (format
) {
810 return this.localeData().monthsShort(this, format
);
813 addFormatToken('MMMM', 0, 0, function (format
) {
814 return this.localeData().months(this, format
);
819 addUnitAlias('month', 'M');
823 addUnitPriority('month', 8);
827 addRegexToken('M', match1to2
);
828 addRegexToken('MM', match1to2
, match2
);
829 addRegexToken('MMM', function (isStrict
, locale
) {
830 return locale
.monthsShortRegex(isStrict
);
832 addRegexToken('MMMM', function (isStrict
, locale
) {
833 return locale
.monthsRegex(isStrict
);
836 addParseToken(['M', 'MM'], function (input
, array
) {
837 array
[MONTH
] = toInt(input
) - 1;
840 addParseToken(['MMM', 'MMMM'], function (input
, array
, config
, token
) {
841 var month
= config
._locale
.monthsParse(input
, token
, config
._strict
);
842 // if we didn't find a month name, mark the date as invalid.
844 array
[MONTH
] = month
;
846 getParsingFlags(config
).invalidMonth
= input
;
852 var MONTHS_IN_FORMAT
= /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
853 var defaultLocaleMonths
= 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
854 function localeMonths (m
, format
) {
856 return isArray(this._months
) ? this._months
:
857 this._months
['standalone'];
859 return isArray(this._months
) ? this._months
[m
.month()] :
860 this._months
[(this._months
.isFormat
|| MONTHS_IN_FORMAT
).test(format
) ? 'format' : 'standalone'][m
.month()];
863 var defaultLocaleMonthsShort
= 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
864 function localeMonthsShort (m
, format
) {
866 return isArray(this._monthsShort
) ? this._monthsShort
:
867 this._monthsShort
['standalone'];
869 return isArray(this._monthsShort
) ? this._monthsShort
[m
.month()] :
870 this._monthsShort
[MONTHS_IN_FORMAT
.test(format
) ? 'format' : 'standalone'][m
.month()];
873 function handleStrictParse(monthName
, format
, strict
) {
874 var i
, ii
, mom
, llc
= monthName
.toLocaleLowerCase();
875 if (!this._monthsParse
) {
877 this._monthsParse
= [];
878 this._longMonthsParse
= [];
879 this._shortMonthsParse
= [];
880 for (i
= 0; i
< 12; ++i
) {
881 mom
= createUTC([2000, i
]);
882 this._shortMonthsParse
[i
] = this.monthsShort(mom
, '').toLocaleLowerCase();
883 this._longMonthsParse
[i
] = this.months(mom
, '').toLocaleLowerCase();
888 if (format
=== 'MMM') {
889 ii
= indexOf
$1.call(this._shortMonthsParse
, llc
);
890 return ii
!== -1 ? ii
: null;
892 ii
= indexOf
$1.call(this._longMonthsParse
, llc
);
893 return ii
!== -1 ? ii
: null;
896 if (format
=== 'MMM') {
897 ii
= indexOf
$1.call(this._shortMonthsParse
, llc
);
901 ii
= indexOf
$1.call(this._longMonthsParse
, llc
);
902 return ii
!== -1 ? ii
: null;
904 ii
= indexOf
$1.call(this._longMonthsParse
, llc
);
908 ii
= indexOf
$1.call(this._shortMonthsParse
, llc
);
909 return ii
!== -1 ? ii
: null;
914 function localeMonthsParse (monthName
, format
, strict
) {
917 if (this._monthsParseExact
) {
918 return handleStrictParse
.call(this, monthName
, format
, strict
);
921 if (!this._monthsParse
) {
922 this._monthsParse
= [];
923 this._longMonthsParse
= [];
924 this._shortMonthsParse
= [];
928 // Sorting makes sure if one month (or abbr) is a prefix of another
929 // see sorting in computeMonthsParse
930 for (i
= 0; i
< 12; i
++) {
931 // make the regex if we don't have it already
932 mom
= createUTC([2000, i
]);
933 if (strict
&& !this._longMonthsParse
[i
]) {
934 this._longMonthsParse
[i
] = new RegExp('^' + this.months(mom
, '').replace('.', '') + '$', 'i');
935 this._shortMonthsParse
[i
] = new RegExp('^' + this.monthsShort(mom
, '').replace('.', '') + '$', 'i');
937 if (!strict
&& !this._monthsParse
[i
]) {
938 regex
= '^' + this.months(mom
, '') + '|^' + this.monthsShort(mom
, '');
939 this._monthsParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
942 if (strict
&& format
=== 'MMMM' && this._longMonthsParse
[i
].test(monthName
)) {
944 } else if (strict
&& format
=== 'MMM' && this._shortMonthsParse
[i
].test(monthName
)) {
946 } else if (!strict
&& this._monthsParse
[i
].test(monthName
)) {
954 function setMonth (mom
, value
) {
957 if (!mom
.isValid()) {
962 if (typeof value
=== 'string') {
963 if (/^\d+$/.test(value
)) {
964 value
= toInt(value
);
966 value
= mom
.localeData().monthsParse(value
);
967 // TODO: Another silent failure?
968 if (!isNumber(value
)) {
974 dayOfMonth
= Math
.min(mom
.date(), daysInMonth(mom
.year(), value
));
975 mom
._d
['set' + (mom
._isUTC
? 'UTC' : '') + 'Month'](value
, dayOfMonth
);
979 function getSetMonth (value
) {
981 setMonth(this, value
);
982 hooks
.updateOffset(this, true);
985 return get(this, 'Month');
989 function getDaysInMonth () {
990 return daysInMonth(this.year(), this.month());
993 var defaultMonthsShortRegex
= matchWord
;
994 function monthsShortRegex (isStrict
) {
995 if (this._monthsParseExact
) {
996 if (!hasOwnProp(this, '_monthsRegex')) {
997 computeMonthsParse
.call(this);
1000 return this._monthsShortStrictRegex
;
1002 return this._monthsShortRegex
;
1005 if (!hasOwnProp(this, '_monthsShortRegex')) {
1006 this._monthsShortRegex
= defaultMonthsShortRegex
;
1008 return this._monthsShortStrictRegex
&& isStrict
?
1009 this._monthsShortStrictRegex
: this._monthsShortRegex
;
1013 var defaultMonthsRegex
= matchWord
;
1014 function monthsRegex (isStrict
) {
1015 if (this._monthsParseExact
) {
1016 if (!hasOwnProp(this, '_monthsRegex')) {
1017 computeMonthsParse
.call(this);
1020 return this._monthsStrictRegex
;
1022 return this._monthsRegex
;
1025 if (!hasOwnProp(this, '_monthsRegex')) {
1026 this._monthsRegex
= defaultMonthsRegex
;
1028 return this._monthsStrictRegex
&& isStrict
?
1029 this._monthsStrictRegex
: this._monthsRegex
;
1033 function computeMonthsParse () {
1034 function cmpLenRev(a
, b
) {
1035 return b
.length
- a
.length
;
1038 var shortPieces
= [], longPieces
= [], mixedPieces
= [],
1040 for (i
= 0; i
< 12; i
++) {
1041 // make the regex if we don't have it already
1042 mom
= createUTC([2000, i
]);
1043 shortPieces
.push(this.monthsShort(mom
, ''));
1044 longPieces
.push(this.months(mom
, ''));
1045 mixedPieces
.push(this.months(mom
, ''));
1046 mixedPieces
.push(this.monthsShort(mom
, ''));
1048 // Sorting makes sure if one month (or abbr) is a prefix of another it
1049 // will match the longer piece.
1050 shortPieces
.sort(cmpLenRev
);
1051 longPieces
.sort(cmpLenRev
);
1052 mixedPieces
.sort(cmpLenRev
);
1053 for (i
= 0; i
< 12; i
++) {
1054 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1055 longPieces
[i
] = regexEscape(longPieces
[i
]);
1057 for (i
= 0; i
< 24; i
++) {
1058 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1061 this._monthsRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1062 this._monthsShortRegex
= this._monthsRegex
;
1063 this._monthsStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1064 this._monthsShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1069 addFormatToken('Y', 0, 0, function () {
1070 var y
= this.year();
1071 return y
<= 9999 ? '' + y
: '+' + y
;
1074 addFormatToken(0, ['YY', 2], 0, function () {
1075 return this.year() % 100;
1078 addFormatToken(0, ['YYYY', 4], 0, 'year');
1079 addFormatToken(0, ['YYYYY', 5], 0, 'year');
1080 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
1084 addUnitAlias('year', 'y');
1088 addUnitPriority('year', 1);
1092 addRegexToken('Y', matchSigned
);
1093 addRegexToken('YY', match1to2
, match2
);
1094 addRegexToken('YYYY', match1to4
, match4
);
1095 addRegexToken('YYYYY', match1to6
, match6
);
1096 addRegexToken('YYYYYY', match1to6
, match6
);
1098 addParseToken(['YYYYY', 'YYYYYY'], YEAR
);
1099 addParseToken('YYYY', function (input
, array
) {
1100 array
[YEAR
] = input
.length
=== 2 ? hooks
.parseTwoDigitYear(input
) : toInt(input
);
1102 addParseToken('YY', function (input
, array
) {
1103 array
[YEAR
] = hooks
.parseTwoDigitYear(input
);
1105 addParseToken('Y', function (input
, array
) {
1106 array
[YEAR
] = parseInt(input
, 10);
1111 function daysInYear(year
) {
1112 return isLeapYear(year
) ? 366 : 365;
1115 function isLeapYear(year
) {
1116 return (year
% 4 === 0 && year
% 100 !== 0) || year
% 400 === 0;
1121 hooks
.parseTwoDigitYear = function (input
) {
1122 return toInt(input
) + (toInt(input
) > 68 ? 1900 : 2000);
1127 var getSetYear
= makeGetSet('FullYear', true);
1129 function getIsLeapYear () {
1130 return isLeapYear(this.year());
1133 function createDate (y
, m
, d
, h
, M
, s
, ms
) {
1134 // can't just apply() to create a date:
1135 // https://stackoverflow.com/q/181348
1136 var date
= new Date(y
, m
, d
, h
, M
, s
, ms
);
1138 // the date constructor remaps years 0-99 to 1900-1999
1139 if (y
< 100 && y
>= 0 && isFinite(date
.getFullYear())) {
1140 date
.setFullYear(y
);
1145 function createUTCDate (y
) {
1146 var date
= new Date(Date
.UTC
.apply(null, arguments
));
1148 // the Date.UTC function remaps years 0-99 to 1900-1999
1149 if (y
< 100 && y
>= 0 && isFinite(date
.getUTCFullYear())) {
1150 date
.setUTCFullYear(y
);
1155 // start-of-first-week - start-of-year
1156 function firstWeekOffset(year
, dow
, doy
) {
1157 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1158 fwd
= 7 + dow
- doy
,
1159 // first-week day local weekday -- which local weekday is fwd
1160 fwdlw
= (7 + createUTCDate(year
, 0, fwd
).getUTCDay() - dow
) % 7;
1162 return -fwdlw
+ fwd
- 1;
1165 // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1166 function dayOfYearFromWeeks(year
, week
, weekday
, dow
, doy
) {
1167 var localWeekday
= (7 + weekday
- dow
) % 7,
1168 weekOffset
= firstWeekOffset(year
, dow
, doy
),
1169 dayOfYear
= 1 + 7 * (week
- 1) + localWeekday
+ weekOffset
,
1170 resYear
, resDayOfYear
;
1172 if (dayOfYear
<= 0) {
1174 resDayOfYear
= daysInYear(resYear
) + dayOfYear
;
1175 } else if (dayOfYear
> daysInYear(year
)) {
1177 resDayOfYear
= dayOfYear
- daysInYear(year
);
1180 resDayOfYear
= dayOfYear
;
1185 dayOfYear
: resDayOfYear
1189 function weekOfYear(mom
, dow
, doy
) {
1190 var weekOffset
= firstWeekOffset(mom
.year(), dow
, doy
),
1191 week
= Math
.floor((mom
.dayOfYear() - weekOffset
- 1) / 7) + 1,
1195 resYear
= mom
.year() - 1;
1196 resWeek
= week
+ weeksInYear(resYear
, dow
, doy
);
1197 } else if (week
> weeksInYear(mom
.year(), dow
, doy
)) {
1198 resWeek
= week
- weeksInYear(mom
.year(), dow
, doy
);
1199 resYear
= mom
.year() + 1;
1201 resYear
= mom
.year();
1211 function weeksInYear(year
, dow
, doy
) {
1212 var weekOffset
= firstWeekOffset(year
, dow
, doy
),
1213 weekOffsetNext
= firstWeekOffset(year
+ 1, dow
, doy
);
1214 return (daysInYear(year
) - weekOffset
+ weekOffsetNext
) / 7;
1219 addFormatToken('w', ['ww', 2], 'wo', 'week');
1220 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
1224 addUnitAlias('week', 'w');
1225 addUnitAlias('isoWeek', 'W');
1229 addUnitPriority('week', 5);
1230 addUnitPriority('isoWeek', 5);
1234 addRegexToken('w', match1to2
);
1235 addRegexToken('ww', match1to2
, match2
);
1236 addRegexToken('W', match1to2
);
1237 addRegexToken('WW', match1to2
, match2
);
1239 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input
, week
, config
, token
) {
1240 week
[token
.substr(0, 1)] = toInt(input
);
1247 function localeWeek (mom
) {
1248 return weekOfYear(mom
, this._week
.dow
, this._week
.doy
).week
;
1251 var defaultLocaleWeek
= {
1252 dow
: 0, // Sunday is the first day of the week.
1253 doy
: 6 // The week that contains Jan 1st is the first week of the year.
1256 function localeFirstDayOfWeek () {
1257 return this._week
.dow
;
1260 function localeFirstDayOfYear () {
1261 return this._week
.doy
;
1266 function getSetWeek (input
) {
1267 var week
= this.localeData().week(this);
1268 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1271 function getSetISOWeek (input
) {
1272 var week
= weekOfYear(this, 1, 4).week
;
1273 return input
== null ? week
: this.add((input
- week
) * 7, 'd');
1278 addFormatToken('d', 0, 'do', 'day');
1280 addFormatToken('dd', 0, 0, function (format
) {
1281 return this.localeData().weekdaysMin(this, format
);
1284 addFormatToken('ddd', 0, 0, function (format
) {
1285 return this.localeData().weekdaysShort(this, format
);
1288 addFormatToken('dddd', 0, 0, function (format
) {
1289 return this.localeData().weekdays(this, format
);
1292 addFormatToken('e', 0, 0, 'weekday');
1293 addFormatToken('E', 0, 0, 'isoWeekday');
1297 addUnitAlias('day', 'd');
1298 addUnitAlias('weekday', 'e');
1299 addUnitAlias('isoWeekday', 'E');
1302 addUnitPriority('day', 11);
1303 addUnitPriority('weekday', 11);
1304 addUnitPriority('isoWeekday', 11);
1308 addRegexToken('d', match1to2
);
1309 addRegexToken('e', match1to2
);
1310 addRegexToken('E', match1to2
);
1311 addRegexToken('dd', function (isStrict
, locale
) {
1312 return locale
.weekdaysMinRegex(isStrict
);
1314 addRegexToken('ddd', function (isStrict
, locale
) {
1315 return locale
.weekdaysShortRegex(isStrict
);
1317 addRegexToken('dddd', function (isStrict
, locale
) {
1318 return locale
.weekdaysRegex(isStrict
);
1321 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input
, week
, config
, token
) {
1322 var weekday
= config
._locale
.weekdaysParse(input
, token
, config
._strict
);
1323 // if we didn't get a weekday name, mark the date as invalid
1324 if (weekday
!= null) {
1327 getParsingFlags(config
).invalidWeekday
= input
;
1331 addWeekParseToken(['d', 'e', 'E'], function (input
, week
, config
, token
) {
1332 week
[token
] = toInt(input
);
1337 function parseWeekday(input
, locale
) {
1338 if (typeof input
!== 'string') {
1342 if (!isNaN(input
)) {
1343 return parseInt(input
, 10);
1346 input
= locale
.weekdaysParse(input
);
1347 if (typeof input
=== 'number') {
1354 function parseIsoWeekday(input
, locale
) {
1355 if (typeof input
=== 'string') {
1356 return locale
.weekdaysParse(input
) % 7 || 7;
1358 return isNaN(input
) ? null : input
;
1363 var defaultLocaleWeekdays
= 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
1364 function localeWeekdays (m
, format
) {
1366 return isArray(this._weekdays
) ? this._weekdays
:
1367 this._weekdays
['standalone'];
1369 return isArray(this._weekdays
) ? this._weekdays
[m
.day()] :
1370 this._weekdays
[this._weekdays
.isFormat
.test(format
) ? 'format' : 'standalone'][m
.day()];
1373 var defaultLocaleWeekdaysShort
= 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
1374 function localeWeekdaysShort (m
) {
1375 return (m
) ? this._weekdaysShort
[m
.day()] : this._weekdaysShort
;
1378 var defaultLocaleWeekdaysMin
= 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
1379 function localeWeekdaysMin (m
) {
1380 return (m
) ? this._weekdaysMin
[m
.day()] : this._weekdaysMin
;
1383 function handleStrictParse
$1(weekdayName
, format
, strict
) {
1384 var i
, ii
, mom
, llc
= weekdayName
.toLocaleLowerCase();
1385 if (!this._weekdaysParse
) {
1386 this._weekdaysParse
= [];
1387 this._shortWeekdaysParse
= [];
1388 this._minWeekdaysParse
= [];
1390 for (i
= 0; i
< 7; ++i
) {
1391 mom
= createUTC([2000, 1]).day(i
);
1392 this._minWeekdaysParse
[i
] = this.weekdaysMin(mom
, '').toLocaleLowerCase();
1393 this._shortWeekdaysParse
[i
] = this.weekdaysShort(mom
, '').toLocaleLowerCase();
1394 this._weekdaysParse
[i
] = this.weekdays(mom
, '').toLocaleLowerCase();
1399 if (format
=== 'dddd') {
1400 ii
= indexOf
$1.call(this._weekdaysParse
, llc
);
1401 return ii
!== -1 ? ii
: null;
1402 } else if (format
=== 'ddd') {
1403 ii
= indexOf
$1.call(this._shortWeekdaysParse
, llc
);
1404 return ii
!== -1 ? ii
: null;
1406 ii
= indexOf
$1.call(this._minWeekdaysParse
, llc
);
1407 return ii
!== -1 ? ii
: null;
1410 if (format
=== 'dddd') {
1411 ii
= indexOf
$1.call(this._weekdaysParse
, llc
);
1415 ii
= indexOf
$1.call(this._shortWeekdaysParse
, llc
);
1419 ii
= indexOf
$1.call(this._minWeekdaysParse
, llc
);
1420 return ii
!== -1 ? ii
: null;
1421 } else if (format
=== 'ddd') {
1422 ii
= indexOf
$1.call(this._shortWeekdaysParse
, llc
);
1426 ii
= indexOf
$1.call(this._weekdaysParse
, llc
);
1430 ii
= indexOf
$1.call(this._minWeekdaysParse
, llc
);
1431 return ii
!== -1 ? ii
: null;
1433 ii
= indexOf
$1.call(this._minWeekdaysParse
, llc
);
1437 ii
= indexOf
$1.call(this._weekdaysParse
, llc
);
1441 ii
= indexOf
$1.call(this._shortWeekdaysParse
, llc
);
1442 return ii
!== -1 ? ii
: null;
1447 function localeWeekdaysParse (weekdayName
, format
, strict
) {
1450 if (this._weekdaysParseExact
) {
1451 return handleStrictParse
$1.call(this, weekdayName
, format
, strict
);
1454 if (!this._weekdaysParse
) {
1455 this._weekdaysParse
= [];
1456 this._minWeekdaysParse
= [];
1457 this._shortWeekdaysParse
= [];
1458 this._fullWeekdaysParse
= [];
1461 for (i
= 0; i
< 7; i
++) {
1462 // make the regex if we don't have it already
1464 mom
= createUTC([2000, 1]).day(i
);
1465 if (strict
&& !this._fullWeekdaysParse
[i
]) {
1466 this._fullWeekdaysParse
[i
] = new RegExp('^' + this.weekdays(mom
, '').replace('.', '\.?') + '$', 'i');
1467 this._shortWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysShort(mom
, '').replace('.', '\.?') + '$', 'i');
1468 this._minWeekdaysParse
[i
] = new RegExp('^' + this.weekdaysMin(mom
, '').replace('.', '\.?') + '$', 'i');
1470 if (!this._weekdaysParse
[i
]) {
1471 regex
= '^' + this.weekdays(mom
, '') + '|^' + this.weekdaysShort(mom
, '') + '|^' + this.weekdaysMin(mom
, '');
1472 this._weekdaysParse
[i
] = new RegExp(regex
.replace('.', ''), 'i');
1475 if (strict
&& format
=== 'dddd' && this._fullWeekdaysParse
[i
].test(weekdayName
)) {
1477 } else if (strict
&& format
=== 'ddd' && this._shortWeekdaysParse
[i
].test(weekdayName
)) {
1479 } else if (strict
&& format
=== 'dd' && this._minWeekdaysParse
[i
].test(weekdayName
)) {
1481 } else if (!strict
&& this._weekdaysParse
[i
].test(weekdayName
)) {
1489 function getSetDayOfWeek (input
) {
1490 if (!this.isValid()) {
1491 return input
!= null ? this : NaN
;
1493 var day
= this._isUTC
? this._d
.getUTCDay() : this._d
.getDay();
1494 if (input
!= null) {
1495 input
= parseWeekday(input
, this.localeData());
1496 return this.add(input
- day
, 'd');
1502 function getSetLocaleDayOfWeek (input
) {
1503 if (!this.isValid()) {
1504 return input
!= null ? this : NaN
;
1506 var weekday
= (this.day() + 7 - this.localeData()._week
.dow
) % 7;
1507 return input
== null ? weekday
: this.add(input
- weekday
, 'd');
1510 function getSetISODayOfWeek (input
) {
1511 if (!this.isValid()) {
1512 return input
!= null ? this : NaN
;
1515 // behaves the same as moment#day except
1516 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
1517 // as a setter, sunday should belong to the previous week.
1519 if (input
!= null) {
1520 var weekday
= parseIsoWeekday(input
, this.localeData());
1521 return this.day(this.day() % 7 ? weekday
: weekday
- 7);
1523 return this.day() || 7;
1527 var defaultWeekdaysRegex
= matchWord
;
1528 function weekdaysRegex (isStrict
) {
1529 if (this._weekdaysParseExact
) {
1530 if (!hasOwnProp(this, '_weekdaysRegex')) {
1531 computeWeekdaysParse
.call(this);
1534 return this._weekdaysStrictRegex
;
1536 return this._weekdaysRegex
;
1539 if (!hasOwnProp(this, '_weekdaysRegex')) {
1540 this._weekdaysRegex
= defaultWeekdaysRegex
;
1542 return this._weekdaysStrictRegex
&& isStrict
?
1543 this._weekdaysStrictRegex
: this._weekdaysRegex
;
1547 var defaultWeekdaysShortRegex
= matchWord
;
1548 function weekdaysShortRegex (isStrict
) {
1549 if (this._weekdaysParseExact
) {
1550 if (!hasOwnProp(this, '_weekdaysRegex')) {
1551 computeWeekdaysParse
.call(this);
1554 return this._weekdaysShortStrictRegex
;
1556 return this._weekdaysShortRegex
;
1559 if (!hasOwnProp(this, '_weekdaysShortRegex')) {
1560 this._weekdaysShortRegex
= defaultWeekdaysShortRegex
;
1562 return this._weekdaysShortStrictRegex
&& isStrict
?
1563 this._weekdaysShortStrictRegex
: this._weekdaysShortRegex
;
1567 var defaultWeekdaysMinRegex
= matchWord
;
1568 function weekdaysMinRegex (isStrict
) {
1569 if (this._weekdaysParseExact
) {
1570 if (!hasOwnProp(this, '_weekdaysRegex')) {
1571 computeWeekdaysParse
.call(this);
1574 return this._weekdaysMinStrictRegex
;
1576 return this._weekdaysMinRegex
;
1579 if (!hasOwnProp(this, '_weekdaysMinRegex')) {
1580 this._weekdaysMinRegex
= defaultWeekdaysMinRegex
;
1582 return this._weekdaysMinStrictRegex
&& isStrict
?
1583 this._weekdaysMinStrictRegex
: this._weekdaysMinRegex
;
1588 function computeWeekdaysParse () {
1589 function cmpLenRev(a
, b
) {
1590 return b
.length
- a
.length
;
1593 var minPieces
= [], shortPieces
= [], longPieces
= [], mixedPieces
= [],
1594 i
, mom
, minp
, shortp
, longp
;
1595 for (i
= 0; i
< 7; i
++) {
1596 // make the regex if we don't have it already
1597 mom
= createUTC([2000, 1]).day(i
);
1598 minp
= this.weekdaysMin(mom
, '');
1599 shortp
= this.weekdaysShort(mom
, '');
1600 longp
= this.weekdays(mom
, '');
1601 minPieces
.push(minp
);
1602 shortPieces
.push(shortp
);
1603 longPieces
.push(longp
);
1604 mixedPieces
.push(minp
);
1605 mixedPieces
.push(shortp
);
1606 mixedPieces
.push(longp
);
1608 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
1609 // will match the longer piece.
1610 minPieces
.sort(cmpLenRev
);
1611 shortPieces
.sort(cmpLenRev
);
1612 longPieces
.sort(cmpLenRev
);
1613 mixedPieces
.sort(cmpLenRev
);
1614 for (i
= 0; i
< 7; i
++) {
1615 shortPieces
[i
] = regexEscape(shortPieces
[i
]);
1616 longPieces
[i
] = regexEscape(longPieces
[i
]);
1617 mixedPieces
[i
] = regexEscape(mixedPieces
[i
]);
1620 this._weekdaysRegex
= new RegExp('^(' + mixedPieces
.join('|') + ')', 'i');
1621 this._weekdaysShortRegex
= this._weekdaysRegex
;
1622 this._weekdaysMinRegex
= this._weekdaysRegex
;
1624 this._weekdaysStrictRegex
= new RegExp('^(' + longPieces
.join('|') + ')', 'i');
1625 this._weekdaysShortStrictRegex
= new RegExp('^(' + shortPieces
.join('|') + ')', 'i');
1626 this._weekdaysMinStrictRegex
= new RegExp('^(' + minPieces
.join('|') + ')', 'i');
1631 function hFormat() {
1632 return this.hours() % 12 || 12;
1635 function kFormat() {
1636 return this.hours() || 24;
1639 addFormatToken('H', ['HH', 2], 0, 'hour');
1640 addFormatToken('h', ['hh', 2], 0, hFormat
);
1641 addFormatToken('k', ['kk', 2], 0, kFormat
);
1643 addFormatToken('hmm', 0, 0, function () {
1644 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2);
1647 addFormatToken('hmmss', 0, 0, function () {
1648 return '' + hFormat
.apply(this) + zeroFill(this.minutes(), 2) +
1649 zeroFill(this.seconds(), 2);
1652 addFormatToken('Hmm', 0, 0, function () {
1653 return '' + this.hours() + zeroFill(this.minutes(), 2);
1656 addFormatToken('Hmmss', 0, 0, function () {
1657 return '' + this.hours() + zeroFill(this.minutes(), 2) +
1658 zeroFill(this.seconds(), 2);
1661 function meridiem (token
, lowercase
) {
1662 addFormatToken(token
, 0, 0, function () {
1663 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase
);
1667 meridiem('a', true);
1668 meridiem('A', false);
1672 addUnitAlias('hour', 'h');
1675 addUnitPriority('hour', 13);
1679 function matchMeridiem (isStrict
, locale
) {
1680 return locale
._meridiemParse
;
1683 addRegexToken('a', matchMeridiem
);
1684 addRegexToken('A', matchMeridiem
);
1685 addRegexToken('H', match1to2
);
1686 addRegexToken('h', match1to2
);
1687 addRegexToken('k', match1to2
);
1688 addRegexToken('HH', match1to2
, match2
);
1689 addRegexToken('hh', match1to2
, match2
);
1690 addRegexToken('kk', match1to2
, match2
);
1692 addRegexToken('hmm', match3to4
);
1693 addRegexToken('hmmss', match5to6
);
1694 addRegexToken('Hmm', match3to4
);
1695 addRegexToken('Hmmss', match5to6
);
1697 addParseToken(['H', 'HH'], HOUR
);
1698 addParseToken(['k', 'kk'], function (input
, array
, config
) {
1699 var kInput
= toInt(input
);
1700 array
[HOUR
] = kInput
=== 24 ? 0 : kInput
;
1702 addParseToken(['a', 'A'], function (input
, array
, config
) {
1703 config
._isPm
= config
._locale
.isPM(input
);
1704 config
._meridiem
= input
;
1706 addParseToken(['h', 'hh'], function (input
, array
, config
) {
1707 array
[HOUR
] = toInt(input
);
1708 getParsingFlags(config
).bigHour
= true;
1710 addParseToken('hmm', function (input
, array
, config
) {
1711 var pos
= input
.length
- 2;
1712 array
[HOUR
] = toInt(input
.substr(0, pos
));
1713 array
[MINUTE
] = toInt(input
.substr(pos
));
1714 getParsingFlags(config
).bigHour
= true;
1716 addParseToken('hmmss', function (input
, array
, config
) {
1717 var pos1
= input
.length
- 4;
1718 var pos2
= input
.length
- 2;
1719 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1720 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1721 array
[SECOND
] = toInt(input
.substr(pos2
));
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
));
1729 addParseToken('Hmmss', function (input
, array
, config
) {
1730 var pos1
= input
.length
- 4;
1731 var pos2
= input
.length
- 2;
1732 array
[HOUR
] = toInt(input
.substr(0, pos1
));
1733 array
[MINUTE
] = toInt(input
.substr(pos1
, 2));
1734 array
[SECOND
] = toInt(input
.substr(pos2
));
1739 function localeIsPM (input
) {
1740 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
1741 // Using charAt should be more compatible.
1742 return ((input
+ '').toLowerCase().charAt(0) === 'p');
1745 var defaultLocaleMeridiemParse
= /[ap]\.?m?\.?/i;
1746 function localeMeridiem (hours
, minutes
, isLower
) {
1748 return isLower
? 'pm' : 'PM';
1750 return isLower
? 'am' : 'AM';
1757 // Setting the hour should keep the time, because the user explicitly
1758 // specified which hour he wants. So trying to maintain the same hour (in
1759 // a new timezone) makes sense. Adding/subtracting hours does not follow
1761 var getSetHour
= makeGetSet('Hours', true);
1768 calendar
: defaultCalendar
,
1769 longDateFormat
: defaultLongDateFormat
,
1770 invalidDate
: defaultInvalidDate
,
1771 ordinal
: defaultOrdinal
,
1772 dayOfMonthOrdinalParse
: defaultDayOfMonthOrdinalParse
,
1773 relativeTime
: defaultRelativeTime
,
1775 months
: defaultLocaleMonths
,
1776 monthsShort
: defaultLocaleMonthsShort
,
1778 week
: defaultLocaleWeek
,
1780 weekdays
: defaultLocaleWeekdays
,
1781 weekdaysMin
: defaultLocaleWeekdaysMin
,
1782 weekdaysShort
: defaultLocaleWeekdaysShort
,
1784 meridiemParse
: defaultLocaleMeridiemParse
1787 // internal storage for locale config files
1789 var localeFamilies
= {};
1792 function normalizeLocale(key
) {
1793 return key
? key
.toLowerCase().replace('_', '-') : key
;
1796 // pick the locale from the array
1797 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
1798 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
1799 function chooseLocale(names
) {
1800 var i
= 0, j
, next
, locale
, split
;
1802 while (i
< names
.length
) {
1803 split
= normalizeLocale(names
[i
]).split('-');
1805 next
= normalizeLocale(names
[i
+ 1]);
1806 next
= next
? next
.split('-') : null;
1808 locale
= loadLocale(split
.slice(0, j
).join('-'));
1812 if (next
&& next
.length
>= j
&& compareArrays(split
, next
, true) >= j
- 1) {
1813 //the next array item is better than a shallower substring of this one
1823 function loadLocale(name
) {
1824 var oldLocale
= null;
1825 // TODO: Find a better way to register and load all the locales in Node
1826 if (!locales
[name
] && (typeof module
!== 'undefined') &&
1827 module
&& module
.exports
) {
1829 oldLocale
= globalLocale
._abbr
;
1830 require('./locale/' + name
);
1831 // because defineLocale currently also sets the global locale, we
1832 // want to undo that for lazy loaded locales
1833 getSetGlobalLocale(oldLocale
);
1836 return locales
[name
];
1839 // This function will load locale and then set the global locale. If
1840 // no arguments are passed in, it will simply return the current global
1842 function getSetGlobalLocale (key
, values
) {
1845 if (isUndefined(values
)) {
1846 data
= getLocale(key
);
1849 data
= defineLocale(key
, values
);
1853 // moment.duration._locale = moment._locale = data;
1854 globalLocale
= data
;
1858 return globalLocale
._abbr
;
1861 function defineLocale (name
, config
) {
1862 if (config
!== null) {
1863 var parentConfig
= baseConfig
;
1865 if (locales
[name
] != null) {
1866 deprecateSimple('defineLocaleOverride',
1867 'use moment.updateLocale(localeName, config) to change ' +
1868 'an existing locale. moment.defineLocale(localeName, ' +
1869 'config) should only be used for creating a new locale ' +
1870 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
1871 parentConfig
= locales
[name
]._config
;
1872 } else if (config
.parentLocale
!= null) {
1873 if (locales
[config
.parentLocale
] != null) {
1874 parentConfig
= locales
[config
.parentLocale
]._config
;
1876 if (!localeFamilies
[config
.parentLocale
]) {
1877 localeFamilies
[config
.parentLocale
] = [];
1879 localeFamilies
[config
.parentLocale
].push({
1886 locales
[name
] = new Locale(mergeConfigs(parentConfig
, config
));
1888 if (localeFamilies
[name
]) {
1889 localeFamilies
[name
].forEach(function (x
) {
1890 defineLocale(x
.name
, x
.config
);
1894 // backwards compat for now: also set the locale
1895 // make sure we set the locale AFTER all child locales have been
1896 // created, so we won't end up with the child locale set.
1897 getSetGlobalLocale(name
);
1900 return locales
[name
];
1902 // useful for testing
1903 delete locales
[name
];
1908 function updateLocale(name
, config
) {
1909 if (config
!= null) {
1910 var locale
, parentConfig
= baseConfig
;
1912 if (locales
[name
] != null) {
1913 parentConfig
= locales
[name
]._config
;
1915 config
= mergeConfigs(parentConfig
, config
);
1916 locale
= new Locale(config
);
1917 locale
.parentLocale
= locales
[name
];
1918 locales
[name
] = locale
;
1920 // backwards compat for now: also set the locale
1921 getSetGlobalLocale(name
);
1923 // pass null for config to unupdate, useful for tests
1924 if (locales
[name
] != null) {
1925 if (locales
[name
].parentLocale
!= null) {
1926 locales
[name
] = locales
[name
].parentLocale
;
1927 } else if (locales
[name
] != null) {
1928 delete locales
[name
];
1932 return locales
[name
];
1935 // returns locale data
1936 function getLocale (key
) {
1939 if (key
&& key
._locale
&& key
._locale
._abbr
) {
1940 key
= key
._locale
._abbr
;
1944 return globalLocale
;
1947 if (!isArray(key
)) {
1948 //short-circuit everything else
1949 locale
= loadLocale(key
);
1956 return chooseLocale(key
);
1959 function listLocales() {
1960 return keys
$1(locales
);
1963 function checkOverflow (m
) {
1967 if (a
&& getParsingFlags(m
).overflow
=== -2) {
1969 a
[MONTH
] < 0 || a
[MONTH
] > 11 ? MONTH
:
1970 a
[DATE
] < 1 || a
[DATE
] > daysInMonth(a
[YEAR
], a
[MONTH
]) ? DATE
:
1971 a
[HOUR
] < 0 || a
[HOUR
] > 24 || (a
[HOUR
] === 24 && (a
[MINUTE
] !== 0 || a
[SECOND
] !== 0 || a
[MILLISECOND
] !== 0)) ? HOUR
:
1972 a
[MINUTE
] < 0 || a
[MINUTE
] > 59 ? MINUTE
:
1973 a
[SECOND
] < 0 || a
[SECOND
] > 59 ? SECOND
:
1974 a
[MILLISECOND
] < 0 || a
[MILLISECOND
] > 999 ? MILLISECOND
:
1977 if (getParsingFlags(m
)._overflowDayOfYear
&& (overflow
< YEAR
|| overflow
> DATE
)) {
1980 if (getParsingFlags(m
)._overflowWeeks
&& overflow
=== -1) {
1983 if (getParsingFlags(m
)._overflowWeekday
&& overflow
=== -1) {
1987 getParsingFlags(m
).overflow
= overflow
;
1994 // 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)
1995 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)?)?$/;
1996 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)?)?$/;
1998 var tzRegex
= /Z|[+-]\d\d(?::?\d\d)?/;
2001 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
2002 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
2003 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
2004 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
2005 ['YYYY-DDD', /\d{4}-\d{3}/],
2006 ['YYYY-MM', /\d{4}-\d\d/, false],
2007 ['YYYYYYMMDD', /[+-]\d{10}/],
2008 ['YYYYMMDD', /\d{8}/],
2009 // YYYYMM is NOT allowed by the standard
2010 ['GGGG[W]WWE', /\d{4}W\d{3}/],
2011 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
2012 ['YYYYDDD', /\d{7}/]
2015 // iso time formats and regexes
2017 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
2018 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
2019 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
2020 ['HH:mm', /\d\d:\d\d/],
2021 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
2022 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
2023 ['HHmmss', /\d\d\d\d\d\d/],
2024 ['HHmm', /\d\d\d\d/],
2028 var aspNetJsonRegex
= /^\/?Date\((\-?\d+)/i;
2030 // date from iso format
2031 function configFromISO(config
) {
2034 match
= extendedIsoRegex
.exec(string
) || basicIsoRegex
.exec(string
),
2035 allowTime
, dateFormat
, timeFormat
, tzFormat
;
2038 getParsingFlags(config
).iso
= true;
2040 for (i
= 0, l
= isoDates
.length
; i
< l
; i
++) {
2041 if (isoDates
[i
][1].exec(match
[1])) {
2042 dateFormat
= isoDates
[i
][0];
2043 allowTime
= isoDates
[i
][2] !== false;
2047 if (dateFormat
== null) {
2048 config
._isValid
= false;
2052 for (i
= 0, l
= isoTimes
.length
; i
< l
; i
++) {
2053 if (isoTimes
[i
][1].exec(match
[3])) {
2054 // match[2] should be 'T' or space
2055 timeFormat
= (match
[2] || ' ') + isoTimes
[i
][0];
2059 if (timeFormat
== null) {
2060 config
._isValid
= false;
2064 if (!allowTime
&& timeFormat
!= null) {
2065 config
._isValid
= false;
2069 if (tzRegex
.exec(match
[4])) {
2072 config
._isValid
= false;
2076 config
._f
= dateFormat
+ (timeFormat
|| '') + (tzFormat
|| '');
2077 configFromStringAndFormat(config
);
2079 config
._isValid
= false;
2083 // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
2084 var basicRfcRegex
= /^((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d?\d\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?:\d\d)?\d\d\s)(\d\d:\d\d)(\:\d\d)?(\s(?:UT|GMT|[ECMP][SD]T|[A-IK-Za-ik-z]|[+-]\d{4}))$/;
2086 // date and time from ref 2822 format
2087 function configFromRFC2822(config
) {
2088 var string
, match
, dayFormat
,
2089 dateFormat
, timeFormat
, tzFormat
;
2101 var military
= 'YXWVUTSRQPONZABCDEFGHIKLM';
2102 var timezone
, timezoneIndex
;
2105 .replace(/\([^\)]*\)|[\n\t]/g, ' ') // Remove comments and folding whitespace
2106 .replace(/(\s\s+)/g, ' ') // Replace multiple-spaces with a single space
2107 .replace(/^\s|\s$/g, ''); // Remove leading and trailing spaces
2108 match
= basicRfcRegex
.exec(string
);
2111 dayFormat
= match
[1] ? 'ddd' + ((match
[1].length
=== 5) ? ', ' : ' ') : '';
2112 dateFormat
= 'D MMM ' + ((match
[2].length
> 10) ? 'YYYY ' : 'YY ');
2113 timeFormat
= 'HH:mm' + (match
[4] ? ':ss' : '');
2115 // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
2116 if (match
[1]) { // day of week given
2117 var momentDate
= new Date(match
[2]);
2118 var momentDay
= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][momentDate
.getDay()];
2120 if (match
[1].substr(0,3) !== momentDay
) {
2121 getParsingFlags(config
).weekdayMismatch
= true;
2122 config
._isValid
= false;
2127 switch (match
[5].length
) {
2129 if (timezoneIndex
=== 0) {
2130 timezone
= ' +0000';
2132 timezoneIndex
= military
.indexOf(match
[5][1].toUpperCase()) - 12;
2133 timezone
= ((timezoneIndex
< 0) ? ' -' : ' +') +
2134 (('' + timezoneIndex
).replace(/^-?/, '0')).match(/..$/)[0] + '00';
2138 timezone
= timezones
[match
[5]];
2140 default: // UT or +/-9999
2141 timezone
= timezones
[' GMT'];
2143 match
[5] = timezone
;
2144 config
._i
= match
.splice(1).join('');
2146 config
._f
= dayFormat
+ dateFormat
+ timeFormat
+ tzFormat
;
2147 configFromStringAndFormat(config
);
2148 getParsingFlags(config
).rfc2822
= true;
2150 config
._isValid
= false;
2154 // date from iso format or fallback
2155 function configFromString(config
) {
2156 var matched
= aspNetJsonRegex
.exec(config
._i
);
2158 if (matched
!== null) {
2159 config
._d
= new Date(+matched
[1]);
2163 configFromISO(config
);
2164 if (config
._isValid
=== false) {
2165 delete config
._isValid
;
2170 configFromRFC2822(config
);
2171 if (config
._isValid
=== false) {
2172 delete config
._isValid
;
2177 // Final attempt, use Input Fallback
2178 hooks
.createFromInputFallback(config
);
2181 hooks
.createFromInputFallback
= deprecate(
2182 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
2183 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
2184 'discouraged and will be removed in an upcoming major release. Please refer to ' +
2185 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
2187 config
._d
= new Date(config
._i
+ (config
._useUTC
? ' UTC' : ''));
2191 // Pick the first defined of two or three arguments.
2192 function defaults(a
, b
, c
) {
2202 function currentDateArray(config
) {
2203 // hooks is actually the exported moment object
2204 var nowValue
= new Date(hooks
.now());
2205 if (config
._useUTC
) {
2206 return [nowValue
.getUTCFullYear(), nowValue
.getUTCMonth(), nowValue
.getUTCDate()];
2208 return [nowValue
.getFullYear(), nowValue
.getMonth(), nowValue
.getDate()];
2211 // convert an array to a date.
2212 // the array should mirror the parameters below
2213 // note: all values past the year are optional and will default to the lowest possible value.
2214 // [year, month, day , hour, minute, second, millisecond]
2215 function configFromArray (config
) {
2216 var i
, date
, input
= [], currentDate
, yearToUse
;
2222 currentDate
= currentDateArray(config
);
2224 //compute day of the year from weeks and weekdays
2225 if (config
._w
&& config
._a
[DATE
] == null && config
._a
[MONTH
] == null) {
2226 dayOfYearFromWeekInfo(config
);
2229 //if the day of the year is set, figure out what it is
2230 if (config
._dayOfYear
!= null) {
2231 yearToUse
= defaults(config
._a
[YEAR
], currentDate
[YEAR
]);
2233 if (config
._dayOfYear
> daysInYear(yearToUse
) || config
._dayOfYear
=== 0) {
2234 getParsingFlags(config
)._overflowDayOfYear
= true;
2237 date
= createUTCDate(yearToUse
, 0, config
._dayOfYear
);
2238 config
._a
[MONTH
] = date
.getUTCMonth();
2239 config
._a
[DATE
] = date
.getUTCDate();
2242 // Default to current date.
2243 // * if no year, month, day of month are given, default to today
2244 // * if day of month is given, default month and year
2245 // * if month is given, default only year
2246 // * if year is given, don't default anything
2247 for (i
= 0; i
< 3 && config
._a
[i
] == null; ++i
) {
2248 config
._a
[i
] = input
[i
] = currentDate
[i
];
2251 // Zero out whatever was not defaulted, including time
2252 for (; i
< 7; i
++) {
2253 config
._a
[i
] = input
[i
] = (config
._a
[i
] == null) ? (i
=== 2 ? 1 : 0) : config
._a
[i
];
2256 // Check for 24:00:00.000
2257 if (config
._a
[HOUR
] === 24 &&
2258 config
._a
[MINUTE
] === 0 &&
2259 config
._a
[SECOND
] === 0 &&
2260 config
._a
[MILLISECOND
] === 0) {
2261 config
._nextDay
= true;
2262 config
._a
[HOUR
] = 0;
2265 config
._d
= (config
._useUTC
? createUTCDate
: createDate
).apply(null, input
);
2266 // Apply timezone offset from input. The actual utcOffset can be changed
2268 if (config
._tzm
!= null) {
2269 config
._d
.setUTCMinutes(config
._d
.getUTCMinutes() - config
._tzm
);
2272 if (config
._nextDay
) {
2273 config
._a
[HOUR
] = 24;
2277 function dayOfYearFromWeekInfo(config
) {
2278 var w
, weekYear
, week
, weekday
, dow
, doy
, temp
, weekdayOverflow
;
2281 if (w
.GG
!= null || w
.W
!= null || w
.E
!= null) {
2285 // TODO: We need to take the current isoWeekYear, but that depends on
2286 // how we interpret now (local, utc, fixed offset). So create
2287 // a now version of current config (take local/utc/offset flags, and
2289 weekYear
= defaults(w
.GG
, config
._a
[YEAR
], weekOfYear(createLocal(), 1, 4).year
);
2290 week
= defaults(w
.W
, 1);
2291 weekday
= defaults(w
.E
, 1);
2292 if (weekday
< 1 || weekday
> 7) {
2293 weekdayOverflow
= true;
2296 dow
= config
._locale
._week
.dow
;
2297 doy
= config
._locale
._week
.doy
;
2299 var curWeek
= weekOfYear(createLocal(), dow
, doy
);
2301 weekYear
= defaults(w
.gg
, config
._a
[YEAR
], curWeek
.year
);
2303 // Default to current week.
2304 week
= defaults(w
.w
, curWeek
.week
);
2307 // weekday -- low day numbers are considered next week
2309 if (weekday
< 0 || weekday
> 6) {
2310 weekdayOverflow
= true;
2312 } else if (w
.e
!= null) {
2313 // local weekday -- counting starts from begining of week
2314 weekday
= w
.e
+ dow
;
2315 if (w
.e
< 0 || w
.e
> 6) {
2316 weekdayOverflow
= true;
2319 // default to begining of week
2323 if (week
< 1 || week
> weeksInYear(weekYear
, dow
, doy
)) {
2324 getParsingFlags(config
)._overflowWeeks
= true;
2325 } else if (weekdayOverflow
!= null) {
2326 getParsingFlags(config
)._overflowWeekday
= true;
2328 temp
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
);
2329 config
._a
[YEAR
] = temp
.year
;
2330 config
._dayOfYear
= temp
.dayOfYear
;
2334 // constant that refers to the ISO standard
2335 hooks
.ISO_8601 = function () {};
2337 // constant that refers to the RFC 2822 form
2338 hooks
.RFC_2822 = function () {};
2340 // date from string and format string
2341 function configFromStringAndFormat(config
) {
2342 // TODO: Move this to another part of the creation flow to prevent circular deps
2343 if (config
._f
=== hooks
.ISO_8601
) {
2344 configFromISO(config
);
2347 if (config
._f
=== hooks
.RFC_2822
) {
2348 configFromRFC2822(config
);
2352 getParsingFlags(config
).empty
= true;
2354 // This array is used to make a Date, either with `new Date` or `Date.UTC`
2355 var string
= '' + config
._i
,
2356 i
, parsedInput
, tokens
, token
, skipped
,
2357 stringLength
= string
.length
,
2358 totalParsedInputLength
= 0;
2360 tokens
= expandFormat(config
._f
, config
._locale
).match(formattingTokens
) || [];
2362 for (i
= 0; i
< tokens
.length
; i
++) {
2364 parsedInput
= (string
.match(getParseRegexForToken(token
, config
)) || [])[0];
2365 // console.log('token', token, 'parsedInput', parsedInput,
2366 // 'regex', getParseRegexForToken(token, config));
2368 skipped
= string
.substr(0, string
.indexOf(parsedInput
));
2369 if (skipped
.length
> 0) {
2370 getParsingFlags(config
).unusedInput
.push(skipped
);
2372 string
= string
.slice(string
.indexOf(parsedInput
) + parsedInput
.length
);
2373 totalParsedInputLength
+= parsedInput
.length
;
2375 // don't parse if it's not a known token
2376 if (formatTokenFunctions
[token
]) {
2378 getParsingFlags(config
).empty
= false;
2381 getParsingFlags(config
).unusedTokens
.push(token
);
2383 addTimeToArrayFromToken(token
, parsedInput
, config
);
2385 else if (config
._strict
&& !parsedInput
) {
2386 getParsingFlags(config
).unusedTokens
.push(token
);
2390 // add remaining unparsed input length to the string
2391 getParsingFlags(config
).charsLeftOver
= stringLength
- totalParsedInputLength
;
2392 if (string
.length
> 0) {
2393 getParsingFlags(config
).unusedInput
.push(string
);
2396 // clear _12h flag if hour is <= 12
2397 if (config
._a
[HOUR
] <= 12 &&
2398 getParsingFlags(config
).bigHour
=== true &&
2399 config
._a
[HOUR
] > 0) {
2400 getParsingFlags(config
).bigHour
= undefined;
2403 getParsingFlags(config
).parsedDateParts
= config
._a
.slice(0);
2404 getParsingFlags(config
).meridiem
= config
._meridiem
;
2406 config
._a
[HOUR
] = meridiemFixWrap(config
._locale
, config
._a
[HOUR
], config
._meridiem
);
2408 configFromArray(config
);
2409 checkOverflow(config
);
2413 function meridiemFixWrap (locale
, hour
, meridiem
) {
2416 if (meridiem
== null) {
2420 if (locale
.meridiemHour
!= null) {
2421 return locale
.meridiemHour(hour
, meridiem
);
2422 } else if (locale
.isPM
!= null) {
2424 isPm
= locale
.isPM(meridiem
);
2425 if (isPm
&& hour
< 12) {
2428 if (!isPm
&& hour
=== 12) {
2433 // this is not supposed to happen
2438 // date from string and array of format strings
2439 function configFromStringAndArray(config
) {
2447 if (config
._f
.length
=== 0) {
2448 getParsingFlags(config
).invalidFormat
= true;
2449 config
._d
= new Date(NaN
);
2453 for (i
= 0; i
< config
._f
.length
; i
++) {
2455 tempConfig
= copyConfig({}, config
);
2456 if (config
._useUTC
!= null) {
2457 tempConfig
._useUTC
= config
._useUTC
;
2459 tempConfig
._f
= config
._f
[i
];
2460 configFromStringAndFormat(tempConfig
);
2462 if (!isValid(tempConfig
)) {
2466 // if there is any input that was not parsed add a penalty for that format
2467 currentScore
+= getParsingFlags(tempConfig
).charsLeftOver
;
2470 currentScore
+= getParsingFlags(tempConfig
).unusedTokens
.length
* 10;
2472 getParsingFlags(tempConfig
).score
= currentScore
;
2474 if (scoreToBeat
== null || currentScore
< scoreToBeat
) {
2475 scoreToBeat
= currentScore
;
2476 bestMoment
= tempConfig
;
2480 extend(config
, bestMoment
|| tempConfig
);
2483 function configFromObject(config
) {
2488 var i
= normalizeObjectUnits(config
._i
);
2489 config
._a
= map([i
.year
, i
.month
, i
.day
|| i
.date
, i
.hour
, i
.minute
, i
.second
, i
.millisecond
], function (obj
) {
2490 return obj
&& parseInt(obj
, 10);
2493 configFromArray(config
);
2496 function createFromConfig (config
) {
2497 var res
= new Moment(checkOverflow(prepareConfig(config
)));
2499 // Adding is smart enough around DST
2501 res
._nextDay
= undefined;
2507 function prepareConfig (config
) {
2508 var input
= config
._i
,
2511 config
._locale
= config
._locale
|| getLocale(config
._l
);
2513 if (input
=== null || (format
=== undefined && input
=== '')) {
2514 return createInvalid({nullInput
: true});
2517 if (typeof input
=== 'string') {
2518 config
._i
= input
= config
._locale
.preparse(input
);
2521 if (isMoment(input
)) {
2522 return new Moment(checkOverflow(input
));
2523 } else if (isDate(input
)) {
2525 } else if (isArray(format
)) {
2526 configFromStringAndArray(config
);
2527 } else if (format
) {
2528 configFromStringAndFormat(config
);
2530 configFromInput(config
);
2533 if (!isValid(config
)) {
2540 function configFromInput(config
) {
2541 var input
= config
._i
;
2542 if (isUndefined(input
)) {
2543 config
._d
= new Date(hooks
.now());
2544 } else if (isDate(input
)) {
2545 config
._d
= new Date(input
.valueOf());
2546 } else if (typeof input
=== 'string') {
2547 configFromString(config
);
2548 } else if (isArray(input
)) {
2549 config
._a
= map(input
.slice(0), function (obj
) {
2550 return parseInt(obj
, 10);
2552 configFromArray(config
);
2553 } else if (isObject(input
)) {
2554 configFromObject(config
);
2555 } else if (isNumber(input
)) {
2556 // from milliseconds
2557 config
._d
= new Date(input
);
2559 hooks
.createFromInputFallback(config
);
2563 function createLocalOrUTC (input
, format
, locale
, strict
, isUTC
) {
2566 if (locale
=== true || locale
=== false) {
2571 if ((isObject(input
) && isObjectEmpty(input
)) ||
2572 (isArray(input
) && input
.length
=== 0)) {
2575 // object construction must be done this way.
2576 // https://github.com/moment/moment/issues/1423
2577 c
._isAMomentObject
= true;
2578 c
._useUTC
= c
._isUTC
= isUTC
;
2584 return createFromConfig(c
);
2587 function createLocal (input
, format
, locale
, strict
) {
2588 return createLocalOrUTC(input
, format
, locale
, strict
, false);
2591 var prototypeMin
= deprecate(
2592 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
2594 var other
= createLocal
.apply(null, arguments
);
2595 if (this.isValid() && other
.isValid()) {
2596 return other
< this ? this : other
;
2598 return createInvalid();
2603 var prototypeMax
= deprecate(
2604 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
2606 var other
= createLocal
.apply(null, arguments
);
2607 if (this.isValid() && other
.isValid()) {
2608 return other
> this ? this : other
;
2610 return createInvalid();
2615 // Pick a moment m from moments so that m[fn](other) is true for all
2616 // other. This relies on the function fn to be transitive.
2618 // moments should either be an array of moment objects or an array, whose
2619 // first element is an array of moment objects.
2620 function pickBy(fn
, moments
) {
2622 if (moments
.length
=== 1 && isArray(moments
[0])) {
2623 moments
= moments
[0];
2625 if (!moments
.length
) {
2626 return createLocal();
2629 for (i
= 1; i
< moments
.length
; ++i
) {
2630 if (!moments
[i
].isValid() || moments
[i
][fn
](res
)) {
2637 // TODO: Use [].sort instead?
2639 var args
= [].slice
.call(arguments
, 0);
2641 return pickBy('isBefore', args
);
2645 var args
= [].slice
.call(arguments
, 0);
2647 return pickBy('isAfter', args
);
2650 var now = function () {
2651 return Date
.now
? Date
.now() : +(new Date());
2654 var ordering
= ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
2656 function isDurationValid(m
) {
2657 for (var key
in m
) {
2658 if (!(ordering
.indexOf(key
) !== -1 && (m
[key
] == null || !isNaN(m
[key
])))) {
2663 var unitHasDecimal
= false;
2664 for (var i
= 0; i
< ordering
.length
; ++i
) {
2665 if (m
[ordering
[i
]]) {
2666 if (unitHasDecimal
) {
2667 return false; // only allow non-integers for smallest unit
2669 if (parseFloat(m
[ordering
[i
]]) !== toInt(m
[ordering
[i
]])) {
2670 unitHasDecimal
= true;
2678 function isValid
$1() {
2679 return this._isValid
;
2682 function createInvalid
$1() {
2683 return createDuration(NaN
);
2686 function Duration (duration
) {
2687 var normalizedInput
= normalizeObjectUnits(duration
),
2688 years
= normalizedInput
.year
|| 0,
2689 quarters
= normalizedInput
.quarter
|| 0,
2690 months
= normalizedInput
.month
|| 0,
2691 weeks
= normalizedInput
.week
|| 0,
2692 days
= normalizedInput
.day
|| 0,
2693 hours
= normalizedInput
.hour
|| 0,
2694 minutes
= normalizedInput
.minute
|| 0,
2695 seconds
= normalizedInput
.second
|| 0,
2696 milliseconds
= normalizedInput
.millisecond
|| 0;
2698 this._isValid
= isDurationValid(normalizedInput
);
2700 // representation for dateAddRemove
2701 this._milliseconds
= +milliseconds
+
2702 seconds
* 1e3
+ // 1000
2703 minutes
* 6e4
+ // 1000 * 60
2704 hours
* 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
2705 // Because of dateAddRemove treats 24 hours as different from a
2706 // day when working around DST, we need to store them separately
2707 this._days
= +days
+
2709 // It is impossible translate months into days without knowing
2710 // which months you are are talking about, so we have to store
2712 this._months
= +months
+
2718 this._locale
= getLocale();
2723 function isDuration (obj
) {
2724 return obj
instanceof Duration
;
2727 function absRound (number
) {
2729 return Math
.round(-1 * number
) * -1;
2731 return Math
.round(number
);
2737 function offset (token
, separator
) {
2738 addFormatToken(token
, 0, 0, function () {
2739 var offset
= this.utcOffset();
2745 return sign
+ zeroFill(~~(offset
/ 60), 2) + separator
+ zeroFill(~~(offset
) % 60, 2);
2754 addRegexToken('Z', matchShortOffset
);
2755 addRegexToken('ZZ', matchShortOffset
);
2756 addParseToken(['Z', 'ZZ'], function (input
, array
, config
) {
2757 config
._useUTC
= true;
2758 config
._tzm
= offsetFromString(matchShortOffset
, input
);
2764 // '+10:00' > ['10', '00']
2765 // '-1530' > ['-15', '30']
2766 var chunkOffset
= /([\+\-]|\d\d)/gi;
2768 function offsetFromString(matcher
, string
) {
2769 var matches
= (string
|| '').match(matcher
);
2771 if (matches
=== null) {
2775 var chunk
= matches
[matches
.length
- 1] || [];
2776 var parts
= (chunk
+ '').match(chunkOffset
) || ['-', 0, 0];
2777 var minutes
= +(parts
[1] * 60) + toInt(parts
[2]);
2779 return minutes
=== 0 ?
2781 parts
[0] === '+' ? minutes
: -minutes
;
2784 // Return a moment from input, that is local/utc/zone equivalent to model.
2785 function cloneWithOffset(input
, model
) {
2788 res
= model
.clone();
2789 diff
= (isMoment(input
) || isDate(input
) ? input
.valueOf() : createLocal(input
).valueOf()) - res
.valueOf();
2790 // Use low-level api, because this fn is low-level api.
2791 res
._d
.setTime(res
._d
.valueOf() + diff
);
2792 hooks
.updateOffset(res
, false);
2795 return createLocal(input
).local();
2799 function getDateOffset (m
) {
2800 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
2801 // https://github.com/moment/moment/pull/1871
2802 return -Math
.round(m
._d
.getTimezoneOffset() / 15) * 15;
2807 // This function will be called whenever a moment is mutated.
2808 // It is intended to keep the offset in sync with the timezone.
2809 hooks
.updateOffset = function () {};
2813 // keepLocalTime = true means only change the timezone, without
2814 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
2815 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
2816 // +0200, so we adjust the time as needed, to be valid.
2818 // Keeping the time actually adds/subtracts (one hour)
2819 // from the actual represented time. That is why we call updateOffset
2820 // a second time. In case it wants us to change the offset again
2821 // _changeInProgress == true case, then we have to adjust, because
2822 // there is no such time in the given timezone.
2823 function getSetOffset (input
, keepLocalTime
, keepMinutes
) {
2824 var offset
= this._offset
|| 0,
2826 if (!this.isValid()) {
2827 return input
!= null ? this : NaN
;
2829 if (input
!= null) {
2830 if (typeof input
=== 'string') {
2831 input
= offsetFromString(matchShortOffset
, input
);
2832 if (input
=== null) {
2835 } else if (Math
.abs(input
) < 16 && !keepMinutes
) {
2838 if (!this._isUTC
&& keepLocalTime
) {
2839 localAdjust
= getDateOffset(this);
2841 this._offset
= input
;
2843 if (localAdjust
!= null) {
2844 this.add(localAdjust
, 'm');
2846 if (offset
!== input
) {
2847 if (!keepLocalTime
|| this._changeInProgress
) {
2848 addSubtract(this, createDuration(input
- offset
, 'm'), 1, false);
2849 } else if (!this._changeInProgress
) {
2850 this._changeInProgress
= true;
2851 hooks
.updateOffset(this, true);
2852 this._changeInProgress
= null;
2857 return this._isUTC
? offset
: getDateOffset(this);
2861 function getSetZone (input
, keepLocalTime
) {
2862 if (input
!= null) {
2863 if (typeof input
!== 'string') {
2867 this.utcOffset(input
, keepLocalTime
);
2871 return -this.utcOffset();
2875 function setOffsetToUTC (keepLocalTime
) {
2876 return this.utcOffset(0, keepLocalTime
);
2879 function setOffsetToLocal (keepLocalTime
) {
2881 this.utcOffset(0, keepLocalTime
);
2882 this._isUTC
= false;
2884 if (keepLocalTime
) {
2885 this.subtract(getDateOffset(this), 'm');
2891 function setOffsetToParsedOffset () {
2892 if (this._tzm
!= null) {
2893 this.utcOffset(this._tzm
, false, true);
2894 } else if (typeof this._i
=== 'string') {
2895 var tZone
= offsetFromString(matchOffset
, this._i
);
2896 if (tZone
!= null) {
2897 this.utcOffset(tZone
);
2900 this.utcOffset(0, true);
2906 function hasAlignedHourOffset (input
) {
2907 if (!this.isValid()) {
2910 input
= input
? createLocal(input
).utcOffset() : 0;
2912 return (this.utcOffset() - input
) % 60 === 0;
2915 function isDaylightSavingTime () {
2917 this.utcOffset() > this.clone().month(0).utcOffset() ||
2918 this.utcOffset() > this.clone().month(5).utcOffset()
2922 function isDaylightSavingTimeShifted () {
2923 if (!isUndefined(this._isDSTShifted
)) {
2924 return this._isDSTShifted
;
2929 copyConfig(c
, this);
2930 c
= prepareConfig(c
);
2933 var other
= c
._isUTC
? createUTC(c
._a
) : createLocal(c
._a
);
2934 this._isDSTShifted
= this.isValid() &&
2935 compareArrays(c
._a
, other
.toArray()) > 0;
2937 this._isDSTShifted
= false;
2940 return this._isDSTShifted
;
2943 function isLocal () {
2944 return this.isValid() ? !this._isUTC
: false;
2947 function isUtcOffset () {
2948 return this.isValid() ? this._isUTC
: false;
2952 return this.isValid() ? this._isUTC
&& this._offset
=== 0 : false;
2955 // ASP.NET json date format regex
2956 var aspNetRegex
= /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
2958 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
2959 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
2960 // and further modified to allow for strings containing both week and day
2961 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)?)?$/;
2963 function createDuration (input
, key
) {
2964 var duration
= input
,
2965 // matching against regexp is expensive, do it on demand
2971 if (isDuration(input
)) {
2973 ms
: input
._milliseconds
,
2977 } else if (isNumber(input
)) {
2980 duration
[key
] = input
;
2982 duration
.milliseconds
= input
;
2984 } else if (!!(match
= aspNetRegex
.exec(input
))) {
2985 sign
= (match
[1] === '-') ? -1 : 1;
2988 d
: toInt(match
[DATE
]) * sign
,
2989 h
: toInt(match
[HOUR
]) * sign
,
2990 m
: toInt(match
[MINUTE
]) * sign
,
2991 s
: toInt(match
[SECOND
]) * sign
,
2992 ms
: toInt(absRound(match
[MILLISECOND
] * 1000)) * sign
// the millisecond decimal point is included in the match
2994 } else if (!!(match
= isoRegex
.exec(input
))) {
2995 sign
= (match
[1] === '-') ? -1 : 1;
2997 y
: parseIso(match
[2], sign
),
2998 M
: parseIso(match
[3], sign
),
2999 w
: parseIso(match
[4], sign
),
3000 d
: parseIso(match
[5], sign
),
3001 h
: parseIso(match
[6], sign
),
3002 m
: parseIso(match
[7], sign
),
3003 s
: parseIso(match
[8], sign
)
3005 } else if (duration
== null) {// checks for null or undefined
3007 } else if (typeof duration
=== 'object' && ('from' in duration
|| 'to' in duration
)) {
3008 diffRes
= momentsDifference(createLocal(duration
.from), createLocal(duration
.to
));
3011 duration
.ms
= diffRes
.milliseconds
;
3012 duration
.M
= diffRes
.months
;
3015 ret
= new Duration(duration
);
3017 if (isDuration(input
) && hasOwnProp(input
, '_locale')) {
3018 ret
._locale
= input
._locale
;
3024 createDuration
.fn
= Duration
.prototype;
3025 createDuration
.invalid
= createInvalid
$1;
3027 function parseIso (inp
, sign
) {
3028 // We'd normally use ~~inp for this, but unfortunately it also
3029 // converts floats to ints.
3030 // inp may be undefined, so careful calling replace on it.
3031 var res
= inp
&& parseFloat(inp
.replace(',', '.'));
3032 // apply sign while we're at it
3033 return (isNaN(res
) ? 0 : res
) * sign
;
3036 function positiveMomentsDifference(base
, other
) {
3037 var res
= {milliseconds
: 0, months
: 0};
3039 res
.months
= other
.month() - base
.month() +
3040 (other
.year() - base
.year()) * 12;
3041 if (base
.clone().add(res
.months
, 'M').isAfter(other
)) {
3045 res
.milliseconds
= +other
- +(base
.clone().add(res
.months
, 'M'));
3050 function momentsDifference(base
, other
) {
3052 if (!(base
.isValid() && other
.isValid())) {
3053 return {milliseconds
: 0, months
: 0};
3056 other
= cloneWithOffset(other
, base
);
3057 if (base
.isBefore(other
)) {
3058 res
= positiveMomentsDifference(base
, other
);
3060 res
= positiveMomentsDifference(other
, base
);
3061 res
.milliseconds
= -res
.milliseconds
;
3062 res
.months
= -res
.months
;
3068 // TODO: remove 'name' arg after deprecation is removed
3069 function createAdder(direction
, name
) {
3070 return function (val
, period
) {
3072 //invert the arguments, but complain about it
3073 if (period
!== null && !isNaN(+period
)) {
3074 deprecateSimple(name
, 'moment().' + name
+ '(period, number) is deprecated. Please use moment().' + name
+ '(number, period). ' +
3075 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
3076 tmp
= val
; val
= period
; period
= tmp
;
3079 val
= typeof val
=== 'string' ? +val
: val
;
3080 dur
= createDuration(val
, period
);
3081 addSubtract(this, dur
, direction
);
3086 function addSubtract (mom
, duration
, isAdding
, updateOffset
) {
3087 var milliseconds
= duration
._milliseconds
,
3088 days
= absRound(duration
._days
),
3089 months
= absRound(duration
._months
);
3091 if (!mom
.isValid()) {
3096 updateOffset
= updateOffset
== null ? true : updateOffset
;
3099 mom
._d
.setTime(mom
._d
.valueOf() + milliseconds
* isAdding
);
3102 set$1(mom
, 'Date', get(mom
, 'Date') + days
* isAdding
);
3105 setMonth(mom
, get(mom
, 'Month') + months
* isAdding
);
3108 hooks
.updateOffset(mom
, days
|| months
);
3112 var add
= createAdder(1, 'add');
3113 var subtract
= createAdder(-1, 'subtract');
3115 function getCalendarFormat(myMoment
, now
) {
3116 var diff
= myMoment
.diff(now
, 'days', true);
3117 return diff
< -6 ? 'sameElse' :
3118 diff
< -1 ? 'lastWeek' :
3119 diff
< 0 ? 'lastDay' :
3120 diff
< 1 ? 'sameDay' :
3121 diff
< 2 ? 'nextDay' :
3122 diff
< 7 ? 'nextWeek' : 'sameElse';
3125 function calendar
$1 (time
, formats
) {
3126 // We want to compare the start of today, vs this.
3127 // Getting start-of-today depends on whether we're local/utc/offset or not.
3128 var now
= time
|| createLocal(),
3129 sod
= cloneWithOffset(now
, this).startOf('day'),
3130 format
= hooks
.calendarFormat(this, sod
) || 'sameElse';
3132 var output
= formats
&& (isFunction(formats
[format
]) ? formats
[format
].call(this, now
) : formats
[format
]);
3134 return this.format(output
|| this.localeData().calendar(format
, this, createLocal(now
)));
3138 return new Moment(this);
3141 function isAfter (input
, units
) {
3142 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3143 if (!(this.isValid() && localInput
.isValid())) {
3146 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3147 if (units
=== 'millisecond') {
3148 return this.valueOf() > localInput
.valueOf();
3150 return localInput
.valueOf() < this.clone().startOf(units
).valueOf();
3154 function isBefore (input
, units
) {
3155 var localInput
= isMoment(input
) ? input
: createLocal(input
);
3156 if (!(this.isValid() && localInput
.isValid())) {
3159 units
= normalizeUnits(!isUndefined(units
) ? units
: 'millisecond');
3160 if (units
=== 'millisecond') {
3161 return this.valueOf() < localInput
.valueOf();
3163 return this.clone().endOf(units
).valueOf() < localInput
.valueOf();
3167 function isBetween (from, to
, units
, inclusivity
) {
3168 inclusivity
= inclusivity
|| '()';
3169 return (inclusivity
[0] === '(' ? this.isAfter(from, units
) : !this.isBefore(from, units
)) &&
3170 (inclusivity
[1] === ')' ? this.isBefore(to
, units
) : !this.isAfter(to
, units
));
3173 function isSame (input
, units
) {
3174 var localInput
= isMoment(input
) ? input
: createLocal(input
),
3176 if (!(this.isValid() && localInput
.isValid())) {
3179 units
= normalizeUnits(units
|| 'millisecond');
3180 if (units
=== 'millisecond') {
3181 return this.valueOf() === localInput
.valueOf();
3183 inputMs
= localInput
.valueOf();
3184 return this.clone().startOf(units
).valueOf() <= inputMs
&& inputMs
<= this.clone().endOf(units
).valueOf();
3188 function isSameOrAfter (input
, units
) {
3189 return this.isSame(input
, units
) || this.isAfter(input
,units
);
3192 function isSameOrBefore (input
, units
) {
3193 return this.isSame(input
, units
) || this.isBefore(input
,units
);
3196 function diff (input
, units
, asFloat
) {
3201 if (!this.isValid()) {
3205 that
= cloneWithOffset(input
, this);
3207 if (!that
.isValid()) {
3211 zoneDelta
= (that
.utcOffset() - this.utcOffset()) * 6e4
;
3213 units
= normalizeUnits(units
);
3215 if (units
=== 'year' || units
=== 'month' || units
=== 'quarter') {
3216 output
= monthDiff(this, that
);
3217 if (units
=== 'quarter') {
3218 output
= output
/ 3;
3219 } else if (units
=== 'year') {
3220 output
= output
/ 12;
3223 delta
= this - that
;
3224 output
= units
=== 'second' ? delta
/ 1e3
: // 1000
3225 units
=== 'minute' ? delta
/ 6e4
: // 1000 * 60
3226 units
=== 'hour' ? delta
/ 36e5
: // 1000 * 60 * 60
3227 units
=== 'day' ? (delta
- zoneDelta
) / 864e5
: // 1000 * 60 * 60 * 24, negate dst
3228 units
=== 'week' ? (delta
- zoneDelta
) / 6048e5
: // 1000 * 60 * 60 * 24 * 7, negate dst
3231 return asFloat
? output
: absFloor(output
);
3234 function monthDiff (a
, b
) {
3235 // difference in months
3236 var wholeMonthDiff
= ((b
.year() - a
.year()) * 12) + (b
.month() - a
.month()),
3237 // b is in (anchor - 1 month, anchor + 1 month)
3238 anchor
= a
.clone().add(wholeMonthDiff
, 'months'),
3241 if (b
- anchor
< 0) {
3242 anchor2
= a
.clone().add(wholeMonthDiff
- 1, 'months');
3243 // linear across the month
3244 adjust
= (b
- anchor
) / (anchor
- anchor2
);
3246 anchor2
= a
.clone().add(wholeMonthDiff
+ 1, 'months');
3247 // linear across the month
3248 adjust
= (b
- anchor
) / (anchor2
- anchor
);
3251 //check for negative zero, return zero if negative zero
3252 return -(wholeMonthDiff
+ adjust
) || 0;
3255 hooks
.defaultFormat
= 'YYYY-MM-DDTHH:mm:ssZ';
3256 hooks
.defaultFormatUtc
= 'YYYY-MM-DDTHH:mm:ss[Z]';
3258 function toString () {
3259 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
3262 function toISOString() {
3263 if (!this.isValid()) {
3266 var m
= this.clone().utc();
3267 if (m
.year() < 0 || m
.year() > 9999) {
3268 return formatMoment(m
, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
3270 if (isFunction(Date
.prototype.toISOString
)) {
3271 // native implementation is ~50x faster, use it when we can
3272 return this.toDate().toISOString();
3274 return formatMoment(m
, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
3278 * Return a human readable representation of a moment that can
3279 * also be evaluated to get a new moment which is the same
3281 * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
3283 function inspect () {
3284 if (!this.isValid()) {
3285 return 'moment.invalid(/* ' + this._i
+ ' */)';
3287 var func
= 'moment';
3289 if (!this.isLocal()) {
3290 func
= this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
3293 var prefix
= '[' + func
+ '("]';
3294 var year
= (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
3295 var datetime
= '-MM-DD[T]HH:mm:ss.SSS';
3296 var suffix
= zone
+ '[")]';
3298 return this.format(prefix
+ year
+ datetime
+ suffix
);
3301 function format (inputString
) {
3303 inputString
= this.isUtc() ? hooks
.defaultFormatUtc
: hooks
.defaultFormat
;
3305 var output
= formatMoment(this, inputString
);
3306 return this.localeData().postformat(output
);
3309 function from (time
, withoutSuffix
) {
3310 if (this.isValid() &&
3311 ((isMoment(time
) && time
.isValid()) ||
3312 createLocal(time
).isValid())) {
3313 return createDuration({to
: this, from: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3315 return this.localeData().invalidDate();
3319 function fromNow (withoutSuffix
) {
3320 return this.from(createLocal(), withoutSuffix
);
3323 function to (time
, withoutSuffix
) {
3324 if (this.isValid() &&
3325 ((isMoment(time
) && time
.isValid()) ||
3326 createLocal(time
).isValid())) {
3327 return createDuration({from: this, to
: time
}).locale(this.locale()).humanize(!withoutSuffix
);
3329 return this.localeData().invalidDate();
3333 function toNow (withoutSuffix
) {
3334 return this.to(createLocal(), withoutSuffix
);
3337 // If passed a locale key, it will set the locale for this
3338 // instance. Otherwise, it will return the locale configuration
3339 // variables for this instance.
3340 function locale (key
) {
3343 if (key
=== undefined) {
3344 return this._locale
._abbr
;
3346 newLocaleData
= getLocale(key
);
3347 if (newLocaleData
!= null) {
3348 this._locale
= newLocaleData
;
3354 var lang
= deprecate(
3355 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
3357 if (key
=== undefined) {
3358 return this.localeData();
3360 return this.locale(key
);
3365 function localeData () {
3366 return this._locale
;
3369 function startOf (units
) {
3370 units
= normalizeUnits(units
);
3371 // the following switch intentionally omits break keywords
3372 // to utilize falling through the cases.
3394 this.milliseconds(0);
3397 // weeks are a special case
3398 if (units
=== 'week') {
3401 if (units
=== 'isoWeek') {
3405 // quarters are also special
3406 if (units
=== 'quarter') {
3407 this.month(Math
.floor(this.month() / 3) * 3);
3413 function endOf (units
) {
3414 units
= normalizeUnits(units
);
3415 if (units
=== undefined || units
=== 'millisecond') {
3419 // 'date' is an alias for 'day', so it should be considered as such.
3420 if (units
=== 'date') {
3424 return this.startOf(units
).add(1, (units
=== 'isoWeek' ? 'week' : units
)).subtract(1, 'ms');
3427 function valueOf () {
3428 return this._d
.valueOf() - ((this._offset
|| 0) * 60000);
3432 return Math
.floor(this.valueOf() / 1000);
3435 function toDate () {
3436 return new Date(this.valueOf());
3439 function toArray () {
3441 return [m
.year(), m
.month(), m
.date(), m
.hour(), m
.minute(), m
.second(), m
.millisecond()];
3444 function toObject () {
3451 minutes
: m
.minutes(),
3452 seconds
: m
.seconds(),
3453 milliseconds
: m
.milliseconds()
3457 function toJSON () {
3458 // new Date(NaN).toJSON() === null
3459 return this.isValid() ? this.toISOString() : null;
3462 function isValid
$2 () {
3463 return isValid(this);
3466 function parsingFlags () {
3467 return extend({}, getParsingFlags(this));
3470 function invalidAt () {
3471 return getParsingFlags(this).overflow
;
3474 function creationData() {
3478 locale
: this._locale
,
3480 strict
: this._strict
3486 addFormatToken(0, ['gg', 2], 0, function () {
3487 return this.weekYear() % 100;
3490 addFormatToken(0, ['GG', 2], 0, function () {
3491 return this.isoWeekYear() % 100;
3494 function addWeekYearFormatToken (token
, getter
) {
3495 addFormatToken(0, [token
, token
.length
], 0, getter
);
3498 addWeekYearFormatToken('gggg', 'weekYear');
3499 addWeekYearFormatToken('ggggg', 'weekYear');
3500 addWeekYearFormatToken('GGGG', 'isoWeekYear');
3501 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
3505 addUnitAlias('weekYear', 'gg');
3506 addUnitAlias('isoWeekYear', 'GG');
3510 addUnitPriority('weekYear', 1);
3511 addUnitPriority('isoWeekYear', 1);
3516 addRegexToken('G', matchSigned
);
3517 addRegexToken('g', matchSigned
);
3518 addRegexToken('GG', match1to2
, match2
);
3519 addRegexToken('gg', match1to2
, match2
);
3520 addRegexToken('GGGG', match1to4
, match4
);
3521 addRegexToken('gggg', match1to4
, match4
);
3522 addRegexToken('GGGGG', match1to6
, match6
);
3523 addRegexToken('ggggg', match1to6
, match6
);
3525 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input
, week
, config
, token
) {
3526 week
[token
.substr(0, 2)] = toInt(input
);
3529 addWeekParseToken(['gg', 'GG'], function (input
, week
, config
, token
) {
3530 week
[token
] = hooks
.parseTwoDigitYear(input
);
3535 function getSetWeekYear (input
) {
3536 return getSetWeekYearHelper
.call(this,
3540 this.localeData()._week
.dow
,
3541 this.localeData()._week
.doy
);
3544 function getSetISOWeekYear (input
) {
3545 return getSetWeekYearHelper
.call(this,
3546 input
, this.isoWeek(), this.isoWeekday(), 1, 4);
3549 function getISOWeeksInYear () {
3550 return weeksInYear(this.year(), 1, 4);
3553 function getWeeksInYear () {
3554 var weekInfo
= this.localeData()._week
;
3555 return weeksInYear(this.year(), weekInfo
.dow
, weekInfo
.doy
);
3558 function getSetWeekYearHelper(input
, week
, weekday
, dow
, doy
) {
3560 if (input
== null) {
3561 return weekOfYear(this, dow
, doy
).year
;
3563 weeksTarget
= weeksInYear(input
, dow
, doy
);
3564 if (week
> weeksTarget
) {
3567 return setWeekAll
.call(this, input
, week
, weekday
, dow
, doy
);
3571 function setWeekAll(weekYear
, week
, weekday
, dow
, doy
) {
3572 var dayOfYearData
= dayOfYearFromWeeks(weekYear
, week
, weekday
, dow
, doy
),
3573 date
= createUTCDate(dayOfYearData
.year
, 0, dayOfYearData
.dayOfYear
);
3575 this.year(date
.getUTCFullYear());
3576 this.month(date
.getUTCMonth());
3577 this.date(date
.getUTCDate());
3583 addFormatToken('Q', 0, 'Qo', 'quarter');
3587 addUnitAlias('quarter', 'Q');
3591 addUnitPriority('quarter', 7);
3595 addRegexToken('Q', match1
);
3596 addParseToken('Q', function (input
, array
) {
3597 array
[MONTH
] = (toInt(input
) - 1) * 3;
3602 function getSetQuarter (input
) {
3603 return input
== null ? Math
.ceil((this.month() + 1) / 3) : this.month((input
- 1) * 3 + this.month() % 3);
3608 addFormatToken('D', ['DD', 2], 'Do', 'date');
3612 addUnitAlias('date', 'D');
3615 addUnitPriority('date', 9);
3619 addRegexToken('D', match1to2
);
3620 addRegexToken('DD', match1to2
, match2
);
3621 addRegexToken('Do', function (isStrict
, locale
) {
3622 // TODO: Remove "ordinalParse" fallback in next major release.
3624 (locale
._dayOfMonthOrdinalParse
|| locale
._ordinalParse
) :
3625 locale
._dayOfMonthOrdinalParseLenient
;
3628 addParseToken(['D', 'DD'], DATE
);
3629 addParseToken('Do', function (input
, array
) {
3630 array
[DATE
] = toInt(input
.match(match1to2
)[0], 10);
3635 var getSetDayOfMonth
= makeGetSet('Date', true);
3639 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
3643 addUnitAlias('dayOfYear', 'DDD');
3646 addUnitPriority('dayOfYear', 4);
3650 addRegexToken('DDD', match1to3
);
3651 addRegexToken('DDDD', match3
);
3652 addParseToken(['DDD', 'DDDD'], function (input
, array
, config
) {
3653 config
._dayOfYear
= toInt(input
);
3660 function getSetDayOfYear (input
) {
3661 var dayOfYear
= Math
.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
) + 1;
3662 return input
== null ? dayOfYear
: this.add((input
- dayOfYear
), 'd');
3667 addFormatToken('m', ['mm', 2], 0, 'minute');
3671 addUnitAlias('minute', 'm');
3675 addUnitPriority('minute', 14);
3679 addRegexToken('m', match1to2
);
3680 addRegexToken('mm', match1to2
, match2
);
3681 addParseToken(['m', 'mm'], MINUTE
);
3685 var getSetMinute
= makeGetSet('Minutes', false);
3689 addFormatToken('s', ['ss', 2], 0, 'second');
3693 addUnitAlias('second', 's');
3697 addUnitPriority('second', 15);
3701 addRegexToken('s', match1to2
);
3702 addRegexToken('ss', match1to2
, match2
);
3703 addParseToken(['s', 'ss'], SECOND
);
3707 var getSetSecond
= makeGetSet('Seconds', false);
3711 addFormatToken('S', 0, 0, function () {
3712 return ~~(this.millisecond() / 100);
3715 addFormatToken(0, ['SS', 2], 0, function () {
3716 return ~~(this.millisecond() / 10);
3719 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
3720 addFormatToken(0, ['SSSS', 4], 0, function () {
3721 return this.millisecond() * 10;
3723 addFormatToken(0, ['SSSSS', 5], 0, function () {
3724 return this.millisecond() * 100;
3726 addFormatToken(0, ['SSSSSS', 6], 0, function () {
3727 return this.millisecond() * 1000;
3729 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
3730 return this.millisecond() * 10000;
3732 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
3733 return this.millisecond() * 100000;
3735 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
3736 return this.millisecond() * 1000000;
3742 addUnitAlias('millisecond', 'ms');
3746 addUnitPriority('millisecond', 16);
3750 addRegexToken('S', match1to3
, match1
);
3751 addRegexToken('SS', match1to3
, match2
);
3752 addRegexToken('SSS', match1to3
, match3
);
3755 for (token
= 'SSSS'; token
.length
<= 9; token
+= 'S') {
3756 addRegexToken(token
, matchUnsigned
);
3759 function parseMs(input
, array
) {
3760 array
[MILLISECOND
] = toInt(('0.' + input
) * 1000);
3763 for (token
= 'S'; token
.length
<= 9; token
+= 'S') {
3764 addParseToken(token
, parseMs
);
3768 var getSetMillisecond
= makeGetSet('Milliseconds', false);
3772 addFormatToken('z', 0, 0, 'zoneAbbr');
3773 addFormatToken('zz', 0, 0, 'zoneName');
3777 function getZoneAbbr () {
3778 return this._isUTC
? 'UTC' : '';
3781 function getZoneName () {
3782 return this._isUTC
? 'Coordinated Universal Time' : '';
3785 var proto
= Moment
.prototype;
3788 proto
.calendar
= calendar
$1;
3789 proto
.clone
= clone
;
3791 proto
.endOf
= endOf
;
3792 proto
.format
= format
;
3794 proto
.fromNow
= fromNow
;
3796 proto
.toNow
= toNow
;
3797 proto
.get = stringGet
;
3798 proto
.invalidAt
= invalidAt
;
3799 proto
.isAfter
= isAfter
;
3800 proto
.isBefore
= isBefore
;
3801 proto
.isBetween
= isBetween
;
3802 proto
.isSame
= isSame
;
3803 proto
.isSameOrAfter
= isSameOrAfter
;
3804 proto
.isSameOrBefore
= isSameOrBefore
;
3805 proto
.isValid
= isValid
$2;
3807 proto
.locale
= locale
;
3808 proto
.localeData
= localeData
;
3809 proto
.max
= prototypeMax
;
3810 proto
.min
= prototypeMin
;
3811 proto
.parsingFlags
= parsingFlags
;
3812 proto
.set = stringSet
;
3813 proto
.startOf
= startOf
;
3814 proto
.subtract
= subtract
;
3815 proto
.toArray
= toArray
;
3816 proto
.toObject
= toObject
;
3817 proto
.toDate
= toDate
;
3818 proto
.toISOString
= toISOString
;
3819 proto
.inspect
= inspect
;
3820 proto
.toJSON
= toJSON
;
3821 proto
.toString
= toString
;
3823 proto
.valueOf
= valueOf
;
3824 proto
.creationData
= creationData
;
3827 proto
.year
= getSetYear
;
3828 proto
.isLeapYear
= getIsLeapYear
;
3831 proto
.weekYear
= getSetWeekYear
;
3832 proto
.isoWeekYear
= getSetISOWeekYear
;
3835 proto
.quarter
= proto
.quarters
= getSetQuarter
;
3838 proto
.month
= getSetMonth
;
3839 proto
.daysInMonth
= getDaysInMonth
;
3842 proto
.week
= proto
.weeks
= getSetWeek
;
3843 proto
.isoWeek
= proto
.isoWeeks
= getSetISOWeek
;
3844 proto
.weeksInYear
= getWeeksInYear
;
3845 proto
.isoWeeksInYear
= getISOWeeksInYear
;
3848 proto
.date
= getSetDayOfMonth
;
3849 proto
.day
= proto
.days
= getSetDayOfWeek
;
3850 proto
.weekday
= getSetLocaleDayOfWeek
;
3851 proto
.isoWeekday
= getSetISODayOfWeek
;
3852 proto
.dayOfYear
= getSetDayOfYear
;
3855 proto
.hour
= proto
.hours
= getSetHour
;
3858 proto
.minute
= proto
.minutes
= getSetMinute
;
3861 proto
.second
= proto
.seconds
= getSetSecond
;
3864 proto
.millisecond
= proto
.milliseconds
= getSetMillisecond
;
3867 proto
.utcOffset
= getSetOffset
;
3868 proto
.utc
= setOffsetToUTC
;
3869 proto
.local
= setOffsetToLocal
;
3870 proto
.parseZone
= setOffsetToParsedOffset
;
3871 proto
.hasAlignedHourOffset
= hasAlignedHourOffset
;
3872 proto
.isDST
= isDaylightSavingTime
;
3873 proto
.isLocal
= isLocal
;
3874 proto
.isUtcOffset
= isUtcOffset
;
3875 proto
.isUtc
= isUtc
;
3876 proto
.isUTC
= isUtc
;
3879 proto
.zoneAbbr
= getZoneAbbr
;
3880 proto
.zoneName
= getZoneName
;
3883 proto
.dates
= deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth
);
3884 proto
.months
= deprecate('months accessor is deprecated. Use month instead', getSetMonth
);
3885 proto
.years
= deprecate('years accessor is deprecated. Use year instead', getSetYear
);
3886 proto
.zone
= deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone
);
3887 proto
.isDSTShifted
= deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted
);
3889 function createUnix (input
) {
3890 return createLocal(input
* 1000);
3893 function createInZone () {
3894 return createLocal
.apply(null, arguments
).parseZone();
3897 function preParsePostFormat (string
) {
3901 var proto
$1 = Locale
.prototype;
3903 proto
$1.calendar
= calendar
;
3904 proto
$1.longDateFormat
= longDateFormat
;
3905 proto
$1.invalidDate
= invalidDate
;
3906 proto
$1.ordinal
= ordinal
;
3907 proto
$1.preparse
= preParsePostFormat
;
3908 proto
$1.postformat
= preParsePostFormat
;
3909 proto
$1.relativeTime
= relativeTime
;
3910 proto
$1.pastFuture
= pastFuture
;
3914 proto
$1.months
= localeMonths
;
3915 proto
$1.monthsShort
= localeMonthsShort
;
3916 proto
$1.monthsParse
= localeMonthsParse
;
3917 proto
$1.monthsRegex
= monthsRegex
;
3918 proto
$1.monthsShortRegex
= monthsShortRegex
;
3921 proto
$1.week
= localeWeek
;
3922 proto
$1.firstDayOfYear
= localeFirstDayOfYear
;
3923 proto
$1.firstDayOfWeek
= localeFirstDayOfWeek
;
3926 proto
$1.weekdays
= localeWeekdays
;
3927 proto
$1.weekdaysMin
= localeWeekdaysMin
;
3928 proto
$1.weekdaysShort
= localeWeekdaysShort
;
3929 proto
$1.weekdaysParse
= localeWeekdaysParse
;
3931 proto
$1.weekdaysRegex
= weekdaysRegex
;
3932 proto
$1.weekdaysShortRegex
= weekdaysShortRegex
;
3933 proto
$1.weekdaysMinRegex
= weekdaysMinRegex
;
3936 proto
$1.isPM
= localeIsPM
;
3937 proto
$1.meridiem
= localeMeridiem
;
3939 function get$1 (format
, index
, field
, setter
) {
3940 var locale
= getLocale();
3941 var utc
= createUTC().set(setter
, index
);
3942 return locale
[field
](utc
, format
);
3945 function listMonthsImpl (format
, index
, field
) {
3946 if (isNumber(format
)) {
3951 format
= format
|| '';
3953 if (index
!= null) {
3954 return get$1(format
, index
, field
, 'month');
3959 for (i
= 0; i
< 12; i
++) {
3960 out
[i
] = get$1(format
, i
, field
, 'month');
3973 function listWeekdaysImpl (localeSorted
, format
, index
, field
) {
3974 if (typeof localeSorted
=== 'boolean') {
3975 if (isNumber(format
)) {
3980 format
= format
|| '';
3982 format
= localeSorted
;
3984 localeSorted
= false;
3986 if (isNumber(format
)) {
3991 format
= format
|| '';
3994 var locale
= getLocale(),
3995 shift
= localeSorted
? locale
._week
.dow
: 0;
3997 if (index
!= null) {
3998 return get$1(format
, (index
+ shift
) % 7, field
, 'day');
4003 for (i
= 0; i
< 7; i
++) {
4004 out
[i
] = get$1(format
, (i
+ shift
) % 7, field
, 'day');
4009 function listMonths (format
, index
) {
4010 return listMonthsImpl(format
, index
, 'months');
4013 function listMonthsShort (format
, index
) {
4014 return listMonthsImpl(format
, index
, 'monthsShort');
4017 function listWeekdays (localeSorted
, format
, index
) {
4018 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdays');
4021 function listWeekdaysShort (localeSorted
, format
, index
) {
4022 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysShort');
4025 function listWeekdaysMin (localeSorted
, format
, index
) {
4026 return listWeekdaysImpl(localeSorted
, format
, index
, 'weekdaysMin');
4029 getSetGlobalLocale('en', {
4030 dayOfMonthOrdinalParse
: /\d{1,2}(th|st|nd|rd)/,
4031 ordinal : function (number
) {
4032 var b
= number
% 10,
4033 output
= (toInt(number
% 100 / 10) === 1) ? 'th' :
4036 (b
=== 3) ? 'rd' : 'th';
4037 return number
+ output
;
4041 // Side effect imports
4042 hooks
.lang
= deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale
);
4043 hooks
.langData
= deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale
);
4045 var mathAbs
= Math
.abs
;
4048 var data
= this._data
;
4050 this._milliseconds
= mathAbs(this._milliseconds
);
4051 this._days
= mathAbs(this._days
);
4052 this._months
= mathAbs(this._months
);
4054 data
.milliseconds
= mathAbs(data
.milliseconds
);
4055 data
.seconds
= mathAbs(data
.seconds
);
4056 data
.minutes
= mathAbs(data
.minutes
);
4057 data
.hours
= mathAbs(data
.hours
);
4058 data
.months
= mathAbs(data
.months
);
4059 data
.years
= mathAbs(data
.years
);
4064 function addSubtract
$1 (duration
, input
, value
, direction
) {
4065 var other
= createDuration(input
, value
);
4067 duration
._milliseconds
+= direction
* other
._milliseconds
;
4068 duration
._days
+= direction
* other
._days
;
4069 duration
._months
+= direction
* other
._months
;
4071 return duration
._bubble();
4074 // supports only 2.0-style add(1, 's') or add(duration)
4075 function add
$1 (input
, value
) {
4076 return addSubtract
$1(this, input
, value
, 1);
4079 // supports only 2.0-style subtract(1, 's') or subtract(duration)
4080 function subtract
$1 (input
, value
) {
4081 return addSubtract
$1(this, input
, value
, -1);
4084 function absCeil (number
) {
4086 return Math
.floor(number
);
4088 return Math
.ceil(number
);
4092 function bubble () {
4093 var milliseconds
= this._milliseconds
;
4094 var days
= this._days
;
4095 var months
= this._months
;
4096 var data
= this._data
;
4097 var seconds
, minutes
, hours
, years
, monthsFromDays
;
4099 // if we have a mix of positive and negative values, bubble down first
4100 // check: https://github.com/moment/moment/issues/2166
4101 if (!((milliseconds
>= 0 && days
>= 0 && months
>= 0) ||
4102 (milliseconds
<= 0 && days
<= 0 && months
<= 0))) {
4103 milliseconds
+= absCeil(monthsToDays(months
) + days
) * 864e5
;
4108 // The following code bubbles up values, see the tests for
4109 // examples of what that means.
4110 data
.milliseconds
= milliseconds
% 1000;
4112 seconds
= absFloor(milliseconds
/ 1000);
4113 data
.seconds
= seconds
% 60;
4115 minutes
= absFloor(seconds
/ 60);
4116 data
.minutes
= minutes
% 60;
4118 hours
= absFloor(minutes
/ 60);
4119 data
.hours
= hours
% 24;
4121 days
+= absFloor(hours
/ 24);
4123 // convert days to months
4124 monthsFromDays
= absFloor(daysToMonths(days
));
4125 months
+= monthsFromDays
;
4126 days
-= absCeil(monthsToDays(monthsFromDays
));
4128 // 12 months -> 1 year
4129 years
= absFloor(months
/ 12);
4133 data
.months
= months
;
4139 function daysToMonths (days
) {
4140 // 400 years have 146097 days (taking into account leap year rules)
4141 // 400 years have 12 months === 4800
4142 return days
* 4800 / 146097;
4145 function monthsToDays (months
) {
4146 // the reverse of daysToMonths
4147 return months
* 146097 / 4800;
4150 function as (units
) {
4151 if (!this.isValid()) {
4156 var milliseconds
= this._milliseconds
;
4158 units
= normalizeUnits(units
);
4160 if (units
=== 'month' || units
=== 'year') {
4161 days
= this._days
+ milliseconds
/ 864e5
;
4162 months
= this._months
+ daysToMonths(days
);
4163 return units
=== 'month' ? months
: months
/ 12;
4165 // handle milliseconds separately because of floating point math errors (issue #1867)
4166 days
= this._days
+ Math
.round(monthsToDays(this._months
));
4168 case 'week' : return days
/ 7 + milliseconds
/ 6048e5
;
4169 case 'day' : return days
+ milliseconds
/ 864e5
;
4170 case 'hour' : return days
* 24 + milliseconds
/ 36e5
;
4171 case 'minute' : return days
* 1440 + milliseconds
/ 6e4
;
4172 case 'second' : return days
* 86400 + milliseconds
/ 1000;
4173 // Math.floor prevents floating point math errors here
4174 case 'millisecond': return Math
.floor(days
* 864e5
) + milliseconds
;
4175 default: throw new Error('Unknown unit ' + units
);
4180 // TODO: Use this.as('ms')?
4181 function valueOf
$1 () {
4182 if (!this.isValid()) {
4186 this._milliseconds
+
4187 this._days
* 864e5
+
4188 (this._months
% 12) * 2592e6
+
4189 toInt(this._months
/ 12) * 31536e6
4193 function makeAs (alias
) {
4194 return function () {
4195 return this.as(alias
);
4199 var asMilliseconds
= makeAs('ms');
4200 var asSeconds
= makeAs('s');
4201 var asMinutes
= makeAs('m');
4202 var asHours
= makeAs('h');
4203 var asDays
= makeAs('d');
4204 var asWeeks
= makeAs('w');
4205 var asMonths
= makeAs('M');
4206 var asYears
= makeAs('y');
4208 function get$2 (units
) {
4209 units
= normalizeUnits(units
);
4210 return this.isValid() ? this[units
+ 's']() : NaN
;
4213 function makeGetter(name
) {
4214 return function () {
4215 return this.isValid() ? this._data
[name
] : NaN
;
4219 var milliseconds
= makeGetter('milliseconds');
4220 var seconds
= makeGetter('seconds');
4221 var minutes
= makeGetter('minutes');
4222 var hours
= makeGetter('hours');
4223 var days
= makeGetter('days');
4224 var months
= makeGetter('months');
4225 var years
= makeGetter('years');
4228 return absFloor(this.days() / 7);
4231 var round
= Math
.round
;
4233 ss
: 44, // a few seconds to seconds
4234 s
: 45, // seconds to minute
4235 m
: 45, // minutes to hour
4236 h
: 22, // hours to day
4237 d
: 26, // days to month
4238 M
: 11 // months to year
4241 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
4242 function substituteTimeAgo(string
, number
, withoutSuffix
, isFuture
, locale
) {
4243 return locale
.relativeTime(number
|| 1, !!withoutSuffix
, string
, isFuture
);
4246 function relativeTime
$1 (posNegDuration
, withoutSuffix
, locale
) {
4247 var duration
= createDuration(posNegDuration
).abs();
4248 var seconds
= round(duration
.as('s'));
4249 var minutes
= round(duration
.as('m'));
4250 var hours
= round(duration
.as('h'));
4251 var days
= round(duration
.as('d'));
4252 var months
= round(duration
.as('M'));
4253 var years
= round(duration
.as('y'));
4255 var a
= seconds
<= thresholds
.ss
&& ['s', seconds
] ||
4256 seconds
< thresholds
.s
&& ['ss', seconds
] ||
4257 minutes
<= 1 && ['m'] ||
4258 minutes
< thresholds
.m
&& ['mm', minutes
] ||
4259 hours
<= 1 && ['h'] ||
4260 hours
< thresholds
.h
&& ['hh', hours
] ||
4261 days
<= 1 && ['d'] ||
4262 days
< thresholds
.d
&& ['dd', days
] ||
4263 months
<= 1 && ['M'] ||
4264 months
< thresholds
.M
&& ['MM', months
] ||
4265 years
<= 1 && ['y'] || ['yy', years
];
4267 a
[2] = withoutSuffix
;
4268 a
[3] = +posNegDuration
> 0;
4270 return substituteTimeAgo
.apply(null, a
);
4273 // This function allows you to set the rounding function for relative time strings
4274 function getSetRelativeTimeRounding (roundingFunction
) {
4275 if (roundingFunction
=== undefined) {
4278 if (typeof(roundingFunction
) === 'function') {
4279 round
= roundingFunction
;
4285 // This function allows you to set a threshold for relative time strings
4286 function getSetRelativeTimeThreshold (threshold
, limit
) {
4287 if (thresholds
[threshold
] === undefined) {
4290 if (limit
=== undefined) {
4291 return thresholds
[threshold
];
4293 thresholds
[threshold
] = limit
;
4294 if (threshold
=== 's') {
4295 thresholds
.ss
= limit
- 1;
4300 function humanize (withSuffix
) {
4301 if (!this.isValid()) {
4302 return this.localeData().invalidDate();
4305 var locale
= this.localeData();
4306 var output
= relativeTime
$1(this, !withSuffix
, locale
);
4309 output
= locale
.pastFuture(+this, output
);
4312 return locale
.postformat(output
);
4315 var abs
$1 = Math
.abs
;
4317 function toISOString
$1() {
4318 // for ISO strings we do not use the normal bubbling rules:
4319 // * milliseconds bubble up until they become hours
4320 // * days do not bubble at all
4321 // * months bubble up until they become years
4322 // This is because there is no context-free conversion between hours and days
4323 // (think of clock changes)
4324 // and also not between days and months (28-31 days per month)
4325 if (!this.isValid()) {
4326 return this.localeData().invalidDate();
4329 var seconds
= abs
$1(this._milliseconds
) / 1000;
4330 var days
= abs
$1(this._days
);
4331 var months
= abs
$1(this._months
);
4332 var minutes
, hours
, years
;
4334 // 3600 seconds -> 60 minutes -> 1 hour
4335 minutes
= absFloor(seconds
/ 60);
4336 hours
= absFloor(minutes
/ 60);
4340 // 12 months -> 1 year
4341 years
= absFloor(months
/ 12);
4345 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
4352 var total
= this.asSeconds();
4355 // this is the same as C#'s (Noda) and python (isodate)...
4356 // but not other JS (goog.date)
4360 return (total
< 0 ? '-' : '') +
4362 (Y
? Y
+ 'Y' : '') +
4363 (M
? M
+ 'M' : '') +
4364 (D
? D
+ 'D' : '') +
4365 ((h
|| m
|| s
) ? 'T' : '') +
4366 (h
? h
+ 'H' : '') +
4367 (m
? m
+ 'M' : '') +
4371 var proto
$2 = Duration
.prototype;
4373 proto
$2.isValid
= isValid
$1;
4375 proto
$2.add
= add
$1;
4376 proto
$2.subtract
= subtract
$1;
4378 proto
$2.asMilliseconds
= asMilliseconds
;
4379 proto
$2.asSeconds
= asSeconds
;
4380 proto
$2.asMinutes
= asMinutes
;
4381 proto
$2.asHours
= asHours
;
4382 proto
$2.asDays
= asDays
;
4383 proto
$2.asWeeks
= asWeeks
;
4384 proto
$2.asMonths
= asMonths
;
4385 proto
$2.asYears
= asYears
;
4386 proto
$2.valueOf
= valueOf
$1;
4387 proto
$2._bubble
= bubble
;
4388 proto
$2.get = get$2;
4389 proto
$2.milliseconds
= milliseconds
;
4390 proto
$2.seconds
= seconds
;
4391 proto
$2.minutes
= minutes
;
4392 proto
$2.hours
= hours
;
4393 proto
$2.days
= days
;
4394 proto
$2.weeks
= weeks
;
4395 proto
$2.months
= months
;
4396 proto
$2.years
= years
;
4397 proto
$2.humanize
= humanize
;
4398 proto
$2.toISOString
= toISOString
$1;
4399 proto
$2.toString
= toISOString
$1;
4400 proto
$2.toJSON
= toISOString
$1;
4401 proto
$2.locale
= locale
;
4402 proto
$2.localeData
= localeData
;
4405 proto
$2.toIsoString
= deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString
$1);
4406 proto
$2.lang
= lang
;
4408 // Side effect imports
4412 addFormatToken('X', 0, 0, 'unix');
4413 addFormatToken('x', 0, 0, 'valueOf');
4417 addRegexToken('x', matchSigned
);
4418 addRegexToken('X', matchTimestamp
);
4419 addParseToken('X', function (input
, array
, config
) {
4420 config
._d
= new Date(parseFloat(input
, 10) * 1000);
4422 addParseToken('x', function (input
, array
, config
) {
4423 config
._d
= new Date(toInt(input
));
4426 // Side effect imports
4429 hooks
.version
= '2.18.1';
4431 setHookCallback(createLocal
);
4437 hooks
.utc
= createUTC
;
4438 hooks
.unix
= createUnix
;
4439 hooks
.months
= listMonths
;
4440 hooks
.isDate
= isDate
;
4441 hooks
.locale
= getSetGlobalLocale
;
4442 hooks
.invalid
= createInvalid
;
4443 hooks
.duration
= createDuration
;
4444 hooks
.isMoment
= isMoment
;
4445 hooks
.weekdays
= listWeekdays
;
4446 hooks
.parseZone
= createInZone
;
4447 hooks
.localeData
= getLocale
;
4448 hooks
.isDuration
= isDuration
;
4449 hooks
.monthsShort
= listMonthsShort
;
4450 hooks
.weekdaysMin
= listWeekdaysMin
;
4451 hooks
.defineLocale
= defineLocale
;
4452 hooks
.updateLocale
= updateLocale
;
4453 hooks
.locales
= listLocales
;
4454 hooks
.weekdaysShort
= listWeekdaysShort
;
4455 hooks
.normalizeUnits
= normalizeUnits
;
4456 hooks
.relativeTimeRounding
= getSetRelativeTimeRounding
;
4457 hooks
.relativeTimeThreshold
= getSetRelativeTimeThreshold
;
4458 hooks
.calendarFormat
= getCalendarFormat
;
4459 hooks
.prototype = proto
;