0f6e2018cc49274b620af704b1d58af2be3c47bb
[lhc/web/www.git] / www / plugins-dist / organiseur / lib / moment / moment.js
1 //! moment.js
2 //! version : 2.29.0
3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
4 //! license : MIT
5 //! momentjs.com
6
7 var hookCallback;
8
9 function hooks() {
10 return hookCallback.apply(null, arguments);
11 }
12
13 // This is done to register the method called with moment()
14 // without creating circular dependencies.
15 function setHookCallback(callback) {
16 hookCallback = callback;
17 }
18
19 function isArray(input) {
20 return (
21 input instanceof Array ||
22 Object.prototype.toString.call(input) === '[object Array]'
23 );
24 }
25
26 function isObject(input) {
27 // IE8 will treat undefined and null as object if it wasn't for
28 // input != null
29 return (
30 input != null &&
31 Object.prototype.toString.call(input) === '[object Object]'
32 );
33 }
34
35 function hasOwnProp(a, b) {
36 return Object.prototype.hasOwnProperty.call(a, b);
37 }
38
39 function isObjectEmpty(obj) {
40 if (Object.getOwnPropertyNames) {
41 return Object.getOwnPropertyNames(obj).length === 0;
42 } else {
43 var k;
44 for (k in obj) {
45 if (hasOwnProp(obj, k)) {
46 return false;
47 }
48 }
49 return true;
50 }
51 }
52
53 function isUndefined(input) {
54 return input === void 0;
55 }
56
57 function isNumber(input) {
58 return (
59 typeof input === 'number' ||
60 Object.prototype.toString.call(input) === '[object Number]'
61 );
62 }
63
64 function isDate(input) {
65 return (
66 input instanceof Date ||
67 Object.prototype.toString.call(input) === '[object Date]'
68 );
69 }
70
71 function map(arr, fn) {
72 var res = [],
73 i;
74 for (i = 0; i < arr.length; ++i) {
75 res.push(fn(arr[i], i));
76 }
77 return res;
78 }
79
80 function extend(a, b) {
81 for (var i in b) {
82 if (hasOwnProp(b, i)) {
83 a[i] = b[i];
84 }
85 }
86
87 if (hasOwnProp(b, 'toString')) {
88 a.toString = b.toString;
89 }
90
91 if (hasOwnProp(b, 'valueOf')) {
92 a.valueOf = b.valueOf;
93 }
94
95 return a;
96 }
97
98 function createUTC(input, format, locale, strict) {
99 return createLocalOrUTC(input, format, locale, strict, true).utc();
100 }
101
102 function defaultParsingFlags() {
103 // We need to deep clone this object.
104 return {
105 empty: false,
106 unusedTokens: [],
107 unusedInput: [],
108 overflow: -2,
109 charsLeftOver: 0,
110 nullInput: false,
111 invalidEra: null,
112 invalidMonth: null,
113 invalidFormat: false,
114 userInvalidated: false,
115 iso: false,
116 parsedDateParts: [],
117 era: null,
118 meridiem: null,
119 rfc2822: false,
120 weekdayMismatch: false,
121 };
122 }
123
124 function getParsingFlags(m) {
125 if (m._pf == null) {
126 m._pf = defaultParsingFlags();
127 }
128 return m._pf;
129 }
130
131 var some;
132 if (Array.prototype.some) {
133 some = Array.prototype.some;
134 } else {
135 some = function (fun) {
136 var t = Object(this),
137 len = t.length >>> 0,
138 i;
139
140 for (i = 0; i < len; i++) {
141 if (i in t && fun.call(this, t[i], i, t)) {
142 return true;
143 }
144 }
145
146 return false;
147 };
148 }
149
150 function isValid(m) {
151 if (m._isValid == null) {
152 var flags = getParsingFlags(m),
153 parsedParts = some.call(flags.parsedDateParts, function (i) {
154 return i != null;
155 }),
156 isNowValid =
157 !isNaN(m._d.getTime()) &&
158 flags.overflow < 0 &&
159 !flags.empty &&
160 !flags.invalidEra &&
161 !flags.invalidMonth &&
162 !flags.invalidWeekday &&
163 !flags.weekdayMismatch &&
164 !flags.nullInput &&
165 !flags.invalidFormat &&
166 !flags.userInvalidated &&
167 (!flags.meridiem || (flags.meridiem && parsedParts));
168
169 if (m._strict) {
170 isNowValid =
171 isNowValid &&
172 flags.charsLeftOver === 0 &&
173 flags.unusedTokens.length === 0 &&
174 flags.bigHour === undefined;
175 }
176
177 if (Object.isFrozen == null || !Object.isFrozen(m)) {
178 m._isValid = isNowValid;
179 } else {
180 return isNowValid;
181 }
182 }
183 return m._isValid;
184 }
185
186 function createInvalid(flags) {
187 var m = createUTC(NaN);
188 if (flags != null) {
189 extend(getParsingFlags(m), flags);
190 } else {
191 getParsingFlags(m).userInvalidated = true;
192 }
193
194 return m;
195 }
196
197 // Plugins that add properties should also add the key here (null value),
198 // so we can properly clone ourselves.
199 var momentProperties = (hooks.momentProperties = []),
200 updateInProgress = false;
201
202 function copyConfig(to, from) {
203 var i, prop, val;
204
205 if (!isUndefined(from._isAMomentObject)) {
206 to._isAMomentObject = from._isAMomentObject;
207 }
208 if (!isUndefined(from._i)) {
209 to._i = from._i;
210 }
211 if (!isUndefined(from._f)) {
212 to._f = from._f;
213 }
214 if (!isUndefined(from._l)) {
215 to._l = from._l;
216 }
217 if (!isUndefined(from._strict)) {
218 to._strict = from._strict;
219 }
220 if (!isUndefined(from._tzm)) {
221 to._tzm = from._tzm;
222 }
223 if (!isUndefined(from._isUTC)) {
224 to._isUTC = from._isUTC;
225 }
226 if (!isUndefined(from._offset)) {
227 to._offset = from._offset;
228 }
229 if (!isUndefined(from._pf)) {
230 to._pf = getParsingFlags(from);
231 }
232 if (!isUndefined(from._locale)) {
233 to._locale = from._locale;
234 }
235
236 if (momentProperties.length > 0) {
237 for (i = 0; i < momentProperties.length; i++) {
238 prop = momentProperties[i];
239 val = from[prop];
240 if (!isUndefined(val)) {
241 to[prop] = val;
242 }
243 }
244 }
245
246 return to;
247 }
248
249 // Moment prototype object
250 function Moment(config) {
251 copyConfig(this, config);
252 this._d = new Date(config._d != null ? config._d.getTime() : NaN);
253 if (!this.isValid()) {
254 this._d = new Date(NaN);
255 }
256 // Prevent infinite loop in case updateOffset creates new moment
257 // objects.
258 if (updateInProgress === false) {
259 updateInProgress = true;
260 hooks.updateOffset(this);
261 updateInProgress = false;
262 }
263 }
264
265 function isMoment(obj) {
266 return (
267 obj instanceof Moment || (obj != null && obj._isAMomentObject != null)
268 );
269 }
270
271 function warn(msg) {
272 if (
273 hooks.suppressDeprecationWarnings === false &&
274 typeof console !== 'undefined' &&
275 console.warn
276 ) {
277 console.warn('Deprecation warning: ' + msg);
278 }
279 }
280
281 function deprecate(msg, fn) {
282 var firstTime = true;
283
284 return extend(function () {
285 if (hooks.deprecationHandler != null) {
286 hooks.deprecationHandler(null, msg);
287 }
288 if (firstTime) {
289 var args = [],
290 arg,
291 i,
292 key;
293 for (i = 0; i < arguments.length; i++) {
294 arg = '';
295 if (typeof arguments[i] === 'object') {
296 arg += '\n[' + i + '] ';
297 for (key in arguments[0]) {
298 if (hasOwnProp(arguments[0], key)) {
299 arg += key + ': ' + arguments[0][key] + ', ';
300 }
301 }
302 arg = arg.slice(0, -2); // Remove trailing comma and space
303 } else {
304 arg = arguments[i];
305 }
306 args.push(arg);
307 }
308 warn(
309 msg +
310 '\nArguments: ' +
311 Array.prototype.slice.call(args).join('') +
312 '\n' +
313 new Error().stack
314 );
315 firstTime = false;
316 }
317 return fn.apply(this, arguments);
318 }, fn);
319 }
320
321 var deprecations = {};
322
323 function deprecateSimple(name, msg) {
324 if (hooks.deprecationHandler != null) {
325 hooks.deprecationHandler(name, msg);
326 }
327 if (!deprecations[name]) {
328 warn(msg);
329 deprecations[name] = true;
330 }
331 }
332
333 hooks.suppressDeprecationWarnings = false;
334 hooks.deprecationHandler = null;
335
336 function isFunction(input) {
337 return (
338 (typeof Function !== 'undefined' && input instanceof Function) ||
339 Object.prototype.toString.call(input) === '[object Function]'
340 );
341 }
342
343 function set(config) {
344 var prop, i;
345 for (i in config) {
346 if (hasOwnProp(config, i)) {
347 prop = config[i];
348 if (isFunction(prop)) {
349 this[i] = prop;
350 } else {
351 this['_' + i] = prop;
352 }
353 }
354 }
355 this._config = config;
356 // Lenient ordinal parsing accepts just a number in addition to
357 // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
358 // TODO: Remove "ordinalParse" fallback in next major release.
359 this._dayOfMonthOrdinalParseLenient = new RegExp(
360 (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
361 '|' +
362 /\d{1,2}/.source
363 );
364 }
365
366 function mergeConfigs(parentConfig, childConfig) {
367 var res = extend({}, parentConfig),
368 prop;
369 for (prop in childConfig) {
370 if (hasOwnProp(childConfig, prop)) {
371 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
372 res[prop] = {};
373 extend(res[prop], parentConfig[prop]);
374 extend(res[prop], childConfig[prop]);
375 } else if (childConfig[prop] != null) {
376 res[prop] = childConfig[prop];
377 } else {
378 delete res[prop];
379 }
380 }
381 }
382 for (prop in parentConfig) {
383 if (
384 hasOwnProp(parentConfig, prop) &&
385 !hasOwnProp(childConfig, prop) &&
386 isObject(parentConfig[prop])
387 ) {
388 // make sure changes to properties don't modify parent config
389 res[prop] = extend({}, res[prop]);
390 }
391 }
392 return res;
393 }
394
395 function Locale(config) {
396 if (config != null) {
397 this.set(config);
398 }
399 }
400
401 var keys;
402
403 if (Object.keys) {
404 keys = Object.keys;
405 } else {
406 keys = function (obj) {
407 var i,
408 res = [];
409 for (i in obj) {
410 if (hasOwnProp(obj, i)) {
411 res.push(i);
412 }
413 }
414 return res;
415 };
416 }
417
418 var defaultCalendar = {
419 sameDay: '[Today at] LT',
420 nextDay: '[Tomorrow at] LT',
421 nextWeek: 'dddd [at] LT',
422 lastDay: '[Yesterday at] LT',
423 lastWeek: '[Last] dddd [at] LT',
424 sameElse: 'L',
425 };
426
427 function calendar(key, mom, now) {
428 var output = this._calendar[key] || this._calendar['sameElse'];
429 return isFunction(output) ? output.call(mom, now) : output;
430 }
431
432 function zeroFill(number, targetLength, forceSign) {
433 var absNumber = '' + Math.abs(number),
434 zerosToFill = targetLength - absNumber.length,
435 sign = number >= 0;
436 return (
437 (sign ? (forceSign ? '+' : '') : '-') +
438 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) +
439 absNumber
440 );
441 }
442
443 var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
444 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
445 formatFunctions = {},
446 formatTokenFunctions = {};
447
448 // token: 'M'
449 // padded: ['MM', 2]
450 // ordinal: 'Mo'
451 // callback: function () { this.month() + 1 }
452 function addFormatToken(token, padded, ordinal, callback) {
453 var func = callback;
454 if (typeof callback === 'string') {
455 func = function () {
456 return this[callback]();
457 };
458 }
459 if (token) {
460 formatTokenFunctions[token] = func;
461 }
462 if (padded) {
463 formatTokenFunctions[padded[0]] = function () {
464 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
465 };
466 }
467 if (ordinal) {
468 formatTokenFunctions[ordinal] = function () {
469 return this.localeData().ordinal(
470 func.apply(this, arguments),
471 token
472 );
473 };
474 }
475 }
476
477 function removeFormattingTokens(input) {
478 if (input.match(/\[[\s\S]/)) {
479 return input.replace(/^\[|\]$/g, '');
480 }
481 return input.replace(/\\/g, '');
482 }
483
484 function makeFormatFunction(format) {
485 var array = format.match(formattingTokens),
486 i,
487 length;
488
489 for (i = 0, length = array.length; i < length; i++) {
490 if (formatTokenFunctions[array[i]]) {
491 array[i] = formatTokenFunctions[array[i]];
492 } else {
493 array[i] = removeFormattingTokens(array[i]);
494 }
495 }
496
497 return function (mom) {
498 var output = '',
499 i;
500 for (i = 0; i < length; i++) {
501 output += isFunction(array[i])
502 ? array[i].call(mom, format)
503 : array[i];
504 }
505 return output;
506 };
507 }
508
509 // format date using native date object
510 function formatMoment(m, format) {
511 if (!m.isValid()) {
512 return m.localeData().invalidDate();
513 }
514
515 format = expandFormat(format, m.localeData());
516 formatFunctions[format] =
517 formatFunctions[format] || makeFormatFunction(format);
518
519 return formatFunctions[format](m);
520 }
521
522 function expandFormat(format, locale) {
523 var i = 5;
524
525 function replaceLongDateFormatTokens(input) {
526 return locale.longDateFormat(input) || input;
527 }
528
529 localFormattingTokens.lastIndex = 0;
530 while (i >= 0 && localFormattingTokens.test(format)) {
531 format = format.replace(
532 localFormattingTokens,
533 replaceLongDateFormatTokens
534 );
535 localFormattingTokens.lastIndex = 0;
536 i -= 1;
537 }
538
539 return format;
540 }
541
542 var defaultLongDateFormat = {
543 LTS: 'h:mm:ss A',
544 LT: 'h:mm A',
545 L: 'MM/DD/YYYY',
546 LL: 'MMMM D, YYYY',
547 LLL: 'MMMM D, YYYY h:mm A',
548 LLLL: 'dddd, MMMM D, YYYY h:mm A',
549 };
550
551 function longDateFormat(key) {
552 var format = this._longDateFormat[key],
553 formatUpper = this._longDateFormat[key.toUpperCase()];
554
555 if (format || !formatUpper) {
556 return format;
557 }
558
559 this._longDateFormat[key] = formatUpper
560 .match(formattingTokens)
561 .map(function (tok) {
562 if (
563 tok === 'MMMM' ||
564 tok === 'MM' ||
565 tok === 'DD' ||
566 tok === 'dddd'
567 ) {
568 return tok.slice(1);
569 }
570 return tok;
571 })
572 .join('');
573
574 return this._longDateFormat[key];
575 }
576
577 var defaultInvalidDate = 'Invalid date';
578
579 function invalidDate() {
580 return this._invalidDate;
581 }
582
583 var defaultOrdinal = '%d',
584 defaultDayOfMonthOrdinalParse = /\d{1,2}/;
585
586 function ordinal(number) {
587 return this._ordinal.replace('%d', number);
588 }
589
590 var defaultRelativeTime = {
591 future: 'in %s',
592 past: '%s ago',
593 s: 'a few seconds',
594 ss: '%d seconds',
595 m: 'a minute',
596 mm: '%d minutes',
597 h: 'an hour',
598 hh: '%d hours',
599 d: 'a day',
600 dd: '%d days',
601 w: 'a week',
602 ww: '%d weeks',
603 M: 'a month',
604 MM: '%d months',
605 y: 'a year',
606 yy: '%d years',
607 };
608
609 function relativeTime(number, withoutSuffix, string, isFuture) {
610 var output = this._relativeTime[string];
611 return isFunction(output)
612 ? output(number, withoutSuffix, string, isFuture)
613 : output.replace(/%d/i, number);
614 }
615
616 function pastFuture(diff, output) {
617 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
618 return isFunction(format) ? format(output) : format.replace(/%s/i, output);
619 }
620
621 var aliases = {};
622
623 function addUnitAlias(unit, shorthand) {
624 var lowerCase = unit.toLowerCase();
625 aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
626 }
627
628 function normalizeUnits(units) {
629 return typeof units === 'string'
630 ? aliases[units] || aliases[units.toLowerCase()]
631 : undefined;
632 }
633
634 function normalizeObjectUnits(inputObject) {
635 var normalizedInput = {},
636 normalizedProp,
637 prop;
638
639 for (prop in inputObject) {
640 if (hasOwnProp(inputObject, prop)) {
641 normalizedProp = normalizeUnits(prop);
642 if (normalizedProp) {
643 normalizedInput[normalizedProp] = inputObject[prop];
644 }
645 }
646 }
647
648 return normalizedInput;
649 }
650
651 var priorities = {};
652
653 function addUnitPriority(unit, priority) {
654 priorities[unit] = priority;
655 }
656
657 function getPrioritizedUnits(unitsObj) {
658 var units = [],
659 u;
660 for (u in unitsObj) {
661 if (hasOwnProp(unitsObj, u)) {
662 units.push({ unit: u, priority: priorities[u] });
663 }
664 }
665 units.sort(function (a, b) {
666 return a.priority - b.priority;
667 });
668 return units;
669 }
670
671 function isLeapYear(year) {
672 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
673 }
674
675 function absFloor(number) {
676 if (number < 0) {
677 // -0 -> 0
678 return Math.ceil(number) || 0;
679 } else {
680 return Math.floor(number);
681 }
682 }
683
684 function toInt(argumentForCoercion) {
685 var coercedNumber = +argumentForCoercion,
686 value = 0;
687
688 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
689 value = absFloor(coercedNumber);
690 }
691
692 return value;
693 }
694
695 function makeGetSet(unit, keepTime) {
696 return function (value) {
697 if (value != null) {
698 set$1(this, unit, value);
699 hooks.updateOffset(this, keepTime);
700 return this;
701 } else {
702 return get(this, unit);
703 }
704 };
705 }
706
707 function get(mom, unit) {
708 return mom.isValid()
709 ? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]()
710 : NaN;
711 }
712
713 function set$1(mom, unit, value) {
714 if (mom.isValid() && !isNaN(value)) {
715 if (
716 unit === 'FullYear' &&
717 isLeapYear(mom.year()) &&
718 mom.month() === 1 &&
719 mom.date() === 29
720 ) {
721 value = toInt(value);
722 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](
723 value,
724 mom.month(),
725 daysInMonth(value, mom.month())
726 );
727 } else {
728 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
729 }
730 }
731 }
732
733 // MOMENTS
734
735 function stringGet(units) {
736 units = normalizeUnits(units);
737 if (isFunction(this[units])) {
738 return this[units]();
739 }
740 return this;
741 }
742
743 function stringSet(units, value) {
744 if (typeof units === 'object') {
745 units = normalizeObjectUnits(units);
746 var prioritized = getPrioritizedUnits(units),
747 i;
748 for (i = 0; i < prioritized.length; i++) {
749 this[prioritized[i].unit](units[prioritized[i].unit]);
750 }
751 } else {
752 units = normalizeUnits(units);
753 if (isFunction(this[units])) {
754 return this[units](value);
755 }
756 }
757 return this;
758 }
759
760 var match1 = /\d/, // 0 - 9
761 match2 = /\d\d/, // 00 - 99
762 match3 = /\d{3}/, // 000 - 999
763 match4 = /\d{4}/, // 0000 - 9999
764 match6 = /[+-]?\d{6}/, // -999999 - 999999
765 match1to2 = /\d\d?/, // 0 - 99
766 match3to4 = /\d\d\d\d?/, // 999 - 9999
767 match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999
768 match1to3 = /\d{1,3}/, // 0 - 999
769 match1to4 = /\d{1,4}/, // 0 - 9999
770 match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
771 matchUnsigned = /\d+/, // 0 - inf
772 matchSigned = /[+-]?\d+/, // -inf - inf
773 matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
774 matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
775 matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
776 // any word (or two) characters or numbers including two/three word month in arabic.
777 // includes scottish gaelic two word and hyphenated months
778 matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
779 regexes;
780
781 regexes = {};
782
783 function addRegexToken(token, regex, strictRegex) {
784 regexes[token] = isFunction(regex)
785 ? regex
786 : function (isStrict, localeData) {
787 return isStrict && strictRegex ? strictRegex : regex;
788 };
789 }
790
791 function getParseRegexForToken(token, config) {
792 if (!hasOwnProp(regexes, token)) {
793 return new RegExp(unescapeFormat(token));
794 }
795
796 return regexes[token](config._strict, config._locale);
797 }
798
799 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
800 function unescapeFormat(s) {
801 return regexEscape(
802 s
803 .replace('\\', '')
804 .replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (
805 matched,
806 p1,
807 p2,
808 p3,
809 p4
810 ) {
811 return p1 || p2 || p3 || p4;
812 })
813 );
814 }
815
816 function regexEscape(s) {
817 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
818 }
819
820 var tokens = {};
821
822 function addParseToken(token, callback) {
823 var i,
824 func = callback;
825 if (typeof token === 'string') {
826 token = [token];
827 }
828 if (isNumber(callback)) {
829 func = function (input, array) {
830 array[callback] = toInt(input);
831 };
832 }
833 for (i = 0; i < token.length; i++) {
834 tokens[token[i]] = func;
835 }
836 }
837
838 function addWeekParseToken(token, callback) {
839 addParseToken(token, function (input, array, config, token) {
840 config._w = config._w || {};
841 callback(input, config._w, config, token);
842 });
843 }
844
845 function addTimeToArrayFromToken(token, input, config) {
846 if (input != null && hasOwnProp(tokens, token)) {
847 tokens[token](input, config._a, config, token);
848 }
849 }
850
851 var YEAR = 0,
852 MONTH = 1,
853 DATE = 2,
854 HOUR = 3,
855 MINUTE = 4,
856 SECOND = 5,
857 MILLISECOND = 6,
858 WEEK = 7,
859 WEEKDAY = 8;
860
861 function mod(n, x) {
862 return ((n % x) + x) % x;
863 }
864
865 var indexOf;
866
867 if (Array.prototype.indexOf) {
868 indexOf = Array.prototype.indexOf;
869 } else {
870 indexOf = function (o) {
871 // I know
872 var i;
873 for (i = 0; i < this.length; ++i) {
874 if (this[i] === o) {
875 return i;
876 }
877 }
878 return -1;
879 };
880 }
881
882 function daysInMonth(year, month) {
883 if (isNaN(year) || isNaN(month)) {
884 return NaN;
885 }
886 var modMonth = mod(month, 12);
887 year += (month - modMonth) / 12;
888 return modMonth === 1
889 ? isLeapYear(year)
890 ? 29
891 : 28
892 : 31 - ((modMonth % 7) % 2);
893 }
894
895 // FORMATTING
896
897 addFormatToken('M', ['MM', 2], 'Mo', function () {
898 return this.month() + 1;
899 });
900
901 addFormatToken('MMM', 0, 0, function (format) {
902 return this.localeData().monthsShort(this, format);
903 });
904
905 addFormatToken('MMMM', 0, 0, function (format) {
906 return this.localeData().months(this, format);
907 });
908
909 // ALIASES
910
911 addUnitAlias('month', 'M');
912
913 // PRIORITY
914
915 addUnitPriority('month', 8);
916
917 // PARSING
918
919 addRegexToken('M', match1to2);
920 addRegexToken('MM', match1to2, match2);
921 addRegexToken('MMM', function (isStrict, locale) {
922 return locale.monthsShortRegex(isStrict);
923 });
924 addRegexToken('MMMM', function (isStrict, locale) {
925 return locale.monthsRegex(isStrict);
926 });
927
928 addParseToken(['M', 'MM'], function (input, array) {
929 array[MONTH] = toInt(input) - 1;
930 });
931
932 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
933 var month = config._locale.monthsParse(input, token, config._strict);
934 // if we didn't find a month name, mark the date as invalid.
935 if (month != null) {
936 array[MONTH] = month;
937 } else {
938 getParsingFlags(config).invalidMonth = input;
939 }
940 });
941
942 // LOCALES
943
944 var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
945 '_'
946 ),
947 defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split(
948 '_'
949 ),
950 MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
951 defaultMonthsShortRegex = matchWord,
952 defaultMonthsRegex = matchWord;
953
954 function localeMonths(m, format) {
955 if (!m) {
956 return isArray(this._months)
957 ? this._months
958 : this._months['standalone'];
959 }
960 return isArray(this._months)
961 ? this._months[m.month()]
962 : this._months[
963 (this._months.isFormat || MONTHS_IN_FORMAT).test(format)
964 ? 'format'
965 : 'standalone'
966 ][m.month()];
967 }
968
969 function localeMonthsShort(m, format) {
970 if (!m) {
971 return isArray(this._monthsShort)
972 ? this._monthsShort
973 : this._monthsShort['standalone'];
974 }
975 return isArray(this._monthsShort)
976 ? this._monthsShort[m.month()]
977 : this._monthsShort[
978 MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'
979 ][m.month()];
980 }
981
982 function handleStrictParse(monthName, format, strict) {
983 var i,
984 ii,
985 mom,
986 llc = monthName.toLocaleLowerCase();
987 if (!this._monthsParse) {
988 // this is not used
989 this._monthsParse = [];
990 this._longMonthsParse = [];
991 this._shortMonthsParse = [];
992 for (i = 0; i < 12; ++i) {
993 mom = createUTC([2000, i]);
994 this._shortMonthsParse[i] = this.monthsShort(
995 mom,
996 ''
997 ).toLocaleLowerCase();
998 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
999 }
1000 }
1001
1002 if (strict) {
1003 if (format === 'MMM') {
1004 ii = indexOf.call(this._shortMonthsParse, llc);
1005 return ii !== -1 ? ii : null;
1006 } else {
1007 ii = indexOf.call(this._longMonthsParse, llc);
1008 return ii !== -1 ? ii : null;
1009 }
1010 } else {
1011 if (format === 'MMM') {
1012 ii = indexOf.call(this._shortMonthsParse, llc);
1013 if (ii !== -1) {
1014 return ii;
1015 }
1016 ii = indexOf.call(this._longMonthsParse, llc);
1017 return ii !== -1 ? ii : null;
1018 } else {
1019 ii = indexOf.call(this._longMonthsParse, llc);
1020 if (ii !== -1) {
1021 return ii;
1022 }
1023 ii = indexOf.call(this._shortMonthsParse, llc);
1024 return ii !== -1 ? ii : null;
1025 }
1026 }
1027 }
1028
1029 function localeMonthsParse(monthName, format, strict) {
1030 var i, mom, regex;
1031
1032 if (this._monthsParseExact) {
1033 return handleStrictParse.call(this, monthName, format, strict);
1034 }
1035
1036 if (!this._monthsParse) {
1037 this._monthsParse = [];
1038 this._longMonthsParse = [];
1039 this._shortMonthsParse = [];
1040 }
1041
1042 // TODO: add sorting
1043 // Sorting makes sure if one month (or abbr) is a prefix of another
1044 // see sorting in computeMonthsParse
1045 for (i = 0; i < 12; i++) {
1046 // make the regex if we don't have it already
1047 mom = createUTC([2000, i]);
1048 if (strict && !this._longMonthsParse[i]) {
1049 this._longMonthsParse[i] = new RegExp(
1050 '^' + this.months(mom, '').replace('.', '') + '$',
1051 'i'
1052 );
1053 this._shortMonthsParse[i] = new RegExp(
1054 '^' + this.monthsShort(mom, '').replace('.', '') + '$',
1055 'i'
1056 );
1057 }
1058 if (!strict && !this._monthsParse[i]) {
1059 regex =
1060 '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
1061 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
1062 }
1063 // test the regex
1064 if (
1065 strict &&
1066 format === 'MMMM' &&
1067 this._longMonthsParse[i].test(monthName)
1068 ) {
1069 return i;
1070 } else if (
1071 strict &&
1072 format === 'MMM' &&
1073 this._shortMonthsParse[i].test(monthName)
1074 ) {
1075 return i;
1076 } else if (!strict && this._monthsParse[i].test(monthName)) {
1077 return i;
1078 }
1079 }
1080 }
1081
1082 // MOMENTS
1083
1084 function setMonth(mom, value) {
1085 var dayOfMonth;
1086
1087 if (!mom.isValid()) {
1088 // No op
1089 return mom;
1090 }
1091
1092 if (typeof value === 'string') {
1093 if (/^\d+$/.test(value)) {
1094 value = toInt(value);
1095 } else {
1096 value = mom.localeData().monthsParse(value);
1097 // TODO: Another silent failure?
1098 if (!isNumber(value)) {
1099 return mom;
1100 }
1101 }
1102 }
1103
1104 dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
1105 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
1106 return mom;
1107 }
1108
1109 function getSetMonth(value) {
1110 if (value != null) {
1111 setMonth(this, value);
1112 hooks.updateOffset(this, true);
1113 return this;
1114 } else {
1115 return get(this, 'Month');
1116 }
1117 }
1118
1119 function getDaysInMonth() {
1120 return daysInMonth(this.year(), this.month());
1121 }
1122
1123 function monthsShortRegex(isStrict) {
1124 if (this._monthsParseExact) {
1125 if (!hasOwnProp(this, '_monthsRegex')) {
1126 computeMonthsParse.call(this);
1127 }
1128 if (isStrict) {
1129 return this._monthsShortStrictRegex;
1130 } else {
1131 return this._monthsShortRegex;
1132 }
1133 } else {
1134 if (!hasOwnProp(this, '_monthsShortRegex')) {
1135 this._monthsShortRegex = defaultMonthsShortRegex;
1136 }
1137 return this._monthsShortStrictRegex && isStrict
1138 ? this._monthsShortStrictRegex
1139 : this._monthsShortRegex;
1140 }
1141 }
1142
1143 function monthsRegex(isStrict) {
1144 if (this._monthsParseExact) {
1145 if (!hasOwnProp(this, '_monthsRegex')) {
1146 computeMonthsParse.call(this);
1147 }
1148 if (isStrict) {
1149 return this._monthsStrictRegex;
1150 } else {
1151 return this._monthsRegex;
1152 }
1153 } else {
1154 if (!hasOwnProp(this, '_monthsRegex')) {
1155 this._monthsRegex = defaultMonthsRegex;
1156 }
1157 return this._monthsStrictRegex && isStrict
1158 ? this._monthsStrictRegex
1159 : this._monthsRegex;
1160 }
1161 }
1162
1163 function computeMonthsParse() {
1164 function cmpLenRev(a, b) {
1165 return b.length - a.length;
1166 }
1167
1168 var shortPieces = [],
1169 longPieces = [],
1170 mixedPieces = [],
1171 i,
1172 mom;
1173 for (i = 0; i < 12; i++) {
1174 // make the regex if we don't have it already
1175 mom = createUTC([2000, i]);
1176 shortPieces.push(this.monthsShort(mom, ''));
1177 longPieces.push(this.months(mom, ''));
1178 mixedPieces.push(this.months(mom, ''));
1179 mixedPieces.push(this.monthsShort(mom, ''));
1180 }
1181 // Sorting makes sure if one month (or abbr) is a prefix of another it
1182 // will match the longer piece.
1183 shortPieces.sort(cmpLenRev);
1184 longPieces.sort(cmpLenRev);
1185 mixedPieces.sort(cmpLenRev);
1186 for (i = 0; i < 12; i++) {
1187 shortPieces[i] = regexEscape(shortPieces[i]);
1188 longPieces[i] = regexEscape(longPieces[i]);
1189 }
1190 for (i = 0; i < 24; i++) {
1191 mixedPieces[i] = regexEscape(mixedPieces[i]);
1192 }
1193
1194 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
1195 this._monthsShortRegex = this._monthsRegex;
1196 this._monthsStrictRegex = new RegExp(
1197 '^(' + longPieces.join('|') + ')',
1198 'i'
1199 );
1200 this._monthsShortStrictRegex = new RegExp(
1201 '^(' + shortPieces.join('|') + ')',
1202 'i'
1203 );
1204 }
1205
1206 // FORMATTING
1207
1208 addFormatToken('Y', 0, 0, function () {
1209 var y = this.year();
1210 return y <= 9999 ? zeroFill(y, 4) : '+' + y;
1211 });
1212
1213 addFormatToken(0, ['YY', 2], 0, function () {
1214 return this.year() % 100;
1215 });
1216
1217 addFormatToken(0, ['YYYY', 4], 0, 'year');
1218 addFormatToken(0, ['YYYYY', 5], 0, 'year');
1219 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
1220
1221 // ALIASES
1222
1223 addUnitAlias('year', 'y');
1224
1225 // PRIORITIES
1226
1227 addUnitPriority('year', 1);
1228
1229 // PARSING
1230
1231 addRegexToken('Y', matchSigned);
1232 addRegexToken('YY', match1to2, match2);
1233 addRegexToken('YYYY', match1to4, match4);
1234 addRegexToken('YYYYY', match1to6, match6);
1235 addRegexToken('YYYYYY', match1to6, match6);
1236
1237 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
1238 addParseToken('YYYY', function (input, array) {
1239 array[YEAR] =
1240 input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
1241 });
1242 addParseToken('YY', function (input, array) {
1243 array[YEAR] = hooks.parseTwoDigitYear(input);
1244 });
1245 addParseToken('Y', function (input, array) {
1246 array[YEAR] = parseInt(input, 10);
1247 });
1248
1249 // HELPERS
1250
1251 function daysInYear(year) {
1252 return isLeapYear(year) ? 366 : 365;
1253 }
1254
1255 // HOOKS
1256
1257 hooks.parseTwoDigitYear = function (input) {
1258 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
1259 };
1260
1261 // MOMENTS
1262
1263 var getSetYear = makeGetSet('FullYear', true);
1264
1265 function getIsLeapYear() {
1266 return isLeapYear(this.year());
1267 }
1268
1269 function createDate(y, m, d, h, M, s, ms) {
1270 // can't just apply() to create a date:
1271 // https://stackoverflow.com/q/181348
1272 var date;
1273 // the date constructor remaps years 0-99 to 1900-1999
1274 if (y < 100 && y >= 0) {
1275 // preserve leap years using a full 400 year cycle, then reset
1276 date = new Date(y + 400, m, d, h, M, s, ms);
1277 if (isFinite(date.getFullYear())) {
1278 date.setFullYear(y);
1279 }
1280 } else {
1281 date = new Date(y, m, d, h, M, s, ms);
1282 }
1283
1284 return date;
1285 }
1286
1287 function createUTCDate(y) {
1288 var date, args;
1289 // the Date.UTC function remaps years 0-99 to 1900-1999
1290 if (y < 100 && y >= 0) {
1291 args = Array.prototype.slice.call(arguments);
1292 // preserve leap years using a full 400 year cycle, then reset
1293 args[0] = y + 400;
1294 date = new Date(Date.UTC.apply(null, args));
1295 if (isFinite(date.getUTCFullYear())) {
1296 date.setUTCFullYear(y);
1297 }
1298 } else {
1299 date = new Date(Date.UTC.apply(null, arguments));
1300 }
1301
1302 return date;
1303 }
1304
1305 // start-of-first-week - start-of-year
1306 function firstWeekOffset(year, dow, doy) {
1307 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1308 fwd = 7 + dow - doy,
1309 // first-week day local weekday -- which local weekday is fwd
1310 fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
1311
1312 return -fwdlw + fwd - 1;
1313 }
1314
1315 // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1316 function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
1317 var localWeekday = (7 + weekday - dow) % 7,
1318 weekOffset = firstWeekOffset(year, dow, doy),
1319 dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
1320 resYear,
1321 resDayOfYear;
1322
1323 if (dayOfYear <= 0) {
1324 resYear = year - 1;
1325 resDayOfYear = daysInYear(resYear) + dayOfYear;
1326 } else if (dayOfYear > daysInYear(year)) {
1327 resYear = year + 1;
1328 resDayOfYear = dayOfYear - daysInYear(year);
1329 } else {
1330 resYear = year;
1331 resDayOfYear = dayOfYear;
1332 }
1333
1334 return {
1335 year: resYear,
1336 dayOfYear: resDayOfYear,
1337 };
1338 }
1339
1340 function weekOfYear(mom, dow, doy) {
1341 var weekOffset = firstWeekOffset(mom.year(), dow, doy),
1342 week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
1343 resWeek,
1344 resYear;
1345
1346 if (week < 1) {
1347 resYear = mom.year() - 1;
1348 resWeek = week + weeksInYear(resYear, dow, doy);
1349 } else if (week > weeksInYear(mom.year(), dow, doy)) {
1350 resWeek = week - weeksInYear(mom.year(), dow, doy);
1351 resYear = mom.year() + 1;
1352 } else {
1353 resYear = mom.year();
1354 resWeek = week;
1355 }
1356
1357 return {
1358 week: resWeek,
1359 year: resYear,
1360 };
1361 }
1362
1363 function weeksInYear(year, dow, doy) {
1364 var weekOffset = firstWeekOffset(year, dow, doy),
1365 weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
1366 return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
1367 }
1368
1369 // FORMATTING
1370
1371 addFormatToken('w', ['ww', 2], 'wo', 'week');
1372 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
1373
1374 // ALIASES
1375
1376 addUnitAlias('week', 'w');
1377 addUnitAlias('isoWeek', 'W');
1378
1379 // PRIORITIES
1380
1381 addUnitPriority('week', 5);
1382 addUnitPriority('isoWeek', 5);
1383
1384 // PARSING
1385
1386 addRegexToken('w', match1to2);
1387 addRegexToken('ww', match1to2, match2);
1388 addRegexToken('W', match1to2);
1389 addRegexToken('WW', match1to2, match2);
1390
1391 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (
1392 input,
1393 week,
1394 config,
1395 token
1396 ) {
1397 week[token.substr(0, 1)] = toInt(input);
1398 });
1399
1400 // HELPERS
1401
1402 // LOCALES
1403
1404 function localeWeek(mom) {
1405 return weekOfYear(mom, this._week.dow, this._week.doy).week;
1406 }
1407
1408 var defaultLocaleWeek = {
1409 dow: 0, // Sunday is the first day of the week.
1410 doy: 6, // The week that contains Jan 6th is the first week of the year.
1411 };
1412
1413 function localeFirstDayOfWeek() {
1414 return this._week.dow;
1415 }
1416
1417 function localeFirstDayOfYear() {
1418 return this._week.doy;
1419 }
1420
1421 // MOMENTS
1422
1423 function getSetWeek(input) {
1424 var week = this.localeData().week(this);
1425 return input == null ? week : this.add((input - week) * 7, 'd');
1426 }
1427
1428 function getSetISOWeek(input) {
1429 var week = weekOfYear(this, 1, 4).week;
1430 return input == null ? week : this.add((input - week) * 7, 'd');
1431 }
1432
1433 // FORMATTING
1434
1435 addFormatToken('d', 0, 'do', 'day');
1436
1437 addFormatToken('dd', 0, 0, function (format) {
1438 return this.localeData().weekdaysMin(this, format);
1439 });
1440
1441 addFormatToken('ddd', 0, 0, function (format) {
1442 return this.localeData().weekdaysShort(this, format);
1443 });
1444
1445 addFormatToken('dddd', 0, 0, function (format) {
1446 return this.localeData().weekdays(this, format);
1447 });
1448
1449 addFormatToken('e', 0, 0, 'weekday');
1450 addFormatToken('E', 0, 0, 'isoWeekday');
1451
1452 // ALIASES
1453
1454 addUnitAlias('day', 'd');
1455 addUnitAlias('weekday', 'e');
1456 addUnitAlias('isoWeekday', 'E');
1457
1458 // PRIORITY
1459 addUnitPriority('day', 11);
1460 addUnitPriority('weekday', 11);
1461 addUnitPriority('isoWeekday', 11);
1462
1463 // PARSING
1464
1465 addRegexToken('d', match1to2);
1466 addRegexToken('e', match1to2);
1467 addRegexToken('E', match1to2);
1468 addRegexToken('dd', function (isStrict, locale) {
1469 return locale.weekdaysMinRegex(isStrict);
1470 });
1471 addRegexToken('ddd', function (isStrict, locale) {
1472 return locale.weekdaysShortRegex(isStrict);
1473 });
1474 addRegexToken('dddd', function (isStrict, locale) {
1475 return locale.weekdaysRegex(isStrict);
1476 });
1477
1478 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
1479 var weekday = config._locale.weekdaysParse(input, token, config._strict);
1480 // if we didn't get a weekday name, mark the date as invalid
1481 if (weekday != null) {
1482 week.d = weekday;
1483 } else {
1484 getParsingFlags(config).invalidWeekday = input;
1485 }
1486 });
1487
1488 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
1489 week[token] = toInt(input);
1490 });
1491
1492 // HELPERS
1493
1494 function parseWeekday(input, locale) {
1495 if (typeof input !== 'string') {
1496 return input;
1497 }
1498
1499 if (!isNaN(input)) {
1500 return parseInt(input, 10);
1501 }
1502
1503 input = locale.weekdaysParse(input);
1504 if (typeof input === 'number') {
1505 return input;
1506 }
1507
1508 return null;
1509 }
1510
1511 function parseIsoWeekday(input, locale) {
1512 if (typeof input === 'string') {
1513 return locale.weekdaysParse(input) % 7 || 7;
1514 }
1515 return isNaN(input) ? null : input;
1516 }
1517
1518 // LOCALES
1519 function shiftWeekdays(ws, n) {
1520 return ws.slice(n, 7).concat(ws.slice(0, n));
1521 }
1522
1523 var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split(
1524 '_'
1525 ),
1526 defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
1527 defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
1528 defaultWeekdaysRegex = matchWord,
1529 defaultWeekdaysShortRegex = matchWord,
1530 defaultWeekdaysMinRegex = matchWord;
1531
1532 function localeWeekdays(m, format) {
1533 var weekdays = isArray(this._weekdays)
1534 ? this._weekdays
1535 : this._weekdays[
1536 m && m !== true && this._weekdays.isFormat.test(format)
1537 ? 'format'
1538 : 'standalone'
1539 ];
1540 return m === true
1541 ? shiftWeekdays(weekdays, this._week.dow)
1542 : m
1543 ? weekdays[m.day()]
1544 : weekdays;
1545 }
1546
1547 function localeWeekdaysShort(m) {
1548 return m === true
1549 ? shiftWeekdays(this._weekdaysShort, this._week.dow)
1550 : m
1551 ? this._weekdaysShort[m.day()]
1552 : this._weekdaysShort;
1553 }
1554
1555 function localeWeekdaysMin(m) {
1556 return m === true
1557 ? shiftWeekdays(this._weekdaysMin, this._week.dow)
1558 : m
1559 ? this._weekdaysMin[m.day()]
1560 : this._weekdaysMin;
1561 }
1562
1563 function handleStrictParse$1(weekdayName, format, strict) {
1564 var i,
1565 ii,
1566 mom,
1567 llc = weekdayName.toLocaleLowerCase();
1568 if (!this._weekdaysParse) {
1569 this._weekdaysParse = [];
1570 this._shortWeekdaysParse = [];
1571 this._minWeekdaysParse = [];
1572
1573 for (i = 0; i < 7; ++i) {
1574 mom = createUTC([2000, 1]).day(i);
1575 this._minWeekdaysParse[i] = this.weekdaysMin(
1576 mom,
1577 ''
1578 ).toLocaleLowerCase();
1579 this._shortWeekdaysParse[i] = this.weekdaysShort(
1580 mom,
1581 ''
1582 ).toLocaleLowerCase();
1583 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
1584 }
1585 }
1586
1587 if (strict) {
1588 if (format === 'dddd') {
1589 ii = indexOf.call(this._weekdaysParse, llc);
1590 return ii !== -1 ? ii : null;
1591 } else if (format === 'ddd') {
1592 ii = indexOf.call(this._shortWeekdaysParse, llc);
1593 return ii !== -1 ? ii : null;
1594 } else {
1595 ii = indexOf.call(this._minWeekdaysParse, llc);
1596 return ii !== -1 ? ii : null;
1597 }
1598 } else {
1599 if (format === 'dddd') {
1600 ii = indexOf.call(this._weekdaysParse, llc);
1601 if (ii !== -1) {
1602 return ii;
1603 }
1604 ii = indexOf.call(this._shortWeekdaysParse, llc);
1605 if (ii !== -1) {
1606 return ii;
1607 }
1608 ii = indexOf.call(this._minWeekdaysParse, llc);
1609 return ii !== -1 ? ii : null;
1610 } else if (format === 'ddd') {
1611 ii = indexOf.call(this._shortWeekdaysParse, llc);
1612 if (ii !== -1) {
1613 return ii;
1614 }
1615 ii = indexOf.call(this._weekdaysParse, llc);
1616 if (ii !== -1) {
1617 return ii;
1618 }
1619 ii = indexOf.call(this._minWeekdaysParse, llc);
1620 return ii !== -1 ? ii : null;
1621 } else {
1622 ii = indexOf.call(this._minWeekdaysParse, llc);
1623 if (ii !== -1) {
1624 return ii;
1625 }
1626 ii = indexOf.call(this._weekdaysParse, llc);
1627 if (ii !== -1) {
1628 return ii;
1629 }
1630 ii = indexOf.call(this._shortWeekdaysParse, llc);
1631 return ii !== -1 ? ii : null;
1632 }
1633 }
1634 }
1635
1636 function localeWeekdaysParse(weekdayName, format, strict) {
1637 var i, mom, regex;
1638
1639 if (this._weekdaysParseExact) {
1640 return handleStrictParse$1.call(this, weekdayName, format, strict);
1641 }
1642
1643 if (!this._weekdaysParse) {
1644 this._weekdaysParse = [];
1645 this._minWeekdaysParse = [];
1646 this._shortWeekdaysParse = [];
1647 this._fullWeekdaysParse = [];
1648 }
1649
1650 for (i = 0; i < 7; i++) {
1651 // make the regex if we don't have it already
1652
1653 mom = createUTC([2000, 1]).day(i);
1654 if (strict && !this._fullWeekdaysParse[i]) {
1655 this._fullWeekdaysParse[i] = new RegExp(
1656 '^' + this.weekdays(mom, '').replace('.', '\\.?') + '$',
1657 'i'
1658 );
1659 this._shortWeekdaysParse[i] = new RegExp(
1660 '^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$',
1661 'i'
1662 );
1663 this._minWeekdaysParse[i] = new RegExp(
1664 '^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$',
1665 'i'
1666 );
1667 }
1668 if (!this._weekdaysParse[i]) {
1669 regex =
1670 '^' +
1671 this.weekdays(mom, '') +
1672 '|^' +
1673 this.weekdaysShort(mom, '') +
1674 '|^' +
1675 this.weekdaysMin(mom, '');
1676 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
1677 }
1678 // test the regex
1679 if (
1680 strict &&
1681 format === 'dddd' &&
1682 this._fullWeekdaysParse[i].test(weekdayName)
1683 ) {
1684 return i;
1685 } else if (
1686 strict &&
1687 format === 'ddd' &&
1688 this._shortWeekdaysParse[i].test(weekdayName)
1689 ) {
1690 return i;
1691 } else if (
1692 strict &&
1693 format === 'dd' &&
1694 this._minWeekdaysParse[i].test(weekdayName)
1695 ) {
1696 return i;
1697 } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
1698 return i;
1699 }
1700 }
1701 }
1702
1703 // MOMENTS
1704
1705 function getSetDayOfWeek(input) {
1706 if (!this.isValid()) {
1707 return input != null ? this : NaN;
1708 }
1709 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
1710 if (input != null) {
1711 input = parseWeekday(input, this.localeData());
1712 return this.add(input - day, 'd');
1713 } else {
1714 return day;
1715 }
1716 }
1717
1718 function getSetLocaleDayOfWeek(input) {
1719 if (!this.isValid()) {
1720 return input != null ? this : NaN;
1721 }
1722 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
1723 return input == null ? weekday : this.add(input - weekday, 'd');
1724 }
1725
1726 function getSetISODayOfWeek(input) {
1727 if (!this.isValid()) {
1728 return input != null ? this : NaN;
1729 }
1730
1731 // behaves the same as moment#day except
1732 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
1733 // as a setter, sunday should belong to the previous week.
1734
1735 if (input != null) {
1736 var weekday = parseIsoWeekday(input, this.localeData());
1737 return this.day(this.day() % 7 ? weekday : weekday - 7);
1738 } else {
1739 return this.day() || 7;
1740 }
1741 }
1742
1743 function weekdaysRegex(isStrict) {
1744 if (this._weekdaysParseExact) {
1745 if (!hasOwnProp(this, '_weekdaysRegex')) {
1746 computeWeekdaysParse.call(this);
1747 }
1748 if (isStrict) {
1749 return this._weekdaysStrictRegex;
1750 } else {
1751 return this._weekdaysRegex;
1752 }
1753 } else {
1754 if (!hasOwnProp(this, '_weekdaysRegex')) {
1755 this._weekdaysRegex = defaultWeekdaysRegex;
1756 }
1757 return this._weekdaysStrictRegex && isStrict
1758 ? this._weekdaysStrictRegex
1759 : this._weekdaysRegex;
1760 }
1761 }
1762
1763 function weekdaysShortRegex(isStrict) {
1764 if (this._weekdaysParseExact) {
1765 if (!hasOwnProp(this, '_weekdaysRegex')) {
1766 computeWeekdaysParse.call(this);
1767 }
1768 if (isStrict) {
1769 return this._weekdaysShortStrictRegex;
1770 } else {
1771 return this._weekdaysShortRegex;
1772 }
1773 } else {
1774 if (!hasOwnProp(this, '_weekdaysShortRegex')) {
1775 this._weekdaysShortRegex = defaultWeekdaysShortRegex;
1776 }
1777 return this._weekdaysShortStrictRegex && isStrict
1778 ? this._weekdaysShortStrictRegex
1779 : this._weekdaysShortRegex;
1780 }
1781 }
1782
1783 function weekdaysMinRegex(isStrict) {
1784 if (this._weekdaysParseExact) {
1785 if (!hasOwnProp(this, '_weekdaysRegex')) {
1786 computeWeekdaysParse.call(this);
1787 }
1788 if (isStrict) {
1789 return this._weekdaysMinStrictRegex;
1790 } else {
1791 return this._weekdaysMinRegex;
1792 }
1793 } else {
1794 if (!hasOwnProp(this, '_weekdaysMinRegex')) {
1795 this._weekdaysMinRegex = defaultWeekdaysMinRegex;
1796 }
1797 return this._weekdaysMinStrictRegex && isStrict
1798 ? this._weekdaysMinStrictRegex
1799 : this._weekdaysMinRegex;
1800 }
1801 }
1802
1803 function computeWeekdaysParse() {
1804 function cmpLenRev(a, b) {
1805 return b.length - a.length;
1806 }
1807
1808 var minPieces = [],
1809 shortPieces = [],
1810 longPieces = [],
1811 mixedPieces = [],
1812 i,
1813 mom,
1814 minp,
1815 shortp,
1816 longp;
1817 for (i = 0; i < 7; i++) {
1818 // make the regex if we don't have it already
1819 mom = createUTC([2000, 1]).day(i);
1820 minp = regexEscape(this.weekdaysMin(mom, ''));
1821 shortp = regexEscape(this.weekdaysShort(mom, ''));
1822 longp = regexEscape(this.weekdays(mom, ''));
1823 minPieces.push(minp);
1824 shortPieces.push(shortp);
1825 longPieces.push(longp);
1826 mixedPieces.push(minp);
1827 mixedPieces.push(shortp);
1828 mixedPieces.push(longp);
1829 }
1830 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
1831 // will match the longer piece.
1832 minPieces.sort(cmpLenRev);
1833 shortPieces.sort(cmpLenRev);
1834 longPieces.sort(cmpLenRev);
1835 mixedPieces.sort(cmpLenRev);
1836
1837 this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
1838 this._weekdaysShortRegex = this._weekdaysRegex;
1839 this._weekdaysMinRegex = this._weekdaysRegex;
1840
1841 this._weekdaysStrictRegex = new RegExp(
1842 '^(' + longPieces.join('|') + ')',
1843 'i'
1844 );
1845 this._weekdaysShortStrictRegex = new RegExp(
1846 '^(' + shortPieces.join('|') + ')',
1847 'i'
1848 );
1849 this._weekdaysMinStrictRegex = new RegExp(
1850 '^(' + minPieces.join('|') + ')',
1851 'i'
1852 );
1853 }
1854
1855 // FORMATTING
1856
1857 function hFormat() {
1858 return this.hours() % 12 || 12;
1859 }
1860
1861 function kFormat() {
1862 return this.hours() || 24;
1863 }
1864
1865 addFormatToken('H', ['HH', 2], 0, 'hour');
1866 addFormatToken('h', ['hh', 2], 0, hFormat);
1867 addFormatToken('k', ['kk', 2], 0, kFormat);
1868
1869 addFormatToken('hmm', 0, 0, function () {
1870 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
1871 });
1872
1873 addFormatToken('hmmss', 0, 0, function () {
1874 return (
1875 '' +
1876 hFormat.apply(this) +
1877 zeroFill(this.minutes(), 2) +
1878 zeroFill(this.seconds(), 2)
1879 );
1880 });
1881
1882 addFormatToken('Hmm', 0, 0, function () {
1883 return '' + this.hours() + zeroFill(this.minutes(), 2);
1884 });
1885
1886 addFormatToken('Hmmss', 0, 0, function () {
1887 return (
1888 '' +
1889 this.hours() +
1890 zeroFill(this.minutes(), 2) +
1891 zeroFill(this.seconds(), 2)
1892 );
1893 });
1894
1895 function meridiem(token, lowercase) {
1896 addFormatToken(token, 0, 0, function () {
1897 return this.localeData().meridiem(
1898 this.hours(),
1899 this.minutes(),
1900 lowercase
1901 );
1902 });
1903 }
1904
1905 meridiem('a', true);
1906 meridiem('A', false);
1907
1908 // ALIASES
1909
1910 addUnitAlias('hour', 'h');
1911
1912 // PRIORITY
1913 addUnitPriority('hour', 13);
1914
1915 // PARSING
1916
1917 function matchMeridiem(isStrict, locale) {
1918 return locale._meridiemParse;
1919 }
1920
1921 addRegexToken('a', matchMeridiem);
1922 addRegexToken('A', matchMeridiem);
1923 addRegexToken('H', match1to2);
1924 addRegexToken('h', match1to2);
1925 addRegexToken('k', match1to2);
1926 addRegexToken('HH', match1to2, match2);
1927 addRegexToken('hh', match1to2, match2);
1928 addRegexToken('kk', match1to2, match2);
1929
1930 addRegexToken('hmm', match3to4);
1931 addRegexToken('hmmss', match5to6);
1932 addRegexToken('Hmm', match3to4);
1933 addRegexToken('Hmmss', match5to6);
1934
1935 addParseToken(['H', 'HH'], HOUR);
1936 addParseToken(['k', 'kk'], function (input, array, config) {
1937 var kInput = toInt(input);
1938 array[HOUR] = kInput === 24 ? 0 : kInput;
1939 });
1940 addParseToken(['a', 'A'], function (input, array, config) {
1941 config._isPm = config._locale.isPM(input);
1942 config._meridiem = input;
1943 });
1944 addParseToken(['h', 'hh'], function (input, array, config) {
1945 array[HOUR] = toInt(input);
1946 getParsingFlags(config).bigHour = true;
1947 });
1948 addParseToken('hmm', function (input, array, config) {
1949 var pos = input.length - 2;
1950 array[HOUR] = toInt(input.substr(0, pos));
1951 array[MINUTE] = toInt(input.substr(pos));
1952 getParsingFlags(config).bigHour = true;
1953 });
1954 addParseToken('hmmss', function (input, array, config) {
1955 var pos1 = input.length - 4,
1956 pos2 = input.length - 2;
1957 array[HOUR] = toInt(input.substr(0, pos1));
1958 array[MINUTE] = toInt(input.substr(pos1, 2));
1959 array[SECOND] = toInt(input.substr(pos2));
1960 getParsingFlags(config).bigHour = true;
1961 });
1962 addParseToken('Hmm', function (input, array, config) {
1963 var pos = input.length - 2;
1964 array[HOUR] = toInt(input.substr(0, pos));
1965 array[MINUTE] = toInt(input.substr(pos));
1966 });
1967 addParseToken('Hmmss', function (input, array, config) {
1968 var pos1 = input.length - 4,
1969 pos2 = input.length - 2;
1970 array[HOUR] = toInt(input.substr(0, pos1));
1971 array[MINUTE] = toInt(input.substr(pos1, 2));
1972 array[SECOND] = toInt(input.substr(pos2));
1973 });
1974
1975 // LOCALES
1976
1977 function localeIsPM(input) {
1978 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
1979 // Using charAt should be more compatible.
1980 return (input + '').toLowerCase().charAt(0) === 'p';
1981 }
1982
1983 var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
1984 // Setting the hour should keep the time, because the user explicitly
1985 // specified which hour they want. So trying to maintain the same hour (in
1986 // a new timezone) makes sense. Adding/subtracting hours does not follow
1987 // this rule.
1988 getSetHour = makeGetSet('Hours', true);
1989
1990 function localeMeridiem(hours, minutes, isLower) {
1991 if (hours > 11) {
1992 return isLower ? 'pm' : 'PM';
1993 } else {
1994 return isLower ? 'am' : 'AM';
1995 }
1996 }
1997
1998 var baseConfig = {
1999 calendar: defaultCalendar,
2000 longDateFormat: defaultLongDateFormat,
2001 invalidDate: defaultInvalidDate,
2002 ordinal: defaultOrdinal,
2003 dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
2004 relativeTime: defaultRelativeTime,
2005
2006 months: defaultLocaleMonths,
2007 monthsShort: defaultLocaleMonthsShort,
2008
2009 week: defaultLocaleWeek,
2010
2011 weekdays: defaultLocaleWeekdays,
2012 weekdaysMin: defaultLocaleWeekdaysMin,
2013 weekdaysShort: defaultLocaleWeekdaysShort,
2014
2015 meridiemParse: defaultLocaleMeridiemParse,
2016 };
2017
2018 // internal storage for locale config files
2019 var locales = {},
2020 localeFamilies = {},
2021 globalLocale;
2022
2023 function commonPrefix(arr1, arr2) {
2024 var i,
2025 minl = Math.min(arr1.length, arr2.length);
2026 for (i = 0; i < minl; i += 1) {
2027 if (arr1[i] !== arr2[i]) {
2028 return i;
2029 }
2030 }
2031 return minl;
2032 }
2033
2034 function normalizeLocale(key) {
2035 return key ? key.toLowerCase().replace('_', '-') : key;
2036 }
2037
2038 // pick the locale from the array
2039 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
2040 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
2041 function chooseLocale(names) {
2042 var i = 0,
2043 j,
2044 next,
2045 locale,
2046 split;
2047
2048 while (i < names.length) {
2049 split = normalizeLocale(names[i]).split('-');
2050 j = split.length;
2051 next = normalizeLocale(names[i + 1]);
2052 next = next ? next.split('-') : null;
2053 while (j > 0) {
2054 locale = loadLocale(split.slice(0, j).join('-'));
2055 if (locale) {
2056 return locale;
2057 }
2058 if (
2059 next &&
2060 next.length >= j &&
2061 commonPrefix(split, next) >= j - 1
2062 ) {
2063 //the next array item is better than a shallower substring of this one
2064 break;
2065 }
2066 j--;
2067 }
2068 i++;
2069 }
2070 return globalLocale;
2071 }
2072
2073 function loadLocale(name) {
2074 var oldLocale = null,
2075 aliasedRequire;
2076 // TODO: Find a better way to register and load all the locales in Node
2077 if (
2078 locales[name] === undefined &&
2079 typeof module !== 'undefined' &&
2080 module &&
2081 module.exports
2082 ) {
2083 try {
2084 oldLocale = globalLocale._abbr;
2085 aliasedRequire = require;
2086 aliasedRequire('./locale/' + name);
2087 getSetGlobalLocale(oldLocale);
2088 } catch (e) {
2089 // mark as not found to avoid repeating expensive file require call causing high CPU
2090 // when trying to find en-US, en_US, en-us for every format call
2091 locales[name] = null; // null means not found
2092 }
2093 }
2094 return locales[name];
2095 }
2096
2097 // This function will load locale and then set the global locale. If
2098 // no arguments are passed in, it will simply return the current global
2099 // locale key.
2100 function getSetGlobalLocale(key, values) {
2101 var data;
2102 if (key) {
2103 if (isUndefined(values)) {
2104 data = getLocale(key);
2105 } else {
2106 data = defineLocale(key, values);
2107 }
2108
2109 if (data) {
2110 // moment.duration._locale = moment._locale = data;
2111 globalLocale = data;
2112 } else {
2113 if (typeof console !== 'undefined' && console.warn) {
2114 //warn user if arguments are passed but the locale could not be set
2115 console.warn(
2116 'Locale ' + key + ' not found. Did you forget to load it?'
2117 );
2118 }
2119 }
2120 }
2121
2122 return globalLocale._abbr;
2123 }
2124
2125 function defineLocale(name, config) {
2126 if (config !== null) {
2127 var locale,
2128 parentConfig = baseConfig;
2129 config.abbr = name;
2130 if (locales[name] != null) {
2131 deprecateSimple(
2132 'defineLocaleOverride',
2133 'use moment.updateLocale(localeName, config) to change ' +
2134 'an existing locale. moment.defineLocale(localeName, ' +
2135 'config) should only be used for creating a new locale ' +
2136 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'
2137 );
2138 parentConfig = locales[name]._config;
2139 } else if (config.parentLocale != null) {
2140 if (locales[config.parentLocale] != null) {
2141 parentConfig = locales[config.parentLocale]._config;
2142 } else {
2143 locale = loadLocale(config.parentLocale);
2144 if (locale != null) {
2145 parentConfig = locale._config;
2146 } else {
2147 if (!localeFamilies[config.parentLocale]) {
2148 localeFamilies[config.parentLocale] = [];
2149 }
2150 localeFamilies[config.parentLocale].push({
2151 name: name,
2152 config: config,
2153 });
2154 return null;
2155 }
2156 }
2157 }
2158 locales[name] = new Locale(mergeConfigs(parentConfig, config));
2159
2160 if (localeFamilies[name]) {
2161 localeFamilies[name].forEach(function (x) {
2162 defineLocale(x.name, x.config);
2163 });
2164 }
2165
2166 // backwards compat for now: also set the locale
2167 // make sure we set the locale AFTER all child locales have been
2168 // created, so we won't end up with the child locale set.
2169 getSetGlobalLocale(name);
2170
2171 return locales[name];
2172 } else {
2173 // useful for testing
2174 delete locales[name];
2175 return null;
2176 }
2177 }
2178
2179 function updateLocale(name, config) {
2180 if (config != null) {
2181 var locale,
2182 tmpLocale,
2183 parentConfig = baseConfig;
2184
2185 if (locales[name] != null && locales[name].parentLocale != null) {
2186 // Update existing child locale in-place to avoid memory-leaks
2187 locales[name].set(mergeConfigs(locales[name]._config, config));
2188 } else {
2189 // MERGE
2190 tmpLocale = loadLocale(name);
2191 if (tmpLocale != null) {
2192 parentConfig = tmpLocale._config;
2193 }
2194 config = mergeConfigs(parentConfig, config);
2195 if (tmpLocale == null) {
2196 // updateLocale is called for creating a new locale
2197 // Set abbr so it will have a name (getters return
2198 // undefined otherwise).
2199 config.abbr = name;
2200 }
2201 locale = new Locale(config);
2202 locale.parentLocale = locales[name];
2203 locales[name] = locale;
2204 }
2205
2206 // backwards compat for now: also set the locale
2207 getSetGlobalLocale(name);
2208 } else {
2209 // pass null for config to unupdate, useful for tests
2210 if (locales[name] != null) {
2211 if (locales[name].parentLocale != null) {
2212 locales[name] = locales[name].parentLocale;
2213 if (name === getSetGlobalLocale()) {
2214 getSetGlobalLocale(name);
2215 }
2216 } else if (locales[name] != null) {
2217 delete locales[name];
2218 }
2219 }
2220 }
2221 return locales[name];
2222 }
2223
2224 // returns locale data
2225 function getLocale(key) {
2226 var locale;
2227
2228 if (key && key._locale && key._locale._abbr) {
2229 key = key._locale._abbr;
2230 }
2231
2232 if (!key) {
2233 return globalLocale;
2234 }
2235
2236 if (!isArray(key)) {
2237 //short-circuit everything else
2238 locale = loadLocale(key);
2239 if (locale) {
2240 return locale;
2241 }
2242 key = [key];
2243 }
2244
2245 return chooseLocale(key);
2246 }
2247
2248 function listLocales() {
2249 return keys(locales);
2250 }
2251
2252 function checkOverflow(m) {
2253 var overflow,
2254 a = m._a;
2255
2256 if (a && getParsingFlags(m).overflow === -2) {
2257 overflow =
2258 a[MONTH] < 0 || a[MONTH] > 11
2259 ? MONTH
2260 : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
2261 ? DATE
2262 : a[HOUR] < 0 ||
2263 a[HOUR] > 24 ||
2264 (a[HOUR] === 24 &&
2265 (a[MINUTE] !== 0 ||
2266 a[SECOND] !== 0 ||
2267 a[MILLISECOND] !== 0))
2268 ? HOUR
2269 : a[MINUTE] < 0 || a[MINUTE] > 59
2270 ? MINUTE
2271 : a[SECOND] < 0 || a[SECOND] > 59
2272 ? SECOND
2273 : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
2274 ? MILLISECOND
2275 : -1;
2276
2277 if (
2278 getParsingFlags(m)._overflowDayOfYear &&
2279 (overflow < YEAR || overflow > DATE)
2280 ) {
2281 overflow = DATE;
2282 }
2283 if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
2284 overflow = WEEK;
2285 }
2286 if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
2287 overflow = WEEKDAY;
2288 }
2289
2290 getParsingFlags(m).overflow = overflow;
2291 }
2292
2293 return m;
2294 }
2295
2296 // iso 8601 regex
2297 // 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)
2298 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)?)?$/,
2299 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)?)?$/,
2300 tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
2301 isoDates = [
2302 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
2303 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
2304 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
2305 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
2306 ['YYYY-DDD', /\d{4}-\d{3}/],
2307 ['YYYY-MM', /\d{4}-\d\d/, false],
2308 ['YYYYYYMMDD', /[+-]\d{10}/],
2309 ['YYYYMMDD', /\d{8}/],
2310 ['GGGG[W]WWE', /\d{4}W\d{3}/],
2311 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
2312 ['YYYYDDD', /\d{7}/],
2313 ['YYYYMM', /\d{6}/, false],
2314 ['YYYY', /\d{4}/, false],
2315 ],
2316 // iso time formats and regexes
2317 isoTimes = [
2318 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
2319 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
2320 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
2321 ['HH:mm', /\d\d:\d\d/],
2322 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
2323 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
2324 ['HHmmss', /\d\d\d\d\d\d/],
2325 ['HHmm', /\d\d\d\d/],
2326 ['HH', /\d\d/],
2327 ],
2328 aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
2329 // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
2330 rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
2331 obsOffsets = {
2332 UT: 0,
2333 GMT: 0,
2334 EDT: -4 * 60,
2335 EST: -5 * 60,
2336 CDT: -5 * 60,
2337 CST: -6 * 60,
2338 MDT: -6 * 60,
2339 MST: -7 * 60,
2340 PDT: -7 * 60,
2341 PST: -8 * 60,
2342 };
2343
2344 // date from iso format
2345 function configFromISO(config) {
2346 var i,
2347 l,
2348 string = config._i,
2349 match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
2350 allowTime,
2351 dateFormat,
2352 timeFormat,
2353 tzFormat;
2354
2355 if (match) {
2356 getParsingFlags(config).iso = true;
2357
2358 for (i = 0, l = isoDates.length; i < l; i++) {
2359 if (isoDates[i][1].exec(match[1])) {
2360 dateFormat = isoDates[i][0];
2361 allowTime = isoDates[i][2] !== false;
2362 break;
2363 }
2364 }
2365 if (dateFormat == null) {
2366 config._isValid = false;
2367 return;
2368 }
2369 if (match[3]) {
2370 for (i = 0, l = isoTimes.length; i < l; i++) {
2371 if (isoTimes[i][1].exec(match[3])) {
2372 // match[2] should be 'T' or space
2373 timeFormat = (match[2] || ' ') + isoTimes[i][0];
2374 break;
2375 }
2376 }
2377 if (timeFormat == null) {
2378 config._isValid = false;
2379 return;
2380 }
2381 }
2382 if (!allowTime && timeFormat != null) {
2383 config._isValid = false;
2384 return;
2385 }
2386 if (match[4]) {
2387 if (tzRegex.exec(match[4])) {
2388 tzFormat = 'Z';
2389 } else {
2390 config._isValid = false;
2391 return;
2392 }
2393 }
2394 config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
2395 configFromStringAndFormat(config);
2396 } else {
2397 config._isValid = false;
2398 }
2399 }
2400
2401 function extractFromRFC2822Strings(
2402 yearStr,
2403 monthStr,
2404 dayStr,
2405 hourStr,
2406 minuteStr,
2407 secondStr
2408 ) {
2409 var result = [
2410 untruncateYear(yearStr),
2411 defaultLocaleMonthsShort.indexOf(monthStr),
2412 parseInt(dayStr, 10),
2413 parseInt(hourStr, 10),
2414 parseInt(minuteStr, 10),
2415 ];
2416
2417 if (secondStr) {
2418 result.push(parseInt(secondStr, 10));
2419 }
2420
2421 return result;
2422 }
2423
2424 function untruncateYear(yearStr) {
2425 var year = parseInt(yearStr, 10);
2426 if (year <= 49) {
2427 return 2000 + year;
2428 } else if (year <= 999) {
2429 return 1900 + year;
2430 }
2431 return year;
2432 }
2433
2434 function preprocessRFC2822(s) {
2435 // Remove comments and folding whitespace and replace multiple-spaces with a single space
2436 return s
2437 .replace(/\([^)]*\)|[\n\t]/g, ' ')
2438 .replace(/(\s\s+)/g, ' ')
2439 .replace(/^\s\s*/, '')
2440 .replace(/\s\s*$/, '');
2441 }
2442
2443 function checkWeekday(weekdayStr, parsedInput, config) {
2444 if (weekdayStr) {
2445 // TODO: Replace the vanilla JS Date object with an independent day-of-week check.
2446 var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
2447 weekdayActual = new Date(
2448 parsedInput[0],
2449 parsedInput[1],
2450 parsedInput[2]
2451 ).getDay();
2452 if (weekdayProvided !== weekdayActual) {
2453 getParsingFlags(config).weekdayMismatch = true;
2454 config._isValid = false;
2455 return false;
2456 }
2457 }
2458 return true;
2459 }
2460
2461 function calculateOffset(obsOffset, militaryOffset, numOffset) {
2462 if (obsOffset) {
2463 return obsOffsets[obsOffset];
2464 } else if (militaryOffset) {
2465 // the only allowed military tz is Z
2466 return 0;
2467 } else {
2468 var hm = parseInt(numOffset, 10),
2469 m = hm % 100,
2470 h = (hm - m) / 100;
2471 return h * 60 + m;
2472 }
2473 }
2474
2475 // date and time from ref 2822 format
2476 function configFromRFC2822(config) {
2477 var match = rfc2822.exec(preprocessRFC2822(config._i)),
2478 parsedArray;
2479 if (match) {
2480 parsedArray = extractFromRFC2822Strings(
2481 match[4],
2482 match[3],
2483 match[2],
2484 match[5],
2485 match[6],
2486 match[7]
2487 );
2488 if (!checkWeekday(match[1], parsedArray, config)) {
2489 return;
2490 }
2491
2492 config._a = parsedArray;
2493 config._tzm = calculateOffset(match[8], match[9], match[10]);
2494
2495 config._d = createUTCDate.apply(null, config._a);
2496 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
2497
2498 getParsingFlags(config).rfc2822 = true;
2499 } else {
2500 config._isValid = false;
2501 }
2502 }
2503
2504 // date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict
2505 function configFromString(config) {
2506 var matched = aspNetJsonRegex.exec(config._i);
2507 if (matched !== null) {
2508 config._d = new Date(+matched[1]);
2509 return;
2510 }
2511
2512 configFromISO(config);
2513 if (config._isValid === false) {
2514 delete config._isValid;
2515 } else {
2516 return;
2517 }
2518
2519 configFromRFC2822(config);
2520 if (config._isValid === false) {
2521 delete config._isValid;
2522 } else {
2523 return;
2524 }
2525
2526 if (config._strict) {
2527 config._isValid = false;
2528 } else {
2529 // Final attempt, use Input Fallback
2530 hooks.createFromInputFallback(config);
2531 }
2532 }
2533
2534 hooks.createFromInputFallback = deprecate(
2535 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
2536 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
2537 'discouraged and will be removed in an upcoming major release. Please refer to ' +
2538 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
2539 function (config) {
2540 config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
2541 }
2542 );
2543
2544 // Pick the first defined of two or three arguments.
2545 function defaults(a, b, c) {
2546 if (a != null) {
2547 return a;
2548 }
2549 if (b != null) {
2550 return b;
2551 }
2552 return c;
2553 }
2554
2555 function currentDateArray(config) {
2556 // hooks is actually the exported moment object
2557 var nowValue = new Date(hooks.now());
2558 if (config._useUTC) {
2559 return [
2560 nowValue.getUTCFullYear(),
2561 nowValue.getUTCMonth(),
2562 nowValue.getUTCDate(),
2563 ];
2564 }
2565 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
2566 }
2567
2568 // convert an array to a date.
2569 // the array should mirror the parameters below
2570 // note: all values past the year are optional and will default to the lowest possible value.
2571 // [year, month, day , hour, minute, second, millisecond]
2572 function configFromArray(config) {
2573 var i,
2574 date,
2575 input = [],
2576 currentDate,
2577 expectedWeekday,
2578 yearToUse;
2579
2580 if (config._d) {
2581 return;
2582 }
2583
2584 currentDate = currentDateArray(config);
2585
2586 //compute day of the year from weeks and weekdays
2587 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
2588 dayOfYearFromWeekInfo(config);
2589 }
2590
2591 //if the day of the year is set, figure out what it is
2592 if (config._dayOfYear != null) {
2593 yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
2594
2595 if (
2596 config._dayOfYear > daysInYear(yearToUse) ||
2597 config._dayOfYear === 0
2598 ) {
2599 getParsingFlags(config)._overflowDayOfYear = true;
2600 }
2601
2602 date = createUTCDate(yearToUse, 0, config._dayOfYear);
2603 config._a[MONTH] = date.getUTCMonth();
2604 config._a[DATE] = date.getUTCDate();
2605 }
2606
2607 // Default to current date.
2608 // * if no year, month, day of month are given, default to today
2609 // * if day of month is given, default month and year
2610 // * if month is given, default only year
2611 // * if year is given, don't default anything
2612 for (i = 0; i < 3 && config._a[i] == null; ++i) {
2613 config._a[i] = input[i] = currentDate[i];
2614 }
2615
2616 // Zero out whatever was not defaulted, including time
2617 for (; i < 7; i++) {
2618 config._a[i] = input[i] =
2619 config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
2620 }
2621
2622 // Check for 24:00:00.000
2623 if (
2624 config._a[HOUR] === 24 &&
2625 config._a[MINUTE] === 0 &&
2626 config._a[SECOND] === 0 &&
2627 config._a[MILLISECOND] === 0
2628 ) {
2629 config._nextDay = true;
2630 config._a[HOUR] = 0;
2631 }
2632
2633 config._d = (config._useUTC ? createUTCDate : createDate).apply(
2634 null,
2635 input
2636 );
2637 expectedWeekday = config._useUTC
2638 ? config._d.getUTCDay()
2639 : config._d.getDay();
2640
2641 // Apply timezone offset from input. The actual utcOffset can be changed
2642 // with parseZone.
2643 if (config._tzm != null) {
2644 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
2645 }
2646
2647 if (config._nextDay) {
2648 config._a[HOUR] = 24;
2649 }
2650
2651 // check for mismatching day of week
2652 if (
2653 config._w &&
2654 typeof config._w.d !== 'undefined' &&
2655 config._w.d !== expectedWeekday
2656 ) {
2657 getParsingFlags(config).weekdayMismatch = true;
2658 }
2659 }
2660
2661 function dayOfYearFromWeekInfo(config) {
2662 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
2663
2664 w = config._w;
2665 if (w.GG != null || w.W != null || w.E != null) {
2666 dow = 1;
2667 doy = 4;
2668
2669 // TODO: We need to take the current isoWeekYear, but that depends on
2670 // how we interpret now (local, utc, fixed offset). So create
2671 // a now version of current config (take local/utc/offset flags, and
2672 // create now).
2673 weekYear = defaults(
2674 w.GG,
2675 config._a[YEAR],
2676 weekOfYear(createLocal(), 1, 4).year
2677 );
2678 week = defaults(w.W, 1);
2679 weekday = defaults(w.E, 1);
2680 if (weekday < 1 || weekday > 7) {
2681 weekdayOverflow = true;
2682 }
2683 } else {
2684 dow = config._locale._week.dow;
2685 doy = config._locale._week.doy;
2686
2687 curWeek = weekOfYear(createLocal(), dow, doy);
2688
2689 weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
2690
2691 // Default to current week.
2692 week = defaults(w.w, curWeek.week);
2693
2694 if (w.d != null) {
2695 // weekday -- low day numbers are considered next week
2696 weekday = w.d;
2697 if (weekday < 0 || weekday > 6) {
2698 weekdayOverflow = true;
2699 }
2700 } else if (w.e != null) {
2701 // local weekday -- counting starts from beginning of week
2702 weekday = w.e + dow;
2703 if (w.e < 0 || w.e > 6) {
2704 weekdayOverflow = true;
2705 }
2706 } else {
2707 // default to beginning of week
2708 weekday = dow;
2709 }
2710 }
2711 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
2712 getParsingFlags(config)._overflowWeeks = true;
2713 } else if (weekdayOverflow != null) {
2714 getParsingFlags(config)._overflowWeekday = true;
2715 } else {
2716 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
2717 config._a[YEAR] = temp.year;
2718 config._dayOfYear = temp.dayOfYear;
2719 }
2720 }
2721
2722 // constant that refers to the ISO standard
2723 hooks.ISO_8601 = function () {};
2724
2725 // constant that refers to the RFC 2822 form
2726 hooks.RFC_2822 = function () {};
2727
2728 // date from string and format string
2729 function configFromStringAndFormat(config) {
2730 // TODO: Move this to another part of the creation flow to prevent circular deps
2731 if (config._f === hooks.ISO_8601) {
2732 configFromISO(config);
2733 return;
2734 }
2735 if (config._f === hooks.RFC_2822) {
2736 configFromRFC2822(config);
2737 return;
2738 }
2739 config._a = [];
2740 getParsingFlags(config).empty = true;
2741
2742 // This array is used to make a Date, either with `new Date` or `Date.UTC`
2743 var string = '' + config._i,
2744 i,
2745 parsedInput,
2746 tokens,
2747 token,
2748 skipped,
2749 stringLength = string.length,
2750 totalParsedInputLength = 0,
2751 era;
2752
2753 tokens =
2754 expandFormat(config._f, config._locale).match(formattingTokens) || [];
2755
2756 for (i = 0; i < tokens.length; i++) {
2757 token = tokens[i];
2758 parsedInput = (string.match(getParseRegexForToken(token, config)) ||
2759 [])[0];
2760 if (parsedInput) {
2761 skipped = string.substr(0, string.indexOf(parsedInput));
2762 if (skipped.length > 0) {
2763 getParsingFlags(config).unusedInput.push(skipped);
2764 }
2765 string = string.slice(
2766 string.indexOf(parsedInput) + parsedInput.length
2767 );
2768 totalParsedInputLength += parsedInput.length;
2769 }
2770 // don't parse if it's not a known token
2771 if (formatTokenFunctions[token]) {
2772 if (parsedInput) {
2773 getParsingFlags(config).empty = false;
2774 } else {
2775 getParsingFlags(config).unusedTokens.push(token);
2776 }
2777 addTimeToArrayFromToken(token, parsedInput, config);
2778 } else if (config._strict && !parsedInput) {
2779 getParsingFlags(config).unusedTokens.push(token);
2780 }
2781 }
2782
2783 // add remaining unparsed input length to the string
2784 getParsingFlags(config).charsLeftOver =
2785 stringLength - totalParsedInputLength;
2786 if (string.length > 0) {
2787 getParsingFlags(config).unusedInput.push(string);
2788 }
2789
2790 // clear _12h flag if hour is <= 12
2791 if (
2792 config._a[HOUR] <= 12 &&
2793 getParsingFlags(config).bigHour === true &&
2794 config._a[HOUR] > 0
2795 ) {
2796 getParsingFlags(config).bigHour = undefined;
2797 }
2798
2799 getParsingFlags(config).parsedDateParts = config._a.slice(0);
2800 getParsingFlags(config).meridiem = config._meridiem;
2801 // handle meridiem
2802 config._a[HOUR] = meridiemFixWrap(
2803 config._locale,
2804 config._a[HOUR],
2805 config._meridiem
2806 );
2807
2808 // handle era
2809 era = getParsingFlags(config).era;
2810 if (era !== null) {
2811 config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
2812 }
2813
2814 configFromArray(config);
2815 checkOverflow(config);
2816 }
2817
2818 function meridiemFixWrap(locale, hour, meridiem) {
2819 var isPm;
2820
2821 if (meridiem == null) {
2822 // nothing to do
2823 return hour;
2824 }
2825 if (locale.meridiemHour != null) {
2826 return locale.meridiemHour(hour, meridiem);
2827 } else if (locale.isPM != null) {
2828 // Fallback
2829 isPm = locale.isPM(meridiem);
2830 if (isPm && hour < 12) {
2831 hour += 12;
2832 }
2833 if (!isPm && hour === 12) {
2834 hour = 0;
2835 }
2836 return hour;
2837 } else {
2838 // this is not supposed to happen
2839 return hour;
2840 }
2841 }
2842
2843 // date from string and array of format strings
2844 function configFromStringAndArray(config) {
2845 var tempConfig,
2846 bestMoment,
2847 scoreToBeat,
2848 i,
2849 currentScore,
2850 validFormatFound,
2851 bestFormatIsValid = false;
2852
2853 if (config._f.length === 0) {
2854 getParsingFlags(config).invalidFormat = true;
2855 config._d = new Date(NaN);
2856 return;
2857 }
2858
2859 for (i = 0; i < config._f.length; i++) {
2860 currentScore = 0;
2861 validFormatFound = false;
2862 tempConfig = copyConfig({}, config);
2863 if (config._useUTC != null) {
2864 tempConfig._useUTC = config._useUTC;
2865 }
2866 tempConfig._f = config._f[i];
2867 configFromStringAndFormat(tempConfig);
2868
2869 if (isValid(tempConfig)) {
2870 validFormatFound = true;
2871 }
2872
2873 // if there is any input that was not parsed add a penalty for that format
2874 currentScore += getParsingFlags(tempConfig).charsLeftOver;
2875
2876 //or tokens
2877 currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
2878
2879 getParsingFlags(tempConfig).score = currentScore;
2880
2881 if (!bestFormatIsValid) {
2882 if (
2883 scoreToBeat == null ||
2884 currentScore < scoreToBeat ||
2885 validFormatFound
2886 ) {
2887 scoreToBeat = currentScore;
2888 bestMoment = tempConfig;
2889 if (validFormatFound) {
2890 bestFormatIsValid = true;
2891 }
2892 }
2893 } else {
2894 if (currentScore < scoreToBeat) {
2895 scoreToBeat = currentScore;
2896 bestMoment = tempConfig;
2897 }
2898 }
2899 }
2900
2901 extend(config, bestMoment || tempConfig);
2902 }
2903
2904 function configFromObject(config) {
2905 if (config._d) {
2906 return;
2907 }
2908
2909 var i = normalizeObjectUnits(config._i),
2910 dayOrDate = i.day === undefined ? i.date : i.day;
2911 config._a = map(
2912 [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
2913 function (obj) {
2914 return obj && parseInt(obj, 10);
2915 }
2916 );
2917
2918 configFromArray(config);
2919 }
2920
2921 function createFromConfig(config) {
2922 var res = new Moment(checkOverflow(prepareConfig(config)));
2923 if (res._nextDay) {
2924 // Adding is smart enough around DST
2925 res.add(1, 'd');
2926 res._nextDay = undefined;
2927 }
2928
2929 return res;
2930 }
2931
2932 function prepareConfig(config) {
2933 var input = config._i,
2934 format = config._f;
2935
2936 config._locale = config._locale || getLocale(config._l);
2937
2938 if (input === null || (format === undefined && input === '')) {
2939 return createInvalid({ nullInput: true });
2940 }
2941
2942 if (typeof input === 'string') {
2943 config._i = input = config._locale.preparse(input);
2944 }
2945
2946 if (isMoment(input)) {
2947 return new Moment(checkOverflow(input));
2948 } else if (isDate(input)) {
2949 config._d = input;
2950 } else if (isArray(format)) {
2951 configFromStringAndArray(config);
2952 } else if (format) {
2953 configFromStringAndFormat(config);
2954 } else {
2955 configFromInput(config);
2956 }
2957
2958 if (!isValid(config)) {
2959 config._d = null;
2960 }
2961
2962 return config;
2963 }
2964
2965 function configFromInput(config) {
2966 var input = config._i;
2967 if (isUndefined(input)) {
2968 config._d = new Date(hooks.now());
2969 } else if (isDate(input)) {
2970 config._d = new Date(input.valueOf());
2971 } else if (typeof input === 'string') {
2972 configFromString(config);
2973 } else if (isArray(input)) {
2974 config._a = map(input.slice(0), function (obj) {
2975 return parseInt(obj, 10);
2976 });
2977 configFromArray(config);
2978 } else if (isObject(input)) {
2979 configFromObject(config);
2980 } else if (isNumber(input)) {
2981 // from milliseconds
2982 config._d = new Date(input);
2983 } else {
2984 hooks.createFromInputFallback(config);
2985 }
2986 }
2987
2988 function createLocalOrUTC(input, format, locale, strict, isUTC) {
2989 var c = {};
2990
2991 if (format === true || format === false) {
2992 strict = format;
2993 format = undefined;
2994 }
2995
2996 if (locale === true || locale === false) {
2997 strict = locale;
2998 locale = undefined;
2999 }
3000
3001 if (
3002 (isObject(input) && isObjectEmpty(input)) ||
3003 (isArray(input) && input.length === 0)
3004 ) {
3005 input = undefined;
3006 }
3007 // object construction must be done this way.
3008 // https://github.com/moment/moment/issues/1423
3009 c._isAMomentObject = true;
3010 c._useUTC = c._isUTC = isUTC;
3011 c._l = locale;
3012 c._i = input;
3013 c._f = format;
3014 c._strict = strict;
3015
3016 return createFromConfig(c);
3017 }
3018
3019 function createLocal(input, format, locale, strict) {
3020 return createLocalOrUTC(input, format, locale, strict, false);
3021 }
3022
3023 var prototypeMin = deprecate(
3024 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
3025 function () {
3026 var other = createLocal.apply(null, arguments);
3027 if (this.isValid() && other.isValid()) {
3028 return other < this ? this : other;
3029 } else {
3030 return createInvalid();
3031 }
3032 }
3033 ),
3034 prototypeMax = deprecate(
3035 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
3036 function () {
3037 var other = createLocal.apply(null, arguments);
3038 if (this.isValid() && other.isValid()) {
3039 return other > this ? this : other;
3040 } else {
3041 return createInvalid();
3042 }
3043 }
3044 );
3045
3046 // Pick a moment m from moments so that m[fn](other) is true for all
3047 // other. This relies on the function fn to be transitive.
3048 //
3049 // moments should either be an array of moment objects or an array, whose
3050 // first element is an array of moment objects.
3051 function pickBy(fn, moments) {
3052 var res, i;
3053 if (moments.length === 1 && isArray(moments[0])) {
3054 moments = moments[0];
3055 }
3056 if (!moments.length) {
3057 return createLocal();
3058 }
3059 res = moments[0];
3060 for (i = 1; i < moments.length; ++i) {
3061 if (!moments[i].isValid() || moments[i][fn](res)) {
3062 res = moments[i];
3063 }
3064 }
3065 return res;
3066 }
3067
3068 // TODO: Use [].sort instead?
3069 function min() {
3070 var args = [].slice.call(arguments, 0);
3071
3072 return pickBy('isBefore', args);
3073 }
3074
3075 function max() {
3076 var args = [].slice.call(arguments, 0);
3077
3078 return pickBy('isAfter', args);
3079 }
3080
3081 var now = function () {
3082 return Date.now ? Date.now() : +new Date();
3083 };
3084
3085 var ordering = [
3086 'year',
3087 'quarter',
3088 'month',
3089 'week',
3090 'day',
3091 'hour',
3092 'minute',
3093 'second',
3094 'millisecond',
3095 ];
3096
3097 function isDurationValid(m) {
3098 var key,
3099 unitHasDecimal = false,
3100 i;
3101 for (key in m) {
3102 if (
3103 hasOwnProp(m, key) &&
3104 !(
3105 indexOf.call(ordering, key) !== -1 &&
3106 (m[key] == null || !isNaN(m[key]))
3107 )
3108 ) {
3109 return false;
3110 }
3111 }
3112
3113 for (i = 0; i < ordering.length; ++i) {
3114 if (m[ordering[i]]) {
3115 if (unitHasDecimal) {
3116 return false; // only allow non-integers for smallest unit
3117 }
3118 if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
3119 unitHasDecimal = true;
3120 }
3121 }
3122 }
3123
3124 return true;
3125 }
3126
3127 function isValid$1() {
3128 return this._isValid;
3129 }
3130
3131 function createInvalid$1() {
3132 return createDuration(NaN);
3133 }
3134
3135 function Duration(duration) {
3136 var normalizedInput = normalizeObjectUnits(duration),
3137 years = normalizedInput.year || 0,
3138 quarters = normalizedInput.quarter || 0,
3139 months = normalizedInput.month || 0,
3140 weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
3141 days = normalizedInput.day || 0,
3142 hours = normalizedInput.hour || 0,
3143 minutes = normalizedInput.minute || 0,
3144 seconds = normalizedInput.second || 0,
3145 milliseconds = normalizedInput.millisecond || 0;
3146
3147 this._isValid = isDurationValid(normalizedInput);
3148
3149 // representation for dateAddRemove
3150 this._milliseconds =
3151 +milliseconds +
3152 seconds * 1e3 + // 1000
3153 minutes * 6e4 + // 1000 * 60
3154 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
3155 // Because of dateAddRemove treats 24 hours as different from a
3156 // day when working around DST, we need to store them separately
3157 this._days = +days + weeks * 7;
3158 // It is impossible to translate months into days without knowing
3159 // which months you are are talking about, so we have to store
3160 // it separately.
3161 this._months = +months + quarters * 3 + years * 12;
3162
3163 this._data = {};
3164
3165 this._locale = getLocale();
3166
3167 this._bubble();
3168 }
3169
3170 function isDuration(obj) {
3171 return obj instanceof Duration;
3172 }
3173
3174 function absRound(number) {
3175 if (number < 0) {
3176 return Math.round(-1 * number) * -1;
3177 } else {
3178 return Math.round(number);
3179 }
3180 }
3181
3182 // compare two arrays, return the number of differences
3183 function compareArrays(array1, array2, dontConvert) {
3184 var len = Math.min(array1.length, array2.length),
3185 lengthDiff = Math.abs(array1.length - array2.length),
3186 diffs = 0,
3187 i;
3188 for (i = 0; i < len; i++) {
3189 if (
3190 (dontConvert && array1[i] !== array2[i]) ||
3191 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))
3192 ) {
3193 diffs++;
3194 }
3195 }
3196 return diffs + lengthDiff;
3197 }
3198
3199 // FORMATTING
3200
3201 function offset(token, separator) {
3202 addFormatToken(token, 0, 0, function () {
3203 var offset = this.utcOffset(),
3204 sign = '+';
3205 if (offset < 0) {
3206 offset = -offset;
3207 sign = '-';
3208 }
3209 return (
3210 sign +
3211 zeroFill(~~(offset / 60), 2) +
3212 separator +
3213 zeroFill(~~offset % 60, 2)
3214 );
3215 });
3216 }
3217
3218 offset('Z', ':');
3219 offset('ZZ', '');
3220
3221 // PARSING
3222
3223 addRegexToken('Z', matchShortOffset);
3224 addRegexToken('ZZ', matchShortOffset);
3225 addParseToken(['Z', 'ZZ'], function (input, array, config) {
3226 config._useUTC = true;
3227 config._tzm = offsetFromString(matchShortOffset, input);
3228 });
3229
3230 // HELPERS
3231
3232 // timezone chunker
3233 // '+10:00' > ['10', '00']
3234 // '-1530' > ['-15', '30']
3235 var chunkOffset = /([\+\-]|\d\d)/gi;
3236
3237 function offsetFromString(matcher, string) {
3238 var matches = (string || '').match(matcher),
3239 chunk,
3240 parts,
3241 minutes;
3242
3243 if (matches === null) {
3244 return null;
3245 }
3246
3247 chunk = matches[matches.length - 1] || [];
3248 parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
3249 minutes = +(parts[1] * 60) + toInt(parts[2]);
3250
3251 return minutes === 0 ? 0 : parts[0] === '+' ? minutes : -minutes;
3252 }
3253
3254 // Return a moment from input, that is local/utc/zone equivalent to model.
3255 function cloneWithOffset(input, model) {
3256 var res, diff;
3257 if (model._isUTC) {
3258 res = model.clone();
3259 diff =
3260 (isMoment(input) || isDate(input)
3261 ? input.valueOf()
3262 : createLocal(input).valueOf()) - res.valueOf();
3263 // Use low-level api, because this fn is low-level api.
3264 res._d.setTime(res._d.valueOf() + diff);
3265 hooks.updateOffset(res, false);
3266 return res;
3267 } else {
3268 return createLocal(input).local();
3269 }
3270 }
3271
3272 function getDateOffset(m) {
3273 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
3274 // https://github.com/moment/moment/pull/1871
3275 return -Math.round(m._d.getTimezoneOffset());
3276 }
3277
3278 // HOOKS
3279
3280 // This function will be called whenever a moment is mutated.
3281 // It is intended to keep the offset in sync with the timezone.
3282 hooks.updateOffset = function () {};
3283
3284 // MOMENTS
3285
3286 // keepLocalTime = true means only change the timezone, without
3287 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
3288 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
3289 // +0200, so we adjust the time as needed, to be valid.
3290 //
3291 // Keeping the time actually adds/subtracts (one hour)
3292 // from the actual represented time. That is why we call updateOffset
3293 // a second time. In case it wants us to change the offset again
3294 // _changeInProgress == true case, then we have to adjust, because
3295 // there is no such time in the given timezone.
3296 function getSetOffset(input, keepLocalTime, keepMinutes) {
3297 var offset = this._offset || 0,
3298 localAdjust;
3299 if (!this.isValid()) {
3300 return input != null ? this : NaN;
3301 }
3302 if (input != null) {
3303 if (typeof input === 'string') {
3304 input = offsetFromString(matchShortOffset, input);
3305 if (input === null) {
3306 return this;
3307 }
3308 } else if (Math.abs(input) < 16 && !keepMinutes) {
3309 input = input * 60;
3310 }
3311 if (!this._isUTC && keepLocalTime) {
3312 localAdjust = getDateOffset(this);
3313 }
3314 this._offset = input;
3315 this._isUTC = true;
3316 if (localAdjust != null) {
3317 this.add(localAdjust, 'm');
3318 }
3319 if (offset !== input) {
3320 if (!keepLocalTime || this._changeInProgress) {
3321 addSubtract(
3322 this,
3323 createDuration(input - offset, 'm'),
3324 1,
3325 false
3326 );
3327 } else if (!this._changeInProgress) {
3328 this._changeInProgress = true;
3329 hooks.updateOffset(this, true);
3330 this._changeInProgress = null;
3331 }
3332 }
3333 return this;
3334 } else {
3335 return this._isUTC ? offset : getDateOffset(this);
3336 }
3337 }
3338
3339 function getSetZone(input, keepLocalTime) {
3340 if (input != null) {
3341 if (typeof input !== 'string') {
3342 input = -input;
3343 }
3344
3345 this.utcOffset(input, keepLocalTime);
3346
3347 return this;
3348 } else {
3349 return -this.utcOffset();
3350 }
3351 }
3352
3353 function setOffsetToUTC(keepLocalTime) {
3354 return this.utcOffset(0, keepLocalTime);
3355 }
3356
3357 function setOffsetToLocal(keepLocalTime) {
3358 if (this._isUTC) {
3359 this.utcOffset(0, keepLocalTime);
3360 this._isUTC = false;
3361
3362 if (keepLocalTime) {
3363 this.subtract(getDateOffset(this), 'm');
3364 }
3365 }
3366 return this;
3367 }
3368
3369 function setOffsetToParsedOffset() {
3370 if (this._tzm != null) {
3371 this.utcOffset(this._tzm, false, true);
3372 } else if (typeof this._i === 'string') {
3373 var tZone = offsetFromString(matchOffset, this._i);
3374 if (tZone != null) {
3375 this.utcOffset(tZone);
3376 } else {
3377 this.utcOffset(0, true);
3378 }
3379 }
3380 return this;
3381 }
3382
3383 function hasAlignedHourOffset(input) {
3384 if (!this.isValid()) {
3385 return false;
3386 }
3387 input = input ? createLocal(input).utcOffset() : 0;
3388
3389 return (this.utcOffset() - input) % 60 === 0;
3390 }
3391
3392 function isDaylightSavingTime() {
3393 return (
3394 this.utcOffset() > this.clone().month(0).utcOffset() ||
3395 this.utcOffset() > this.clone().month(5).utcOffset()
3396 );
3397 }
3398
3399 function isDaylightSavingTimeShifted() {
3400 if (!isUndefined(this._isDSTShifted)) {
3401 return this._isDSTShifted;
3402 }
3403
3404 var c = {},
3405 other;
3406
3407 copyConfig(c, this);
3408 c = prepareConfig(c);
3409
3410 if (c._a) {
3411 other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
3412 this._isDSTShifted =
3413 this.isValid() && compareArrays(c._a, other.toArray()) > 0;
3414 } else {
3415 this._isDSTShifted = false;
3416 }
3417
3418 return this._isDSTShifted;
3419 }
3420
3421 function isLocal() {
3422 return this.isValid() ? !this._isUTC : false;
3423 }
3424
3425 function isUtcOffset() {
3426 return this.isValid() ? this._isUTC : false;
3427 }
3428
3429 function isUtc() {
3430 return this.isValid() ? this._isUTC && this._offset === 0 : false;
3431 }
3432
3433 // ASP.NET json date format regex
3434 var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
3435 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
3436 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
3437 // and further modified to allow for strings containing both week and day
3438 isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
3439
3440 function createDuration(input, key) {
3441 var duration = input,
3442 // matching against regexp is expensive, do it on demand
3443 match = null,
3444 sign,
3445 ret,
3446 diffRes;
3447
3448 if (isDuration(input)) {
3449 duration = {
3450 ms: input._milliseconds,
3451 d: input._days,
3452 M: input._months,
3453 };
3454 } else if (isNumber(input) || !isNaN(+input)) {
3455 duration = {};
3456 if (key) {
3457 duration[key] = +input;
3458 } else {
3459 duration.milliseconds = +input;
3460 }
3461 } else if ((match = aspNetRegex.exec(input))) {
3462 sign = match[1] === '-' ? -1 : 1;
3463 duration = {
3464 y: 0,
3465 d: toInt(match[DATE]) * sign,
3466 h: toInt(match[HOUR]) * sign,
3467 m: toInt(match[MINUTE]) * sign,
3468 s: toInt(match[SECOND]) * sign,
3469 ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match
3470 };
3471 } else if ((match = isoRegex.exec(input))) {
3472 sign = match[1] === '-' ? -1 : 1;
3473 duration = {
3474 y: parseIso(match[2], sign),
3475 M: parseIso(match[3], sign),
3476 w: parseIso(match[4], sign),
3477 d: parseIso(match[5], sign),
3478 h: parseIso(match[6], sign),
3479 m: parseIso(match[7], sign),
3480 s: parseIso(match[8], sign),
3481 };
3482 } else if (duration == null) {
3483 // checks for null or undefined
3484 duration = {};
3485 } else if (
3486 typeof duration === 'object' &&
3487 ('from' in duration || 'to' in duration)
3488 ) {
3489 diffRes = momentsDifference(
3490 createLocal(duration.from),
3491 createLocal(duration.to)
3492 );
3493
3494 duration = {};
3495 duration.ms = diffRes.milliseconds;
3496 duration.M = diffRes.months;
3497 }
3498
3499 ret = new Duration(duration);
3500
3501 if (isDuration(input) && hasOwnProp(input, '_locale')) {
3502 ret._locale = input._locale;
3503 }
3504
3505 if (isDuration(input) && hasOwnProp(input, '_isValid')) {
3506 ret._isValid = input._isValid;
3507 }
3508
3509 return ret;
3510 }
3511
3512 createDuration.fn = Duration.prototype;
3513 createDuration.invalid = createInvalid$1;
3514
3515 function parseIso(inp, sign) {
3516 // We'd normally use ~~inp for this, but unfortunately it also
3517 // converts floats to ints.
3518 // inp may be undefined, so careful calling replace on it.
3519 var res = inp && parseFloat(inp.replace(',', '.'));
3520 // apply sign while we're at it
3521 return (isNaN(res) ? 0 : res) * sign;
3522 }
3523
3524 function positiveMomentsDifference(base, other) {
3525 var res = {};
3526
3527 res.months =
3528 other.month() - base.month() + (other.year() - base.year()) * 12;
3529 if (base.clone().add(res.months, 'M').isAfter(other)) {
3530 --res.months;
3531 }
3532
3533 res.milliseconds = +other - +base.clone().add(res.months, 'M');
3534
3535 return res;
3536 }
3537
3538 function momentsDifference(base, other) {
3539 var res;
3540 if (!(base.isValid() && other.isValid())) {
3541 return { milliseconds: 0, months: 0 };
3542 }
3543
3544 other = cloneWithOffset(other, base);
3545 if (base.isBefore(other)) {
3546 res = positiveMomentsDifference(base, other);
3547 } else {
3548 res = positiveMomentsDifference(other, base);
3549 res.milliseconds = -res.milliseconds;
3550 res.months = -res.months;
3551 }
3552
3553 return res;
3554 }
3555
3556 // TODO: remove 'name' arg after deprecation is removed
3557 function createAdder(direction, name) {
3558 return function (val, period) {
3559 var dur, tmp;
3560 //invert the arguments, but complain about it
3561 if (period !== null && !isNaN(+period)) {
3562 deprecateSimple(
3563 name,
3564 'moment().' +
3565 name +
3566 '(period, number) is deprecated. Please use moment().' +
3567 name +
3568 '(number, period). ' +
3569 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'
3570 );
3571 tmp = val;
3572 val = period;
3573 period = tmp;
3574 }
3575
3576 dur = createDuration(val, period);
3577 addSubtract(this, dur, direction);
3578 return this;
3579 };
3580 }
3581
3582 function addSubtract(mom, duration, isAdding, updateOffset) {
3583 var milliseconds = duration._milliseconds,
3584 days = absRound(duration._days),
3585 months = absRound(duration._months);
3586
3587 if (!mom.isValid()) {
3588 // No op
3589 return;
3590 }
3591
3592 updateOffset = updateOffset == null ? true : updateOffset;
3593
3594 if (months) {
3595 setMonth(mom, get(mom, 'Month') + months * isAdding);
3596 }
3597 if (days) {
3598 set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
3599 }
3600 if (milliseconds) {
3601 mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
3602 }
3603 if (updateOffset) {
3604 hooks.updateOffset(mom, days || months);
3605 }
3606 }
3607
3608 var add = createAdder(1, 'add'),
3609 subtract = createAdder(-1, 'subtract');
3610
3611 function isString(input) {
3612 return typeof input === 'string' || input instanceof String;
3613 }
3614
3615 // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
3616 function isMomentInput(input) {
3617 return (
3618 isMoment(input) ||
3619 isDate(input) ||
3620 isString(input) ||
3621 isNumber(input) ||
3622 isNumberOrStringArray(input) ||
3623 isMomentInputObject(input) ||
3624 input === null ||
3625 input === undefined
3626 );
3627 }
3628
3629 function isMomentInputObject(input) {
3630 var objectTest = isObject(input) && !isObjectEmpty(input),
3631 propertyTest = false,
3632 properties = [
3633 'years',
3634 'year',
3635 'y',
3636 'months',
3637 'month',
3638 'M',
3639 'days',
3640 'day',
3641 'd',
3642 'dates',
3643 'date',
3644 'D',
3645 'hours',
3646 'hour',
3647 'h',
3648 'minutes',
3649 'minute',
3650 'm',
3651 'seconds',
3652 'second',
3653 's',
3654 'milliseconds',
3655 'millisecond',
3656 'ms',
3657 ],
3658 i,
3659 property;
3660
3661 for (i = 0; i < properties.length; i += 1) {
3662 property = properties[i];
3663 propertyTest = propertyTest || hasOwnProp(input, property);
3664 }
3665
3666 return objectTest && propertyTest;
3667 }
3668
3669 function isNumberOrStringArray(input) {
3670 var arrayTest = isArray(input),
3671 dataTypeTest = false;
3672 if (arrayTest) {
3673 dataTypeTest =
3674 input.filter(function (item) {
3675 return !isNumber(item) && isString(input);
3676 }).length === 0;
3677 }
3678 return arrayTest && dataTypeTest;
3679 }
3680
3681 function isCalendarSpec(input) {
3682 var objectTest = isObject(input) && !isObjectEmpty(input),
3683 propertyTest = false,
3684 properties = [
3685 'sameDay',
3686 'nextDay',
3687 'lastDay',
3688 'nextWeek',
3689 'lastWeek',
3690 'sameElse',
3691 ],
3692 i,
3693 property;
3694
3695 for (i = 0; i < properties.length; i += 1) {
3696 property = properties[i];
3697 propertyTest = propertyTest || hasOwnProp(input, property);
3698 }
3699
3700 return objectTest && propertyTest;
3701 }
3702
3703 function getCalendarFormat(myMoment, now) {
3704 var diff = myMoment.diff(now, 'days', true);
3705 return diff < -6
3706 ? 'sameElse'
3707 : diff < -1
3708 ? 'lastWeek'
3709 : diff < 0
3710 ? 'lastDay'
3711 : diff < 1
3712 ? 'sameDay'
3713 : diff < 2
3714 ? 'nextDay'
3715 : diff < 7
3716 ? 'nextWeek'
3717 : 'sameElse';
3718 }
3719
3720 function calendar$1(time, formats) {
3721 // Support for single parameter, formats only overload to the calendar function
3722 if (arguments.length === 1) {
3723 if (!arguments[0]) {
3724 time = undefined;
3725 formats = undefined;
3726 } else if (isMomentInput(arguments[0])) {
3727 time = arguments[0];
3728 formats = undefined;
3729 } else if (isCalendarSpec(arguments[0])) {
3730 formats = arguments[0];
3731 time = undefined;
3732 }
3733 }
3734 // We want to compare the start of today, vs this.
3735 // Getting start-of-today depends on whether we're local/utc/offset or not.
3736 var now = time || createLocal(),
3737 sod = cloneWithOffset(now, this).startOf('day'),
3738 format = hooks.calendarFormat(this, sod) || 'sameElse',
3739 output =
3740 formats &&
3741 (isFunction(formats[format])
3742 ? formats[format].call(this, now)
3743 : formats[format]);
3744
3745 return this.format(
3746 output || this.localeData().calendar(format, this, createLocal(now))
3747 );
3748 }
3749
3750 function clone() {
3751 return new Moment(this);
3752 }
3753
3754 function isAfter(input, units) {
3755 var localInput = isMoment(input) ? input : createLocal(input);
3756 if (!(this.isValid() && localInput.isValid())) {
3757 return false;
3758 }
3759 units = normalizeUnits(units) || 'millisecond';
3760 if (units === 'millisecond') {
3761 return this.valueOf() > localInput.valueOf();
3762 } else {
3763 return localInput.valueOf() < this.clone().startOf(units).valueOf();
3764 }
3765 }
3766
3767 function isBefore(input, units) {
3768 var localInput = isMoment(input) ? input : createLocal(input);
3769 if (!(this.isValid() && localInput.isValid())) {
3770 return false;
3771 }
3772 units = normalizeUnits(units) || 'millisecond';
3773 if (units === 'millisecond') {
3774 return this.valueOf() < localInput.valueOf();
3775 } else {
3776 return this.clone().endOf(units).valueOf() < localInput.valueOf();
3777 }
3778 }
3779
3780 function isBetween(from, to, units, inclusivity) {
3781 var localFrom = isMoment(from) ? from : createLocal(from),
3782 localTo = isMoment(to) ? to : createLocal(to);
3783 if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
3784 return false;
3785 }
3786 inclusivity = inclusivity || '()';
3787 return (
3788 (inclusivity[0] === '('
3789 ? this.isAfter(localFrom, units)
3790 : !this.isBefore(localFrom, units)) &&
3791 (inclusivity[1] === ')'
3792 ? this.isBefore(localTo, units)
3793 : !this.isAfter(localTo, units))
3794 );
3795 }
3796
3797 function isSame(input, units) {
3798 var localInput = isMoment(input) ? input : createLocal(input),
3799 inputMs;
3800 if (!(this.isValid() && localInput.isValid())) {
3801 return false;
3802 }
3803 units = normalizeUnits(units) || 'millisecond';
3804 if (units === 'millisecond') {
3805 return this.valueOf() === localInput.valueOf();
3806 } else {
3807 inputMs = localInput.valueOf();
3808 return (
3809 this.clone().startOf(units).valueOf() <= inputMs &&
3810 inputMs <= this.clone().endOf(units).valueOf()
3811 );
3812 }
3813 }
3814
3815 function isSameOrAfter(input, units) {
3816 return this.isSame(input, units) || this.isAfter(input, units);
3817 }
3818
3819 function isSameOrBefore(input, units) {
3820 return this.isSame(input, units) || this.isBefore(input, units);
3821 }
3822
3823 function diff(input, units, asFloat) {
3824 var that, zoneDelta, output;
3825
3826 if (!this.isValid()) {
3827 return NaN;
3828 }
3829
3830 that = cloneWithOffset(input, this);
3831
3832 if (!that.isValid()) {
3833 return NaN;
3834 }
3835
3836 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
3837
3838 units = normalizeUnits(units);
3839
3840 switch (units) {
3841 case 'year':
3842 output = monthDiff(this, that) / 12;
3843 break;
3844 case 'month':
3845 output = monthDiff(this, that);
3846 break;
3847 case 'quarter':
3848 output = monthDiff(this, that) / 3;
3849 break;
3850 case 'second':
3851 output = (this - that) / 1e3;
3852 break; // 1000
3853 case 'minute':
3854 output = (this - that) / 6e4;
3855 break; // 1000 * 60
3856 case 'hour':
3857 output = (this - that) / 36e5;
3858 break; // 1000 * 60 * 60
3859 case 'day':
3860 output = (this - that - zoneDelta) / 864e5;
3861 break; // 1000 * 60 * 60 * 24, negate dst
3862 case 'week':
3863 output = (this - that - zoneDelta) / 6048e5;
3864 break; // 1000 * 60 * 60 * 24 * 7, negate dst
3865 default:
3866 output = this - that;
3867 }
3868
3869 return asFloat ? output : absFloor(output);
3870 }
3871
3872 function monthDiff(a, b) {
3873 if (a.date() < b.date()) {
3874 // end-of-month calculations work correct when the start month has more
3875 // days than the end month.
3876 return -monthDiff(b, a);
3877 }
3878 // difference in months
3879 var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
3880 // b is in (anchor - 1 month, anchor + 1 month)
3881 anchor = a.clone().add(wholeMonthDiff, 'months'),
3882 anchor2,
3883 adjust;
3884
3885 if (b - anchor < 0) {
3886 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
3887 // linear across the month
3888 adjust = (b - anchor) / (anchor - anchor2);
3889 } else {
3890 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
3891 // linear across the month
3892 adjust = (b - anchor) / (anchor2 - anchor);
3893 }
3894
3895 //check for negative zero, return zero if negative zero
3896 return -(wholeMonthDiff + adjust) || 0;
3897 }
3898
3899 hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
3900 hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
3901
3902 function toString() {
3903 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
3904 }
3905
3906 function toISOString(keepOffset) {
3907 if (!this.isValid()) {
3908 return null;
3909 }
3910 var utc = keepOffset !== true,
3911 m = utc ? this.clone().utc() : this;
3912 if (m.year() < 0 || m.year() > 9999) {
3913 return formatMoment(
3914 m,
3915 utc
3916 ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'
3917 : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'
3918 );
3919 }
3920 if (isFunction(Date.prototype.toISOString)) {
3921 // native implementation is ~50x faster, use it when we can
3922 if (utc) {
3923 return this.toDate().toISOString();
3924 } else {
3925 return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
3926 .toISOString()
3927 .replace('Z', formatMoment(m, 'Z'));
3928 }
3929 }
3930 return formatMoment(
3931 m,
3932 utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ'
3933 );
3934 }
3935
3936 /**
3937 * Return a human readable representation of a moment that can
3938 * also be evaluated to get a new moment which is the same
3939 *
3940 * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
3941 */
3942 function inspect() {
3943 if (!this.isValid()) {
3944 return 'moment.invalid(/* ' + this._i + ' */)';
3945 }
3946 var func = 'moment',
3947 zone = '',
3948 prefix,
3949 year,
3950 datetime,
3951 suffix;
3952 if (!this.isLocal()) {
3953 func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
3954 zone = 'Z';
3955 }
3956 prefix = '[' + func + '("]';
3957 year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY';
3958 datetime = '-MM-DD[T]HH:mm:ss.SSS';
3959 suffix = zone + '[")]';
3960
3961 return this.format(prefix + year + datetime + suffix);
3962 }
3963
3964 function format(inputString) {
3965 if (!inputString) {
3966 inputString = this.isUtc()
3967 ? hooks.defaultFormatUtc
3968 : hooks.defaultFormat;
3969 }
3970 var output = formatMoment(this, inputString);
3971 return this.localeData().postformat(output);
3972 }
3973
3974 function from(time, withoutSuffix) {
3975 if (
3976 this.isValid() &&
3977 ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
3978 ) {
3979 return createDuration({ to: this, from: time })
3980 .locale(this.locale())
3981 .humanize(!withoutSuffix);
3982 } else {
3983 return this.localeData().invalidDate();
3984 }
3985 }
3986
3987 function fromNow(withoutSuffix) {
3988 return this.from(createLocal(), withoutSuffix);
3989 }
3990
3991 function to(time, withoutSuffix) {
3992 if (
3993 this.isValid() &&
3994 ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
3995 ) {
3996 return createDuration({ from: this, to: time })
3997 .locale(this.locale())
3998 .humanize(!withoutSuffix);
3999 } else {
4000 return this.localeData().invalidDate();
4001 }
4002 }
4003
4004 function toNow(withoutSuffix) {
4005 return this.to(createLocal(), withoutSuffix);
4006 }
4007
4008 // If passed a locale key, it will set the locale for this
4009 // instance. Otherwise, it will return the locale configuration
4010 // variables for this instance.
4011 function locale(key) {
4012 var newLocaleData;
4013
4014 if (key === undefined) {
4015 return this._locale._abbr;
4016 } else {
4017 newLocaleData = getLocale(key);
4018 if (newLocaleData != null) {
4019 this._locale = newLocaleData;
4020 }
4021 return this;
4022 }
4023 }
4024
4025 var lang = deprecate(
4026 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
4027 function (key) {
4028 if (key === undefined) {
4029 return this.localeData();
4030 } else {
4031 return this.locale(key);
4032 }
4033 }
4034 );
4035
4036 function localeData() {
4037 return this._locale;
4038 }
4039
4040 var MS_PER_SECOND = 1000,
4041 MS_PER_MINUTE = 60 * MS_PER_SECOND,
4042 MS_PER_HOUR = 60 * MS_PER_MINUTE,
4043 MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
4044
4045 // actual modulo - handles negative numbers (for dates before 1970):
4046 function mod$1(dividend, divisor) {
4047 return ((dividend % divisor) + divisor) % divisor;
4048 }
4049
4050 function localStartOfDate(y, m, d) {
4051 // the date constructor remaps years 0-99 to 1900-1999
4052 if (y < 100 && y >= 0) {
4053 // preserve leap years using a full 400 year cycle, then reset
4054 return new Date(y + 400, m, d) - MS_PER_400_YEARS;
4055 } else {
4056 return new Date(y, m, d).valueOf();
4057 }
4058 }
4059
4060 function utcStartOfDate(y, m, d) {
4061 // Date.UTC remaps years 0-99 to 1900-1999
4062 if (y < 100 && y >= 0) {
4063 // preserve leap years using a full 400 year cycle, then reset
4064 return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
4065 } else {
4066 return Date.UTC(y, m, d);
4067 }
4068 }
4069
4070 function startOf(units) {
4071 var time, startOfDate;
4072 units = normalizeUnits(units);
4073 if (units === undefined || units === 'millisecond' || !this.isValid()) {
4074 return this;
4075 }
4076
4077 startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
4078
4079 switch (units) {
4080 case 'year':
4081 time = startOfDate(this.year(), 0, 1);
4082 break;
4083 case 'quarter':
4084 time = startOfDate(
4085 this.year(),
4086 this.month() - (this.month() % 3),
4087 1
4088 );
4089 break;
4090 case 'month':
4091 time = startOfDate(this.year(), this.month(), 1);
4092 break;
4093 case 'week':
4094 time = startOfDate(
4095 this.year(),
4096 this.month(),
4097 this.date() - this.weekday()
4098 );
4099 break;
4100 case 'isoWeek':
4101 time = startOfDate(
4102 this.year(),
4103 this.month(),
4104 this.date() - (this.isoWeekday() - 1)
4105 );
4106 break;
4107 case 'day':
4108 case 'date':
4109 time = startOfDate(this.year(), this.month(), this.date());
4110 break;
4111 case 'hour':
4112 time = this._d.valueOf();
4113 time -= mod$1(
4114 time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
4115 MS_PER_HOUR
4116 );
4117 break;
4118 case 'minute':
4119 time = this._d.valueOf();
4120 time -= mod$1(time, MS_PER_MINUTE);
4121 break;
4122 case 'second':
4123 time = this._d.valueOf();
4124 time -= mod$1(time, MS_PER_SECOND);
4125 break;
4126 }
4127
4128 this._d.setTime(time);
4129 hooks.updateOffset(this, true);
4130 return this;
4131 }
4132
4133 function endOf(units) {
4134 var time, startOfDate;
4135 units = normalizeUnits(units);
4136 if (units === undefined || units === 'millisecond' || !this.isValid()) {
4137 return this;
4138 }
4139
4140 startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
4141
4142 switch (units) {
4143 case 'year':
4144 time = startOfDate(this.year() + 1, 0, 1) - 1;
4145 break;
4146 case 'quarter':
4147 time =
4148 startOfDate(
4149 this.year(),
4150 this.month() - (this.month() % 3) + 3,
4151 1
4152 ) - 1;
4153 break;
4154 case 'month':
4155 time = startOfDate(this.year(), this.month() + 1, 1) - 1;
4156 break;
4157 case 'week':
4158 time =
4159 startOfDate(
4160 this.year(),
4161 this.month(),
4162 this.date() - this.weekday() + 7
4163 ) - 1;
4164 break;
4165 case 'isoWeek':
4166 time =
4167 startOfDate(
4168 this.year(),
4169 this.month(),
4170 this.date() - (this.isoWeekday() - 1) + 7
4171 ) - 1;
4172 break;
4173 case 'day':
4174 case 'date':
4175 time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
4176 break;
4177 case 'hour':
4178 time = this._d.valueOf();
4179 time +=
4180 MS_PER_HOUR -
4181 mod$1(
4182 time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
4183 MS_PER_HOUR
4184 ) -
4185 1;
4186 break;
4187 case 'minute':
4188 time = this._d.valueOf();
4189 time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
4190 break;
4191 case 'second':
4192 time = this._d.valueOf();
4193 time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
4194 break;
4195 }
4196
4197 this._d.setTime(time);
4198 hooks.updateOffset(this, true);
4199 return this;
4200 }
4201
4202 function valueOf() {
4203 return this._d.valueOf() - (this._offset || 0) * 60000;
4204 }
4205
4206 function unix() {
4207 return Math.floor(this.valueOf() / 1000);
4208 }
4209
4210 function toDate() {
4211 return new Date(this.valueOf());
4212 }
4213
4214 function toArray() {
4215 var m = this;
4216 return [
4217 m.year(),
4218 m.month(),
4219 m.date(),
4220 m.hour(),
4221 m.minute(),
4222 m.second(),
4223 m.millisecond(),
4224 ];
4225 }
4226
4227 function toObject() {
4228 var m = this;
4229 return {
4230 years: m.year(),
4231 months: m.month(),
4232 date: m.date(),
4233 hours: m.hours(),
4234 minutes: m.minutes(),
4235 seconds: m.seconds(),
4236 milliseconds: m.milliseconds(),
4237 };
4238 }
4239
4240 function toJSON() {
4241 // new Date(NaN).toJSON() === null
4242 return this.isValid() ? this.toISOString() : null;
4243 }
4244
4245 function isValid$2() {
4246 return isValid(this);
4247 }
4248
4249 function parsingFlags() {
4250 return extend({}, getParsingFlags(this));
4251 }
4252
4253 function invalidAt() {
4254 return getParsingFlags(this).overflow;
4255 }
4256
4257 function creationData() {
4258 return {
4259 input: this._i,
4260 format: this._f,
4261 locale: this._locale,
4262 isUTC: this._isUTC,
4263 strict: this._strict,
4264 };
4265 }
4266
4267 addFormatToken('N', 0, 0, 'eraAbbr');
4268 addFormatToken('NN', 0, 0, 'eraAbbr');
4269 addFormatToken('NNN', 0, 0, 'eraAbbr');
4270 addFormatToken('NNNN', 0, 0, 'eraName');
4271 addFormatToken('NNNNN', 0, 0, 'eraNarrow');
4272
4273 addFormatToken('y', ['y', 1], 'yo', 'eraYear');
4274 addFormatToken('y', ['yy', 2], 0, 'eraYear');
4275 addFormatToken('y', ['yyy', 3], 0, 'eraYear');
4276 addFormatToken('y', ['yyyy', 4], 0, 'eraYear');
4277
4278 addRegexToken('N', matchEraAbbr);
4279 addRegexToken('NN', matchEraAbbr);
4280 addRegexToken('NNN', matchEraAbbr);
4281 addRegexToken('NNNN', matchEraName);
4282 addRegexToken('NNNNN', matchEraNarrow);
4283
4284 addParseToken(['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], function (
4285 input,
4286 array,
4287 config,
4288 token
4289 ) {
4290 var era = config._locale.erasParse(input, token, config._strict);
4291 if (era) {
4292 getParsingFlags(config).era = era;
4293 } else {
4294 getParsingFlags(config).invalidEra = input;
4295 }
4296 });
4297
4298 addRegexToken('y', matchUnsigned);
4299 addRegexToken('yy', matchUnsigned);
4300 addRegexToken('yyy', matchUnsigned);
4301 addRegexToken('yyyy', matchUnsigned);
4302 addRegexToken('yo', matchEraYearOrdinal);
4303
4304 addParseToken(['y', 'yy', 'yyy', 'yyyy'], YEAR);
4305 addParseToken(['yo'], function (input, array, config, token) {
4306 var match;
4307 if (config._locale._eraYearOrdinalRegex) {
4308 match = input.match(config._locale._eraYearOrdinalRegex);
4309 }
4310
4311 if (config._locale.eraYearOrdinalParse) {
4312 array[YEAR] = config._locale.eraYearOrdinalParse(input, match);
4313 } else {
4314 array[YEAR] = parseInt(input, 10);
4315 }
4316 });
4317
4318 function localeEras(m, format) {
4319 var i,
4320 l,
4321 date,
4322 eras = this._eras || getLocale('en')._eras;
4323 for (i = 0, l = eras.length; i < l; ++i) {
4324 switch (typeof eras[i].since) {
4325 case 'string':
4326 // truncate time
4327 date = hooks(eras[i].since).startOf('day');
4328 eras[i].since = date.valueOf();
4329 break;
4330 }
4331
4332 switch (typeof eras[i].until) {
4333 case 'undefined':
4334 eras[i].until = +Infinity;
4335 break;
4336 case 'string':
4337 // truncate time
4338 date = hooks(eras[i].until).startOf('day').valueOf();
4339 eras[i].until = date.valueOf();
4340 break;
4341 }
4342 }
4343 return eras;
4344 }
4345
4346 function localeErasParse(eraName, format, strict) {
4347 var i,
4348 l,
4349 eras = this.eras(),
4350 name,
4351 abbr,
4352 narrow;
4353 eraName = eraName.toUpperCase();
4354
4355 for (i = 0, l = eras.length; i < l; ++i) {
4356 name = eras[i].name.toUpperCase();
4357 abbr = eras[i].abbr.toUpperCase();
4358 narrow = eras[i].narrow.toUpperCase();
4359
4360 if (strict) {
4361 switch (format) {
4362 case 'N':
4363 case 'NN':
4364 case 'NNN':
4365 if (abbr === eraName) {
4366 return eras[i];
4367 }
4368 break;
4369
4370 case 'NNNN':
4371 if (name === eraName) {
4372 return eras[i];
4373 }
4374 break;
4375
4376 case 'NNNNN':
4377 if (narrow === eraName) {
4378 return eras[i];
4379 }
4380 break;
4381 }
4382 } else if ([name, abbr, narrow].indexOf(eraName) >= 0) {
4383 return eras[i];
4384 }
4385 }
4386 }
4387
4388 function localeErasConvertYear(era, year) {
4389 var dir = era.since <= era.until ? +1 : -1;
4390 if (year === undefined) {
4391 return hooks(era.since).year();
4392 } else {
4393 return hooks(era.since).year() + (year - era.offset) * dir;
4394 }
4395 }
4396
4397 function getEraName() {
4398 var i,
4399 l,
4400 val,
4401 eras = this.localeData().eras();
4402 for (i = 0, l = eras.length; i < l; ++i) {
4403 // truncate time
4404 val = this.clone().startOf('day').valueOf();
4405
4406 if (eras[i].since <= val && val <= eras[i].until) {
4407 return eras[i].name;
4408 }
4409 if (eras[i].until <= val && val <= eras[i].since) {
4410 return eras[i].name;
4411 }
4412 }
4413
4414 return '';
4415 }
4416
4417 function getEraNarrow() {
4418 var i,
4419 l,
4420 val,
4421 eras = this.localeData().eras();
4422 for (i = 0, l = eras.length; i < l; ++i) {
4423 // truncate time
4424 val = this.clone().startOf('day').valueOf();
4425
4426 if (eras[i].since <= val && val <= eras[i].until) {
4427 return eras[i].narrow;
4428 }
4429 if (eras[i].until <= val && val <= eras[i].since) {
4430 return eras[i].narrow;
4431 }
4432 }
4433
4434 return '';
4435 }
4436
4437 function getEraAbbr() {
4438 var i,
4439 l,
4440 val,
4441 eras = this.localeData().eras();
4442 for (i = 0, l = eras.length; i < l; ++i) {
4443 // truncate time
4444 val = this.clone().startOf('day').valueOf();
4445
4446 if (eras[i].since <= val && val <= eras[i].until) {
4447 return eras[i].abbr;
4448 }
4449 if (eras[i].until <= val && val <= eras[i].since) {
4450 return eras[i].abbr;
4451 }
4452 }
4453
4454 return '';
4455 }
4456
4457 function getEraYear() {
4458 var i,
4459 l,
4460 dir,
4461 val,
4462 eras = this.localeData().eras();
4463 for (i = 0, l = eras.length; i < l; ++i) {
4464 dir = eras[i].since <= eras[i].until ? +1 : -1;
4465
4466 // truncate time
4467 val = this.clone().startOf('day').valueOf();
4468
4469 if (
4470 (eras[i].since <= val && val <= eras[i].until) ||
4471 (eras[i].until <= val && val <= eras[i].since)
4472 ) {
4473 return (
4474 (this.year() - hooks(eras[i].since).year()) * dir +
4475 eras[i].offset
4476 );
4477 }
4478 }
4479
4480 return this.year();
4481 }
4482
4483 function erasNameRegex(isStrict) {
4484 if (!hasOwnProp(this, '_erasNameRegex')) {
4485 computeErasParse.call(this);
4486 }
4487 return isStrict ? this._erasNameRegex : this._erasRegex;
4488 }
4489
4490 function erasAbbrRegex(isStrict) {
4491 if (!hasOwnProp(this, '_erasAbbrRegex')) {
4492 computeErasParse.call(this);
4493 }
4494 return isStrict ? this._erasAbbrRegex : this._erasRegex;
4495 }
4496
4497 function erasNarrowRegex(isStrict) {
4498 if (!hasOwnProp(this, '_erasNarrowRegex')) {
4499 computeErasParse.call(this);
4500 }
4501 return isStrict ? this._erasNarrowRegex : this._erasRegex;
4502 }
4503
4504 function matchEraAbbr(isStrict, locale) {
4505 return locale.erasAbbrRegex(isStrict);
4506 }
4507
4508 function matchEraName(isStrict, locale) {
4509 return locale.erasNameRegex(isStrict);
4510 }
4511
4512 function matchEraNarrow(isStrict, locale) {
4513 return locale.erasNarrowRegex(isStrict);
4514 }
4515
4516 function matchEraYearOrdinal(isStrict, locale) {
4517 return locale._eraYearOrdinalRegex || matchUnsigned;
4518 }
4519
4520 function computeErasParse() {
4521 var abbrPieces = [],
4522 namePieces = [],
4523 narrowPieces = [],
4524 mixedPieces = [],
4525 i,
4526 l,
4527 eras = this.eras();
4528
4529 for (i = 0, l = eras.length; i < l; ++i) {
4530 namePieces.push(regexEscape(eras[i].name));
4531 abbrPieces.push(regexEscape(eras[i].abbr));
4532 narrowPieces.push(regexEscape(eras[i].narrow));
4533
4534 mixedPieces.push(regexEscape(eras[i].name));
4535 mixedPieces.push(regexEscape(eras[i].abbr));
4536 mixedPieces.push(regexEscape(eras[i].narrow));
4537 }
4538
4539 this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
4540 this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i');
4541 this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i');
4542 this._erasNarrowRegex = new RegExp(
4543 '^(' + narrowPieces.join('|') + ')',
4544 'i'
4545 );
4546 }
4547
4548 // FORMATTING
4549
4550 addFormatToken(0, ['gg', 2], 0, function () {
4551 return this.weekYear() % 100;
4552 });
4553
4554 addFormatToken(0, ['GG', 2], 0, function () {
4555 return this.isoWeekYear() % 100;
4556 });
4557
4558 function addWeekYearFormatToken(token, getter) {
4559 addFormatToken(0, [token, token.length], 0, getter);
4560 }
4561
4562 addWeekYearFormatToken('gggg', 'weekYear');
4563 addWeekYearFormatToken('ggggg', 'weekYear');
4564 addWeekYearFormatToken('GGGG', 'isoWeekYear');
4565 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
4566
4567 // ALIASES
4568
4569 addUnitAlias('weekYear', 'gg');
4570 addUnitAlias('isoWeekYear', 'GG');
4571
4572 // PRIORITY
4573
4574 addUnitPriority('weekYear', 1);
4575 addUnitPriority('isoWeekYear', 1);
4576
4577 // PARSING
4578
4579 addRegexToken('G', matchSigned);
4580 addRegexToken('g', matchSigned);
4581 addRegexToken('GG', match1to2, match2);
4582 addRegexToken('gg', match1to2, match2);
4583 addRegexToken('GGGG', match1to4, match4);
4584 addRegexToken('gggg', match1to4, match4);
4585 addRegexToken('GGGGG', match1to6, match6);
4586 addRegexToken('ggggg', match1to6, match6);
4587
4588 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (
4589 input,
4590 week,
4591 config,
4592 token
4593 ) {
4594 week[token.substr(0, 2)] = toInt(input);
4595 });
4596
4597 addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
4598 week[token] = hooks.parseTwoDigitYear(input);
4599 });
4600
4601 // MOMENTS
4602
4603 function getSetWeekYear(input) {
4604 return getSetWeekYearHelper.call(
4605 this,
4606 input,
4607 this.week(),
4608 this.weekday(),
4609 this.localeData()._week.dow,
4610 this.localeData()._week.doy
4611 );
4612 }
4613
4614 function getSetISOWeekYear(input) {
4615 return getSetWeekYearHelper.call(
4616 this,
4617 input,
4618 this.isoWeek(),
4619 this.isoWeekday(),
4620 1,
4621 4
4622 );
4623 }
4624
4625 function getISOWeeksInYear() {
4626 return weeksInYear(this.year(), 1, 4);
4627 }
4628
4629 function getISOWeeksInISOWeekYear() {
4630 return weeksInYear(this.isoWeekYear(), 1, 4);
4631 }
4632
4633 function getWeeksInYear() {
4634 var weekInfo = this.localeData()._week;
4635 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
4636 }
4637
4638 function getWeeksInWeekYear() {
4639 var weekInfo = this.localeData()._week;
4640 return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
4641 }
4642
4643 function getSetWeekYearHelper(input, week, weekday, dow, doy) {
4644 var weeksTarget;
4645 if (input == null) {
4646 return weekOfYear(this, dow, doy).year;
4647 } else {
4648 weeksTarget = weeksInYear(input, dow, doy);
4649 if (week > weeksTarget) {
4650 week = weeksTarget;
4651 }
4652 return setWeekAll.call(this, input, week, weekday, dow, doy);
4653 }
4654 }
4655
4656 function setWeekAll(weekYear, week, weekday, dow, doy) {
4657 var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
4658 date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
4659
4660 this.year(date.getUTCFullYear());
4661 this.month(date.getUTCMonth());
4662 this.date(date.getUTCDate());
4663 return this;
4664 }
4665
4666 // FORMATTING
4667
4668 addFormatToken('Q', 0, 'Qo', 'quarter');
4669
4670 // ALIASES
4671
4672 addUnitAlias('quarter', 'Q');
4673
4674 // PRIORITY
4675
4676 addUnitPriority('quarter', 7);
4677
4678 // PARSING
4679
4680 addRegexToken('Q', match1);
4681 addParseToken('Q', function (input, array) {
4682 array[MONTH] = (toInt(input) - 1) * 3;
4683 });
4684
4685 // MOMENTS
4686
4687 function getSetQuarter(input) {
4688 return input == null
4689 ? Math.ceil((this.month() + 1) / 3)
4690 : this.month((input - 1) * 3 + (this.month() % 3));
4691 }
4692
4693 // FORMATTING
4694
4695 addFormatToken('D', ['DD', 2], 'Do', 'date');
4696
4697 // ALIASES
4698
4699 addUnitAlias('date', 'D');
4700
4701 // PRIORITY
4702 addUnitPriority('date', 9);
4703
4704 // PARSING
4705
4706 addRegexToken('D', match1to2);
4707 addRegexToken('DD', match1to2, match2);
4708 addRegexToken('Do', function (isStrict, locale) {
4709 // TODO: Remove "ordinalParse" fallback in next major release.
4710 return isStrict
4711 ? locale._dayOfMonthOrdinalParse || locale._ordinalParse
4712 : locale._dayOfMonthOrdinalParseLenient;
4713 });
4714
4715 addParseToken(['D', 'DD'], DATE);
4716 addParseToken('Do', function (input, array) {
4717 array[DATE] = toInt(input.match(match1to2)[0]);
4718 });
4719
4720 // MOMENTS
4721
4722 var getSetDayOfMonth = makeGetSet('Date', true);
4723
4724 // FORMATTING
4725
4726 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
4727
4728 // ALIASES
4729
4730 addUnitAlias('dayOfYear', 'DDD');
4731
4732 // PRIORITY
4733 addUnitPriority('dayOfYear', 4);
4734
4735 // PARSING
4736
4737 addRegexToken('DDD', match1to3);
4738 addRegexToken('DDDD', match3);
4739 addParseToken(['DDD', 'DDDD'], function (input, array, config) {
4740 config._dayOfYear = toInt(input);
4741 });
4742
4743 // HELPERS
4744
4745 // MOMENTS
4746
4747 function getSetDayOfYear(input) {
4748 var dayOfYear =
4749 Math.round(
4750 (this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
4751 ) + 1;
4752 return input == null ? dayOfYear : this.add(input - dayOfYear, 'd');
4753 }
4754
4755 // FORMATTING
4756
4757 addFormatToken('m', ['mm', 2], 0, 'minute');
4758
4759 // ALIASES
4760
4761 addUnitAlias('minute', 'm');
4762
4763 // PRIORITY
4764
4765 addUnitPriority('minute', 14);
4766
4767 // PARSING
4768
4769 addRegexToken('m', match1to2);
4770 addRegexToken('mm', match1to2, match2);
4771 addParseToken(['m', 'mm'], MINUTE);
4772
4773 // MOMENTS
4774
4775 var getSetMinute = makeGetSet('Minutes', false);
4776
4777 // FORMATTING
4778
4779 addFormatToken('s', ['ss', 2], 0, 'second');
4780
4781 // ALIASES
4782
4783 addUnitAlias('second', 's');
4784
4785 // PRIORITY
4786
4787 addUnitPriority('second', 15);
4788
4789 // PARSING
4790
4791 addRegexToken('s', match1to2);
4792 addRegexToken('ss', match1to2, match2);
4793 addParseToken(['s', 'ss'], SECOND);
4794
4795 // MOMENTS
4796
4797 var getSetSecond = makeGetSet('Seconds', false);
4798
4799 // FORMATTING
4800
4801 addFormatToken('S', 0, 0, function () {
4802 return ~~(this.millisecond() / 100);
4803 });
4804
4805 addFormatToken(0, ['SS', 2], 0, function () {
4806 return ~~(this.millisecond() / 10);
4807 });
4808
4809 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
4810 addFormatToken(0, ['SSSS', 4], 0, function () {
4811 return this.millisecond() * 10;
4812 });
4813 addFormatToken(0, ['SSSSS', 5], 0, function () {
4814 return this.millisecond() * 100;
4815 });
4816 addFormatToken(0, ['SSSSSS', 6], 0, function () {
4817 return this.millisecond() * 1000;
4818 });
4819 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
4820 return this.millisecond() * 10000;
4821 });
4822 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
4823 return this.millisecond() * 100000;
4824 });
4825 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
4826 return this.millisecond() * 1000000;
4827 });
4828
4829 // ALIASES
4830
4831 addUnitAlias('millisecond', 'ms');
4832
4833 // PRIORITY
4834
4835 addUnitPriority('millisecond', 16);
4836
4837 // PARSING
4838
4839 addRegexToken('S', match1to3, match1);
4840 addRegexToken('SS', match1to3, match2);
4841 addRegexToken('SSS', match1to3, match3);
4842
4843 var token, getSetMillisecond;
4844 for (token = 'SSSS'; token.length <= 9; token += 'S') {
4845 addRegexToken(token, matchUnsigned);
4846 }
4847
4848 function parseMs(input, array) {
4849 array[MILLISECOND] = toInt(('0.' + input) * 1000);
4850 }
4851
4852 for (token = 'S'; token.length <= 9; token += 'S') {
4853 addParseToken(token, parseMs);
4854 }
4855
4856 getSetMillisecond = makeGetSet('Milliseconds', false);
4857
4858 // FORMATTING
4859
4860 addFormatToken('z', 0, 0, 'zoneAbbr');
4861 addFormatToken('zz', 0, 0, 'zoneName');
4862
4863 // MOMENTS
4864
4865 function getZoneAbbr() {
4866 return this._isUTC ? 'UTC' : '';
4867 }
4868
4869 function getZoneName() {
4870 return this._isUTC ? 'Coordinated Universal Time' : '';
4871 }
4872
4873 var proto = Moment.prototype;
4874
4875 proto.add = add;
4876 proto.calendar = calendar$1;
4877 proto.clone = clone;
4878 proto.diff = diff;
4879 proto.endOf = endOf;
4880 proto.format = format;
4881 proto.from = from;
4882 proto.fromNow = fromNow;
4883 proto.to = to;
4884 proto.toNow = toNow;
4885 proto.get = stringGet;
4886 proto.invalidAt = invalidAt;
4887 proto.isAfter = isAfter;
4888 proto.isBefore = isBefore;
4889 proto.isBetween = isBetween;
4890 proto.isSame = isSame;
4891 proto.isSameOrAfter = isSameOrAfter;
4892 proto.isSameOrBefore = isSameOrBefore;
4893 proto.isValid = isValid$2;
4894 proto.lang = lang;
4895 proto.locale = locale;
4896 proto.localeData = localeData;
4897 proto.max = prototypeMax;
4898 proto.min = prototypeMin;
4899 proto.parsingFlags = parsingFlags;
4900 proto.set = stringSet;
4901 proto.startOf = startOf;
4902 proto.subtract = subtract;
4903 proto.toArray = toArray;
4904 proto.toObject = toObject;
4905 proto.toDate = toDate;
4906 proto.toISOString = toISOString;
4907 proto.inspect = inspect;
4908 if (typeof Symbol !== 'undefined' && Symbol.for != null) {
4909 proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
4910 return 'Moment<' + this.format() + '>';
4911 };
4912 }
4913 proto.toJSON = toJSON;
4914 proto.toString = toString;
4915 proto.unix = unix;
4916 proto.valueOf = valueOf;
4917 proto.creationData = creationData;
4918 proto.eraName = getEraName;
4919 proto.eraNarrow = getEraNarrow;
4920 proto.eraAbbr = getEraAbbr;
4921 proto.eraYear = getEraYear;
4922 proto.year = getSetYear;
4923 proto.isLeapYear = getIsLeapYear;
4924 proto.weekYear = getSetWeekYear;
4925 proto.isoWeekYear = getSetISOWeekYear;
4926 proto.quarter = proto.quarters = getSetQuarter;
4927 proto.month = getSetMonth;
4928 proto.daysInMonth = getDaysInMonth;
4929 proto.week = proto.weeks = getSetWeek;
4930 proto.isoWeek = proto.isoWeeks = getSetISOWeek;
4931 proto.weeksInYear = getWeeksInYear;
4932 proto.weeksInWeekYear = getWeeksInWeekYear;
4933 proto.isoWeeksInYear = getISOWeeksInYear;
4934 proto.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear;
4935 proto.date = getSetDayOfMonth;
4936 proto.day = proto.days = getSetDayOfWeek;
4937 proto.weekday = getSetLocaleDayOfWeek;
4938 proto.isoWeekday = getSetISODayOfWeek;
4939 proto.dayOfYear = getSetDayOfYear;
4940 proto.hour = proto.hours = getSetHour;
4941 proto.minute = proto.minutes = getSetMinute;
4942 proto.second = proto.seconds = getSetSecond;
4943 proto.millisecond = proto.milliseconds = getSetMillisecond;
4944 proto.utcOffset = getSetOffset;
4945 proto.utc = setOffsetToUTC;
4946 proto.local = setOffsetToLocal;
4947 proto.parseZone = setOffsetToParsedOffset;
4948 proto.hasAlignedHourOffset = hasAlignedHourOffset;
4949 proto.isDST = isDaylightSavingTime;
4950 proto.isLocal = isLocal;
4951 proto.isUtcOffset = isUtcOffset;
4952 proto.isUtc = isUtc;
4953 proto.isUTC = isUtc;
4954 proto.zoneAbbr = getZoneAbbr;
4955 proto.zoneName = getZoneName;
4956 proto.dates = deprecate(
4957 'dates accessor is deprecated. Use date instead.',
4958 getSetDayOfMonth
4959 );
4960 proto.months = deprecate(
4961 'months accessor is deprecated. Use month instead',
4962 getSetMonth
4963 );
4964 proto.years = deprecate(
4965 'years accessor is deprecated. Use year instead',
4966 getSetYear
4967 );
4968 proto.zone = deprecate(
4969 'moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',
4970 getSetZone
4971 );
4972 proto.isDSTShifted = deprecate(
4973 'isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',
4974 isDaylightSavingTimeShifted
4975 );
4976
4977 function createUnix(input) {
4978 return createLocal(input * 1000);
4979 }
4980
4981 function createInZone() {
4982 return createLocal.apply(null, arguments).parseZone();
4983 }
4984
4985 function preParsePostFormat(string) {
4986 return string;
4987 }
4988
4989 var proto$1 = Locale.prototype;
4990
4991 proto$1.calendar = calendar;
4992 proto$1.longDateFormat = longDateFormat;
4993 proto$1.invalidDate = invalidDate;
4994 proto$1.ordinal = ordinal;
4995 proto$1.preparse = preParsePostFormat;
4996 proto$1.postformat = preParsePostFormat;
4997 proto$1.relativeTime = relativeTime;
4998 proto$1.pastFuture = pastFuture;
4999 proto$1.set = set;
5000 proto$1.eras = localeEras;
5001 proto$1.erasParse = localeErasParse;
5002 proto$1.erasConvertYear = localeErasConvertYear;
5003 proto$1.erasAbbrRegex = erasAbbrRegex;
5004 proto$1.erasNameRegex = erasNameRegex;
5005 proto$1.erasNarrowRegex = erasNarrowRegex;
5006
5007 proto$1.months = localeMonths;
5008 proto$1.monthsShort = localeMonthsShort;
5009 proto$1.monthsParse = localeMonthsParse;
5010 proto$1.monthsRegex = monthsRegex;
5011 proto$1.monthsShortRegex = monthsShortRegex;
5012 proto$1.week = localeWeek;
5013 proto$1.firstDayOfYear = localeFirstDayOfYear;
5014 proto$1.firstDayOfWeek = localeFirstDayOfWeek;
5015
5016 proto$1.weekdays = localeWeekdays;
5017 proto$1.weekdaysMin = localeWeekdaysMin;
5018 proto$1.weekdaysShort = localeWeekdaysShort;
5019 proto$1.weekdaysParse = localeWeekdaysParse;
5020
5021 proto$1.weekdaysRegex = weekdaysRegex;
5022 proto$1.weekdaysShortRegex = weekdaysShortRegex;
5023 proto$1.weekdaysMinRegex = weekdaysMinRegex;
5024
5025 proto$1.isPM = localeIsPM;
5026 proto$1.meridiem = localeMeridiem;
5027
5028 function get$1(format, index, field, setter) {
5029 var locale = getLocale(),
5030 utc = createUTC().set(setter, index);
5031 return locale[field](utc, format);
5032 }
5033
5034 function listMonthsImpl(format, index, field) {
5035 if (isNumber(format)) {
5036 index = format;
5037 format = undefined;
5038 }
5039
5040 format = format || '';
5041
5042 if (index != null) {
5043 return get$1(format, index, field, 'month');
5044 }
5045
5046 var i,
5047 out = [];
5048 for (i = 0; i < 12; i++) {
5049 out[i] = get$1(format, i, field, 'month');
5050 }
5051 return out;
5052 }
5053
5054 // ()
5055 // (5)
5056 // (fmt, 5)
5057 // (fmt)
5058 // (true)
5059 // (true, 5)
5060 // (true, fmt, 5)
5061 // (true, fmt)
5062 function listWeekdaysImpl(localeSorted, format, index, field) {
5063 if (typeof localeSorted === 'boolean') {
5064 if (isNumber(format)) {
5065 index = format;
5066 format = undefined;
5067 }
5068
5069 format = format || '';
5070 } else {
5071 format = localeSorted;
5072 index = format;
5073 localeSorted = false;
5074
5075 if (isNumber(format)) {
5076 index = format;
5077 format = undefined;
5078 }
5079
5080 format = format || '';
5081 }
5082
5083 var locale = getLocale(),
5084 shift = localeSorted ? locale._week.dow : 0,
5085 i,
5086 out = [];
5087
5088 if (index != null) {
5089 return get$1(format, (index + shift) % 7, field, 'day');
5090 }
5091
5092 for (i = 0; i < 7; i++) {
5093 out[i] = get$1(format, (i + shift) % 7, field, 'day');
5094 }
5095 return out;
5096 }
5097
5098 function listMonths(format, index) {
5099 return listMonthsImpl(format, index, 'months');
5100 }
5101
5102 function listMonthsShort(format, index) {
5103 return listMonthsImpl(format, index, 'monthsShort');
5104 }
5105
5106 function listWeekdays(localeSorted, format, index) {
5107 return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
5108 }
5109
5110 function listWeekdaysShort(localeSorted, format, index) {
5111 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
5112 }
5113
5114 function listWeekdaysMin(localeSorted, format, index) {
5115 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
5116 }
5117
5118 getSetGlobalLocale('en', {
5119 eras: [
5120 {
5121 since: '0001-01-01',
5122 until: +Infinity,
5123 offset: 1,
5124 name: 'Anno Domini',
5125 narrow: 'AD',
5126 abbr: 'AD',
5127 },
5128 {
5129 since: '0000-12-31',
5130 until: -Infinity,
5131 offset: 1,
5132 name: 'Before Christ',
5133 narrow: 'BC',
5134 abbr: 'BC',
5135 },
5136 ],
5137 dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
5138 ordinal: function (number) {
5139 var b = number % 10,
5140 output =
5141 toInt((number % 100) / 10) === 1
5142 ? 'th'
5143 : b === 1
5144 ? 'st'
5145 : b === 2
5146 ? 'nd'
5147 : b === 3
5148 ? 'rd'
5149 : 'th';
5150 return number + output;
5151 },
5152 });
5153
5154 // Side effect imports
5155
5156 hooks.lang = deprecate(
5157 'moment.lang is deprecated. Use moment.locale instead.',
5158 getSetGlobalLocale
5159 );
5160 hooks.langData = deprecate(
5161 'moment.langData is deprecated. Use moment.localeData instead.',
5162 getLocale
5163 );
5164
5165 var mathAbs = Math.abs;
5166
5167 function abs() {
5168 var data = this._data;
5169
5170 this._milliseconds = mathAbs(this._milliseconds);
5171 this._days = mathAbs(this._days);
5172 this._months = mathAbs(this._months);
5173
5174 data.milliseconds = mathAbs(data.milliseconds);
5175 data.seconds = mathAbs(data.seconds);
5176 data.minutes = mathAbs(data.minutes);
5177 data.hours = mathAbs(data.hours);
5178 data.months = mathAbs(data.months);
5179 data.years = mathAbs(data.years);
5180
5181 return this;
5182 }
5183
5184 function addSubtract$1(duration, input, value, direction) {
5185 var other = createDuration(input, value);
5186
5187 duration._milliseconds += direction * other._milliseconds;
5188 duration._days += direction * other._days;
5189 duration._months += direction * other._months;
5190
5191 return duration._bubble();
5192 }
5193
5194 // supports only 2.0-style add(1, 's') or add(duration)
5195 function add$1(input, value) {
5196 return addSubtract$1(this, input, value, 1);
5197 }
5198
5199 // supports only 2.0-style subtract(1, 's') or subtract(duration)
5200 function subtract$1(input, value) {
5201 return addSubtract$1(this, input, value, -1);
5202 }
5203
5204 function absCeil(number) {
5205 if (number < 0) {
5206 return Math.floor(number);
5207 } else {
5208 return Math.ceil(number);
5209 }
5210 }
5211
5212 function bubble() {
5213 var milliseconds = this._milliseconds,
5214 days = this._days,
5215 months = this._months,
5216 data = this._data,
5217 seconds,
5218 minutes,
5219 hours,
5220 years,
5221 monthsFromDays;
5222
5223 // if we have a mix of positive and negative values, bubble down first
5224 // check: https://github.com/moment/moment/issues/2166
5225 if (
5226 !(
5227 (milliseconds >= 0 && days >= 0 && months >= 0) ||
5228 (milliseconds <= 0 && days <= 0 && months <= 0)
5229 )
5230 ) {
5231 milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
5232 days = 0;
5233 months = 0;
5234 }
5235
5236 // The following code bubbles up values, see the tests for
5237 // examples of what that means.
5238 data.milliseconds = milliseconds % 1000;
5239
5240 seconds = absFloor(milliseconds / 1000);
5241 data.seconds = seconds % 60;
5242
5243 minutes = absFloor(seconds / 60);
5244 data.minutes = minutes % 60;
5245
5246 hours = absFloor(minutes / 60);
5247 data.hours = hours % 24;
5248
5249 days += absFloor(hours / 24);
5250
5251 // convert days to months
5252 monthsFromDays = absFloor(daysToMonths(days));
5253 months += monthsFromDays;
5254 days -= absCeil(monthsToDays(monthsFromDays));
5255
5256 // 12 months -> 1 year
5257 years = absFloor(months / 12);
5258 months %= 12;
5259
5260 data.days = days;
5261 data.months = months;
5262 data.years = years;
5263
5264 return this;
5265 }
5266
5267 function daysToMonths(days) {
5268 // 400 years have 146097 days (taking into account leap year rules)
5269 // 400 years have 12 months === 4800
5270 return (days * 4800) / 146097;
5271 }
5272
5273 function monthsToDays(months) {
5274 // the reverse of daysToMonths
5275 return (months * 146097) / 4800;
5276 }
5277
5278 function as(units) {
5279 if (!this.isValid()) {
5280 return NaN;
5281 }
5282 var days,
5283 months,
5284 milliseconds = this._milliseconds;
5285
5286 units = normalizeUnits(units);
5287
5288 if (units === 'month' || units === 'quarter' || units === 'year') {
5289 days = this._days + milliseconds / 864e5;
5290 months = this._months + daysToMonths(days);
5291 switch (units) {
5292 case 'month':
5293 return months;
5294 case 'quarter':
5295 return months / 3;
5296 case 'year':
5297 return months / 12;
5298 }
5299 } else {
5300 // handle milliseconds separately because of floating point math errors (issue #1867)
5301 days = this._days + Math.round(monthsToDays(this._months));
5302 switch (units) {
5303 case 'week':
5304 return days / 7 + milliseconds / 6048e5;
5305 case 'day':
5306 return days + milliseconds / 864e5;
5307 case 'hour':
5308 return days * 24 + milliseconds / 36e5;
5309 case 'minute':
5310 return days * 1440 + milliseconds / 6e4;
5311 case 'second':
5312 return days * 86400 + milliseconds / 1000;
5313 // Math.floor prevents floating point math errors here
5314 case 'millisecond':
5315 return Math.floor(days * 864e5) + milliseconds;
5316 default:
5317 throw new Error('Unknown unit ' + units);
5318 }
5319 }
5320 }
5321
5322 // TODO: Use this.as('ms')?
5323 function valueOf$1() {
5324 if (!this.isValid()) {
5325 return NaN;
5326 }
5327 return (
5328 this._milliseconds +
5329 this._days * 864e5 +
5330 (this._months % 12) * 2592e6 +
5331 toInt(this._months / 12) * 31536e6
5332 );
5333 }
5334
5335 function makeAs(alias) {
5336 return function () {
5337 return this.as(alias);
5338 };
5339 }
5340
5341 var asMilliseconds = makeAs('ms'),
5342 asSeconds = makeAs('s'),
5343 asMinutes = makeAs('m'),
5344 asHours = makeAs('h'),
5345 asDays = makeAs('d'),
5346 asWeeks = makeAs('w'),
5347 asMonths = makeAs('M'),
5348 asQuarters = makeAs('Q'),
5349 asYears = makeAs('y');
5350
5351 function clone$1() {
5352 return createDuration(this);
5353 }
5354
5355 function get$2(units) {
5356 units = normalizeUnits(units);
5357 return this.isValid() ? this[units + 's']() : NaN;
5358 }
5359
5360 function makeGetter(name) {
5361 return function () {
5362 return this.isValid() ? this._data[name] : NaN;
5363 };
5364 }
5365
5366 var milliseconds = makeGetter('milliseconds'),
5367 seconds = makeGetter('seconds'),
5368 minutes = makeGetter('minutes'),
5369 hours = makeGetter('hours'),
5370 days = makeGetter('days'),
5371 months = makeGetter('months'),
5372 years = makeGetter('years');
5373
5374 function weeks() {
5375 return absFloor(this.days() / 7);
5376 }
5377
5378 var round = Math.round,
5379 thresholds = {
5380 ss: 44, // a few seconds to seconds
5381 s: 45, // seconds to minute
5382 m: 45, // minutes to hour
5383 h: 22, // hours to day
5384 d: 26, // days to month/week
5385 w: null, // weeks to month
5386 M: 11, // months to year
5387 };
5388
5389 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
5390 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
5391 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
5392 }
5393
5394 function relativeTime$1(posNegDuration, withoutSuffix, thresholds, locale) {
5395 var duration = createDuration(posNegDuration).abs(),
5396 seconds = round(duration.as('s')),
5397 minutes = round(duration.as('m')),
5398 hours = round(duration.as('h')),
5399 days = round(duration.as('d')),
5400 months = round(duration.as('M')),
5401 weeks = round(duration.as('w')),
5402 years = round(duration.as('y')),
5403 a =
5404 (seconds <= thresholds.ss && ['s', seconds]) ||
5405 (seconds < thresholds.s && ['ss', seconds]) ||
5406 (minutes <= 1 && ['m']) ||
5407 (minutes < thresholds.m && ['mm', minutes]) ||
5408 (hours <= 1 && ['h']) ||
5409 (hours < thresholds.h && ['hh', hours]) ||
5410 (days <= 1 && ['d']) ||
5411 (days < thresholds.d && ['dd', days]);
5412
5413 if (thresholds.w != null) {
5414 a =
5415 a ||
5416 (weeks <= 1 && ['w']) ||
5417 (weeks < thresholds.w && ['ww', weeks]);
5418 }
5419 a = a ||
5420 (months <= 1 && ['M']) ||
5421 (months < thresholds.M && ['MM', months]) ||
5422 (years <= 1 && ['y']) || ['yy', years];
5423
5424 a[2] = withoutSuffix;
5425 a[3] = +posNegDuration > 0;
5426 a[4] = locale;
5427 return substituteTimeAgo.apply(null, a);
5428 }
5429
5430 // This function allows you to set the rounding function for relative time strings
5431 function getSetRelativeTimeRounding(roundingFunction) {
5432 if (roundingFunction === undefined) {
5433 return round;
5434 }
5435 if (typeof roundingFunction === 'function') {
5436 round = roundingFunction;
5437 return true;
5438 }
5439 return false;
5440 }
5441
5442 // This function allows you to set a threshold for relative time strings
5443 function getSetRelativeTimeThreshold(threshold, limit) {
5444 if (thresholds[threshold] === undefined) {
5445 return false;
5446 }
5447 if (limit === undefined) {
5448 return thresholds[threshold];
5449 }
5450 thresholds[threshold] = limit;
5451 if (threshold === 's') {
5452 thresholds.ss = limit - 1;
5453 }
5454 return true;
5455 }
5456
5457 function humanize(argWithSuffix, argThresholds) {
5458 if (!this.isValid()) {
5459 return this.localeData().invalidDate();
5460 }
5461
5462 var withSuffix = false,
5463 th = thresholds,
5464 locale,
5465 output;
5466
5467 if (typeof argWithSuffix === 'object') {
5468 argThresholds = argWithSuffix;
5469 argWithSuffix = false;
5470 }
5471 if (typeof argWithSuffix === 'boolean') {
5472 withSuffix = argWithSuffix;
5473 }
5474 if (typeof argThresholds === 'object') {
5475 th = Object.assign({}, thresholds, argThresholds);
5476 if (argThresholds.s != null && argThresholds.ss == null) {
5477 th.ss = argThresholds.s - 1;
5478 }
5479 }
5480
5481 locale = this.localeData();
5482 output = relativeTime$1(this, !withSuffix, th, locale);
5483
5484 if (withSuffix) {
5485 output = locale.pastFuture(+this, output);
5486 }
5487
5488 return locale.postformat(output);
5489 }
5490
5491 var abs$1 = Math.abs;
5492
5493 function sign(x) {
5494 return (x > 0) - (x < 0) || +x;
5495 }
5496
5497 function toISOString$1() {
5498 // for ISO strings we do not use the normal bubbling rules:
5499 // * milliseconds bubble up until they become hours
5500 // * days do not bubble at all
5501 // * months bubble up until they become years
5502 // This is because there is no context-free conversion between hours and days
5503 // (think of clock changes)
5504 // and also not between days and months (28-31 days per month)
5505 if (!this.isValid()) {
5506 return this.localeData().invalidDate();
5507 }
5508
5509 var seconds = abs$1(this._milliseconds) / 1000,
5510 days = abs$1(this._days),
5511 months = abs$1(this._months),
5512 minutes,
5513 hours,
5514 years,
5515 s,
5516 total = this.asSeconds(),
5517 totalSign,
5518 ymSign,
5519 daysSign,
5520 hmsSign;
5521
5522 if (!total) {
5523 // this is the same as C#'s (Noda) and python (isodate)...
5524 // but not other JS (goog.date)
5525 return 'P0D';
5526 }
5527
5528 // 3600 seconds -> 60 minutes -> 1 hour
5529 minutes = absFloor(seconds / 60);
5530 hours = absFloor(minutes / 60);
5531 seconds %= 60;
5532 minutes %= 60;
5533
5534 // 12 months -> 1 year
5535 years = absFloor(months / 12);
5536 months %= 12;
5537
5538 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
5539 s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
5540
5541 totalSign = total < 0 ? '-' : '';
5542 ymSign = sign(this._months) !== sign(total) ? '-' : '';
5543 daysSign = sign(this._days) !== sign(total) ? '-' : '';
5544 hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
5545
5546 return (
5547 totalSign +
5548 'P' +
5549 (years ? ymSign + years + 'Y' : '') +
5550 (months ? ymSign + months + 'M' : '') +
5551 (days ? daysSign + days + 'D' : '') +
5552 (hours || minutes || seconds ? 'T' : '') +
5553 (hours ? hmsSign + hours + 'H' : '') +
5554 (minutes ? hmsSign + minutes + 'M' : '') +
5555 (seconds ? hmsSign + s + 'S' : '')
5556 );
5557 }
5558
5559 var proto$2 = Duration.prototype;
5560
5561 proto$2.isValid = isValid$1;
5562 proto$2.abs = abs;
5563 proto$2.add = add$1;
5564 proto$2.subtract = subtract$1;
5565 proto$2.as = as;
5566 proto$2.asMilliseconds = asMilliseconds;
5567 proto$2.asSeconds = asSeconds;
5568 proto$2.asMinutes = asMinutes;
5569 proto$2.asHours = asHours;
5570 proto$2.asDays = asDays;
5571 proto$2.asWeeks = asWeeks;
5572 proto$2.asMonths = asMonths;
5573 proto$2.asQuarters = asQuarters;
5574 proto$2.asYears = asYears;
5575 proto$2.valueOf = valueOf$1;
5576 proto$2._bubble = bubble;
5577 proto$2.clone = clone$1;
5578 proto$2.get = get$2;
5579 proto$2.milliseconds = milliseconds;
5580 proto$2.seconds = seconds;
5581 proto$2.minutes = minutes;
5582 proto$2.hours = hours;
5583 proto$2.days = days;
5584 proto$2.weeks = weeks;
5585 proto$2.months = months;
5586 proto$2.years = years;
5587 proto$2.humanize = humanize;
5588 proto$2.toISOString = toISOString$1;
5589 proto$2.toString = toISOString$1;
5590 proto$2.toJSON = toISOString$1;
5591 proto$2.locale = locale;
5592 proto$2.localeData = localeData;
5593
5594 proto$2.toIsoString = deprecate(
5595 'toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',
5596 toISOString$1
5597 );
5598 proto$2.lang = lang;
5599
5600 // FORMATTING
5601
5602 addFormatToken('X', 0, 0, 'unix');
5603 addFormatToken('x', 0, 0, 'valueOf');
5604
5605 // PARSING
5606
5607 addRegexToken('x', matchSigned);
5608 addRegexToken('X', matchTimestamp);
5609 addParseToken('X', function (input, array, config) {
5610 config._d = new Date(parseFloat(input) * 1000);
5611 });
5612 addParseToken('x', function (input, array, config) {
5613 config._d = new Date(toInt(input));
5614 });
5615
5616 //! moment.js
5617
5618 hooks.version = '2.29.0';
5619
5620 setHookCallback(createLocal);
5621
5622 hooks.fn = proto;
5623 hooks.min = min;
5624 hooks.max = max;
5625 hooks.now = now;
5626 hooks.utc = createUTC;
5627 hooks.unix = createUnix;
5628 hooks.months = listMonths;
5629 hooks.isDate = isDate;
5630 hooks.locale = getSetGlobalLocale;
5631 hooks.invalid = createInvalid;
5632 hooks.duration = createDuration;
5633 hooks.isMoment = isMoment;
5634 hooks.weekdays = listWeekdays;
5635 hooks.parseZone = createInZone;
5636 hooks.localeData = getLocale;
5637 hooks.isDuration = isDuration;
5638 hooks.monthsShort = listMonthsShort;
5639 hooks.weekdaysMin = listWeekdaysMin;
5640 hooks.defineLocale = defineLocale;
5641 hooks.updateLocale = updateLocale;
5642 hooks.locales = listLocales;
5643 hooks.weekdaysShort = listWeekdaysShort;
5644 hooks.normalizeUnits = normalizeUnits;
5645 hooks.relativeTimeRounding = getSetRelativeTimeRounding;
5646 hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
5647 hooks.calendarFormat = getCalendarFormat;
5648 hooks.prototype = proto;
5649
5650 // currently HTML5 input type only supports 24-hour formats
5651 hooks.HTML5_FMT = {
5652 DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
5653 DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
5654 DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
5655 DATE: 'YYYY-MM-DD', // <input type="date" />
5656 TIME: 'HH:mm', // <input type="time" />
5657 TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
5658 TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
5659 WEEK: 'GGGG-[W]WW', // <input type="week" />
5660 MONTH: 'YYYY-MM', // <input type="month" />
5661 };
5662
5663 export default hooks;