blob: ed94e44a1e158e5cc5d752ac873c6de58c5baa66 [file] [log] [blame]
Dirk Vogt5c448042017-12-06 10:42:28 +01001//! moment.js
2//! version : 2.13.0
3//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
4//! license : MIT
5//! momentjs.com
6
7;(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9 typeof define === 'function' && define.amd ? define(factory) :
10 global.moment = factory()
11}(this, function () { 'use strict';
12
13 var hookCallback;
14
15 function utils_hooks__hooks () {
16 return hookCallback.apply(null, arguments);
17 }
18
19 // This is done to register the method called with moment()
20 // without creating circular dependencies.
21 function setHookCallback (callback) {
22 hookCallback = callback;
23 }
24
25 function isArray(input) {
26 return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
27 }
28
29 function isDate(input) {
30 return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
31 }
32
33 function map(arr, fn) {
34 var res = [], i;
35 for (i = 0; i < arr.length; ++i) {
36 res.push(fn(arr[i], i));
37 }
38 return res;
39 }
40
41 function hasOwnProp(a, b) {
42 return Object.prototype.hasOwnProperty.call(a, b);
43 }
44
45 function extend(a, b) {
46 for (var i in b) {
47 if (hasOwnProp(b, i)) {
48 a[i] = b[i];
49 }
50 }
51
52 if (hasOwnProp(b, 'toString')) {
53 a.toString = b.toString;
54 }
55
56 if (hasOwnProp(b, 'valueOf')) {
57 a.valueOf = b.valueOf;
58 }
59
60 return a;
61 }
62
63 function create_utc__createUTC (input, format, locale, strict) {
64 return createLocalOrUTC(input, format, locale, strict, true).utc();
65 }
66
67 function defaultParsingFlags() {
68 // We need to deep clone this object.
69 return {
70 empty : false,
71 unusedTokens : [],
72 unusedInput : [],
73 overflow : -2,
74 charsLeftOver : 0,
75 nullInput : false,
76 invalidMonth : null,
77 invalidFormat : false,
78 userInvalidated : false,
79 iso : false,
80 parsedDateParts : [],
81 meridiem : null
82 };
83 }
84
85 function getParsingFlags(m) {
86 if (m._pf == null) {
87 m._pf = defaultParsingFlags();
88 }
89 return m._pf;
90 }
91
92 var some;
93 if (Array.prototype.some) {
94 some = Array.prototype.some;
95 } else {
96 some = function (fun) {
97 var t = Object(this);
98 var len = t.length >>> 0;
99
100 for (var i = 0; i < len; i++) {
101 if (i in t && fun.call(this, t[i], i, t)) {
102 return true;
103 }
104 }
105
106 return false;
107 };
108 }
109
110 function valid__isValid(m) {
111 if (m._isValid == null) {
112 var flags = getParsingFlags(m);
113 var parsedParts = some.call(flags.parsedDateParts, function (i) {
114 return i != null;
115 });
116 m._isValid = !isNaN(m._d.getTime()) &&
117 flags.overflow < 0 &&
118 !flags.empty &&
119 !flags.invalidMonth &&
120 !flags.invalidWeekday &&
121 !flags.nullInput &&
122 !flags.invalidFormat &&
123 !flags.userInvalidated &&
124 (!flags.meridiem || (flags.meridiem && parsedParts));
125
126 if (m._strict) {
127 m._isValid = m._isValid &&
128 flags.charsLeftOver === 0 &&
129 flags.unusedTokens.length === 0 &&
130 flags.bigHour === undefined;
131 }
132 }
133 return m._isValid;
134 }
135
136 function valid__createInvalid (flags) {
137 var m = create_utc__createUTC(NaN);
138 if (flags != null) {
139 extend(getParsingFlags(m), flags);
140 }
141 else {
142 getParsingFlags(m).userInvalidated = true;
143 }
144
145 return m;
146 }
147
148 function isUndefined(input) {
149 return input === void 0;
150 }
151
152 // Plugins that add properties should also add the key here (null value),
153 // so we can properly clone ourselves.
154 var momentProperties = utils_hooks__hooks.momentProperties = [];
155
156 function copyConfig(to, from) {
157 var i, prop, val;
158
159 if (!isUndefined(from._isAMomentObject)) {
160 to._isAMomentObject = from._isAMomentObject;
161 }
162 if (!isUndefined(from._i)) {
163 to._i = from._i;
164 }
165 if (!isUndefined(from._f)) {
166 to._f = from._f;
167 }
168 if (!isUndefined(from._l)) {
169 to._l = from._l;
170 }
171 if (!isUndefined(from._strict)) {
172 to._strict = from._strict;
173 }
174 if (!isUndefined(from._tzm)) {
175 to._tzm = from._tzm;
176 }
177 if (!isUndefined(from._isUTC)) {
178 to._isUTC = from._isUTC;
179 }
180 if (!isUndefined(from._offset)) {
181 to._offset = from._offset;
182 }
183 if (!isUndefined(from._pf)) {
184 to._pf = getParsingFlags(from);
185 }
186 if (!isUndefined(from._locale)) {
187 to._locale = from._locale;
188 }
189
190 if (momentProperties.length > 0) {
191 for (i in momentProperties) {
192 prop = momentProperties[i];
193 val = from[prop];
194 if (!isUndefined(val)) {
195 to[prop] = val;
196 }
197 }
198 }
199
200 return to;
201 }
202
203 var updateInProgress = false;
204
205 // Moment prototype object
206 function Moment(config) {
207 copyConfig(this, config);
208 this._d = new Date(config._d != null ? config._d.getTime() : NaN);
209 // Prevent infinite loop in case updateOffset creates new moment
210 // objects.
211 if (updateInProgress === false) {
212 updateInProgress = true;
213 utils_hooks__hooks.updateOffset(this);
214 updateInProgress = false;
215 }
216 }
217
218 function isMoment (obj) {
219 return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
220 }
221
222 function absFloor (number) {
223 if (number < 0) {
224 return Math.ceil(number);
225 } else {
226 return Math.floor(number);
227 }
228 }
229
230 function toInt(argumentForCoercion) {
231 var coercedNumber = +argumentForCoercion,
232 value = 0;
233
234 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
235 value = absFloor(coercedNumber);
236 }
237
238 return value;
239 }
240
241 // compare two arrays, return the number of differences
242 function compareArrays(array1, array2, dontConvert) {
243 var len = Math.min(array1.length, array2.length),
244 lengthDiff = Math.abs(array1.length - array2.length),
245 diffs = 0,
246 i;
247 for (i = 0; i < len; i++) {
248 if ((dontConvert && array1[i] !== array2[i]) ||
249 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
250 diffs++;
251 }
252 }
253 return diffs + lengthDiff;
254 }
255
256 function warn(msg) {
257 if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
258 (typeof console !== 'undefined') && console.warn) {
259 console.warn('Deprecation warning: ' + msg);
260 }
261 }
262
263 function deprecate(msg, fn) {
264 var firstTime = true;
265
266 return extend(function () {
267 if (utils_hooks__hooks.deprecationHandler != null) {
268 utils_hooks__hooks.deprecationHandler(null, msg);
269 }
270 if (firstTime) {
271 warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
272 firstTime = false;
273 }
274 return fn.apply(this, arguments);
275 }, fn);
276 }
277
278 var deprecations = {};
279
280 function deprecateSimple(name, msg) {
281 if (utils_hooks__hooks.deprecationHandler != null) {
282 utils_hooks__hooks.deprecationHandler(name, msg);
283 }
284 if (!deprecations[name]) {
285 warn(msg);
286 deprecations[name] = true;
287 }
288 }
289
290 utils_hooks__hooks.suppressDeprecationWarnings = false;
291 utils_hooks__hooks.deprecationHandler = null;
292
293 function isFunction(input) {
294 return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
295 }
296
297 function isObject(input) {
298 return Object.prototype.toString.call(input) === '[object Object]';
299 }
300
301 function locale_set__set (config) {
302 var prop, i;
303 for (i in config) {
304 prop = config[i];
305 if (isFunction(prop)) {
306 this[i] = prop;
307 } else {
308 this['_' + i] = prop;
309 }
310 }
311 this._config = config;
312 // Lenient ordinal parsing accepts just a number in addition to
313 // number + (possibly) stuff coming from _ordinalParseLenient.
314 this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
315 }
316
317 function mergeConfigs(parentConfig, childConfig) {
318 var res = extend({}, parentConfig), prop;
319 for (prop in childConfig) {
320 if (hasOwnProp(childConfig, prop)) {
321 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
322 res[prop] = {};
323 extend(res[prop], parentConfig[prop]);
324 extend(res[prop], childConfig[prop]);
325 } else if (childConfig[prop] != null) {
326 res[prop] = childConfig[prop];
327 } else {
328 delete res[prop];
329 }
330 }
331 }
332 return res;
333 }
334
335 function Locale(config) {
336 if (config != null) {
337 this.set(config);
338 }
339 }
340
341 var keys;
342
343 if (Object.keys) {
344 keys = Object.keys;
345 } else {
346 keys = function (obj) {
347 var i, res = [];
348 for (i in obj) {
349 if (hasOwnProp(obj, i)) {
350 res.push(i);
351 }
352 }
353 return res;
354 };
355 }
356
357 // internal storage for locale config files
358 var locales = {};
359 var globalLocale;
360
361 function normalizeLocale(key) {
362 return key ? key.toLowerCase().replace('_', '-') : key;
363 }
364
365 // pick the locale from the array
366 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
367 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
368 function chooseLocale(names) {
369 var i = 0, j, next, locale, split;
370
371 while (i < names.length) {
372 split = normalizeLocale(names[i]).split('-');
373 j = split.length;
374 next = normalizeLocale(names[i + 1]);
375 next = next ? next.split('-') : null;
376 while (j > 0) {
377 locale = loadLocale(split.slice(0, j).join('-'));
378 if (locale) {
379 return locale;
380 }
381 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
382 //the next array item is better than a shallower substring of this one
383 break;
384 }
385 j--;
386 }
387 i++;
388 }
389 return null;
390 }
391
392 function loadLocale(name) {
393 var oldLocale = null;
394 // TODO: Find a better way to register and load all the locales in Node
395 if (!locales[name] && (typeof module !== 'undefined') &&
396 module && module.exports) {
397 try {
398 oldLocale = globalLocale._abbr;
399 require('./locale/' + name);
400 // because defineLocale currently also sets the global locale, we
401 // want to undo that for lazy loaded locales
402 locale_locales__getSetGlobalLocale(oldLocale);
403 } catch (e) { }
404 }
405 return locales[name];
406 }
407
408 // This function will load locale and then set the global locale. If
409 // no arguments are passed in, it will simply return the current global
410 // locale key.
411 function locale_locales__getSetGlobalLocale (key, values) {
412 var data;
413 if (key) {
414 if (isUndefined(values)) {
415 data = locale_locales__getLocale(key);
416 }
417 else {
418 data = defineLocale(key, values);
419 }
420
421 if (data) {
422 // moment.duration._locale = moment._locale = data;
423 globalLocale = data;
424 }
425 }
426
427 return globalLocale._abbr;
428 }
429
430 function defineLocale (name, config) {
431 if (config !== null) {
432 config.abbr = name;
433 if (locales[name] != null) {
434 deprecateSimple('defineLocaleOverride',
435 'use moment.updateLocale(localeName, config) to change ' +
436 'an existing locale. moment.defineLocale(localeName, ' +
437 'config) should only be used for creating a new locale');
438 config = mergeConfigs(locales[name]._config, config);
439 } else if (config.parentLocale != null) {
440 if (locales[config.parentLocale] != null) {
441 config = mergeConfigs(locales[config.parentLocale]._config, config);
442 } else {
443 // treat as if there is no base config
444 deprecateSimple('parentLocaleUndefined',
445 'specified parentLocale is not defined yet');
446 }
447 }
448 locales[name] = new Locale(config);
449
450 // backwards compat for now: also set the locale
451 locale_locales__getSetGlobalLocale(name);
452
453 return locales[name];
454 } else {
455 // useful for testing
456 delete locales[name];
457 return null;
458 }
459 }
460
461 function updateLocale(name, config) {
462 if (config != null) {
463 var locale;
464 if (locales[name] != null) {
465 config = mergeConfigs(locales[name]._config, config);
466 }
467 locale = new Locale(config);
468 locale.parentLocale = locales[name];
469 locales[name] = locale;
470
471 // backwards compat for now: also set the locale
472 locale_locales__getSetGlobalLocale(name);
473 } else {
474 // pass null for config to unupdate, useful for tests
475 if (locales[name] != null) {
476 if (locales[name].parentLocale != null) {
477 locales[name] = locales[name].parentLocale;
478 } else if (locales[name] != null) {
479 delete locales[name];
480 }
481 }
482 }
483 return locales[name];
484 }
485
486 // returns locale data
487 function locale_locales__getLocale (key) {
488 var locale;
489
490 if (key && key._locale && key._locale._abbr) {
491 key = key._locale._abbr;
492 }
493
494 if (!key) {
495 return globalLocale;
496 }
497
498 if (!isArray(key)) {
499 //short-circuit everything else
500 locale = loadLocale(key);
501 if (locale) {
502 return locale;
503 }
504 key = [key];
505 }
506
507 return chooseLocale(key);
508 }
509
510 function locale_locales__listLocales() {
511 return keys(locales);
512 }
513
514 var aliases = {};
515
516 function addUnitAlias (unit, shorthand) {
517 var lowerCase = unit.toLowerCase();
518 aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
519 }
520
521 function normalizeUnits(units) {
522 return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
523 }
524
525 function normalizeObjectUnits(inputObject) {
526 var normalizedInput = {},
527 normalizedProp,
528 prop;
529
530 for (prop in inputObject) {
531 if (hasOwnProp(inputObject, prop)) {
532 normalizedProp = normalizeUnits(prop);
533 if (normalizedProp) {
534 normalizedInput[normalizedProp] = inputObject[prop];
535 }
536 }
537 }
538
539 return normalizedInput;
540 }
541
542 function makeGetSet (unit, keepTime) {
543 return function (value) {
544 if (value != null) {
545 get_set__set(this, unit, value);
546 utils_hooks__hooks.updateOffset(this, keepTime);
547 return this;
548 } else {
549 return get_set__get(this, unit);
550 }
551 };
552 }
553
554 function get_set__get (mom, unit) {
555 return mom.isValid() ?
556 mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
557 }
558
559 function get_set__set (mom, unit, value) {
560 if (mom.isValid()) {
561 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
562 }
563 }
564
565 // MOMENTS
566
567 function getSet (units, value) {
568 var unit;
569 if (typeof units === 'object') {
570 for (unit in units) {
571 this.set(unit, units[unit]);
572 }
573 } else {
574 units = normalizeUnits(units);
575 if (isFunction(this[units])) {
576 return this[units](value);
577 }
578 }
579 return this;
580 }
581
582 function zeroFill(number, targetLength, forceSign) {
583 var absNumber = '' + Math.abs(number),
584 zerosToFill = targetLength - absNumber.length,
585 sign = number >= 0;
586 return (sign ? (forceSign ? '+' : '') : '-') +
587 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
588 }
589
590 var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
591
592 var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
593
594 var formatFunctions = {};
595
596 var formatTokenFunctions = {};
597
598 // token: 'M'
599 // padded: ['MM', 2]
600 // ordinal: 'Mo'
601 // callback: function () { this.month() + 1 }
602 function addFormatToken (token, padded, ordinal, callback) {
603 var func = callback;
604 if (typeof callback === 'string') {
605 func = function () {
606 return this[callback]();
607 };
608 }
609 if (token) {
610 formatTokenFunctions[token] = func;
611 }
612 if (padded) {
613 formatTokenFunctions[padded[0]] = function () {
614 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
615 };
616 }
617 if (ordinal) {
618 formatTokenFunctions[ordinal] = function () {
619 return this.localeData().ordinal(func.apply(this, arguments), token);
620 };
621 }
622 }
623
624 function removeFormattingTokens(input) {
625 if (input.match(/\[[\s\S]/)) {
626 return input.replace(/^\[|\]$/g, '');
627 }
628 return input.replace(/\\/g, '');
629 }
630
631 function makeFormatFunction(format) {
632 var array = format.match(formattingTokens), i, length;
633
634 for (i = 0, length = array.length; i < length; i++) {
635 if (formatTokenFunctions[array[i]]) {
636 array[i] = formatTokenFunctions[array[i]];
637 } else {
638 array[i] = removeFormattingTokens(array[i]);
639 }
640 }
641
642 return function (mom) {
643 var output = '', i;
644 for (i = 0; i < length; i++) {
645 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
646 }
647 return output;
648 };
649 }
650
651 // format date using native date object
652 function formatMoment(m, format) {
653 if (!m.isValid()) {
654 return m.localeData().invalidDate();
655 }
656
657 format = expandFormat(format, m.localeData());
658 formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
659
660 return formatFunctions[format](m);
661 }
662
663 function expandFormat(format, locale) {
664 var i = 5;
665
666 function replaceLongDateFormatTokens(input) {
667 return locale.longDateFormat(input) || input;
668 }
669
670 localFormattingTokens.lastIndex = 0;
671 while (i >= 0 && localFormattingTokens.test(format)) {
672 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
673 localFormattingTokens.lastIndex = 0;
674 i -= 1;
675 }
676
677 return format;
678 }
679
680 var match1 = /\d/; // 0 - 9
681 var match2 = /\d\d/; // 00 - 99
682 var match3 = /\d{3}/; // 000 - 999
683 var match4 = /\d{4}/; // 0000 - 9999
684 var match6 = /[+-]?\d{6}/; // -999999 - 999999
685 var match1to2 = /\d\d?/; // 0 - 99
686 var match3to4 = /\d\d\d\d?/; // 999 - 9999
687 var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
688 var match1to3 = /\d{1,3}/; // 0 - 999
689 var match1to4 = /\d{1,4}/; // 0 - 9999
690 var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
691
692 var matchUnsigned = /\d+/; // 0 - inf
693 var matchSigned = /[+-]?\d+/; // -inf - inf
694
695 var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
696 var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
697
698 var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
699
700 // any word (or two) characters or numbers including two/three word month in arabic.
701 // includes scottish gaelic two word and hyphenated months
702 var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
703
704
705 var regexes = {};
706
707 function addRegexToken (token, regex, strictRegex) {
708 regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
709 return (isStrict && strictRegex) ? strictRegex : regex;
710 };
711 }
712
713 function getParseRegexForToken (token, config) {
714 if (!hasOwnProp(regexes, token)) {
715 return new RegExp(unescapeFormat(token));
716 }
717
718 return regexes[token](config._strict, config._locale);
719 }
720
721 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
722 function unescapeFormat(s) {
723 return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
724 return p1 || p2 || p3 || p4;
725 }));
726 }
727
728 function regexEscape(s) {
729 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
730 }
731
732 var tokens = {};
733
734 function addParseToken (token, callback) {
735 var i, func = callback;
736 if (typeof token === 'string') {
737 token = [token];
738 }
739 if (typeof callback === 'number') {
740 func = function (input, array) {
741 array[callback] = toInt(input);
742 };
743 }
744 for (i = 0; i < token.length; i++) {
745 tokens[token[i]] = func;
746 }
747 }
748
749 function addWeekParseToken (token, callback) {
750 addParseToken(token, function (input, array, config, token) {
751 config._w = config._w || {};
752 callback(input, config._w, config, token);
753 });
754 }
755
756 function addTimeToArrayFromToken(token, input, config) {
757 if (input != null && hasOwnProp(tokens, token)) {
758 tokens[token](input, config._a, config, token);
759 }
760 }
761
762 var YEAR = 0;
763 var MONTH = 1;
764 var DATE = 2;
765 var HOUR = 3;
766 var MINUTE = 4;
767 var SECOND = 5;
768 var MILLISECOND = 6;
769 var WEEK = 7;
770 var WEEKDAY = 8;
771
772 var indexOf;
773
774 if (Array.prototype.indexOf) {
775 indexOf = Array.prototype.indexOf;
776 } else {
777 indexOf = function (o) {
778 // I know
779 var i;
780 for (i = 0; i < this.length; ++i) {
781 if (this[i] === o) {
782 return i;
783 }
784 }
785 return -1;
786 };
787 }
788
789 function daysInMonth(year, month) {
790 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
791 }
792
793 // FORMATTING
794
795 addFormatToken('M', ['MM', 2], 'Mo', function () {
796 return this.month() + 1;
797 });
798
799 addFormatToken('MMM', 0, 0, function (format) {
800 return this.localeData().monthsShort(this, format);
801 });
802
803 addFormatToken('MMMM', 0, 0, function (format) {
804 return this.localeData().months(this, format);
805 });
806
807 // ALIASES
808
809 addUnitAlias('month', 'M');
810
811 // PARSING
812
813 addRegexToken('M', match1to2);
814 addRegexToken('MM', match1to2, match2);
815 addRegexToken('MMM', function (isStrict, locale) {
816 return locale.monthsShortRegex(isStrict);
817 });
818 addRegexToken('MMMM', function (isStrict, locale) {
819 return locale.monthsRegex(isStrict);
820 });
821
822 addParseToken(['M', 'MM'], function (input, array) {
823 array[MONTH] = toInt(input) - 1;
824 });
825
826 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
827 var month = config._locale.monthsParse(input, token, config._strict);
828 // if we didn't find a month name, mark the date as invalid.
829 if (month != null) {
830 array[MONTH] = month;
831 } else {
832 getParsingFlags(config).invalidMonth = input;
833 }
834 });
835
836 // LOCALES
837
838 var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
839 var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
840 function localeMonths (m, format) {
841 return isArray(this._months) ? this._months[m.month()] :
842 this._months[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
843 }
844
845 var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
846 function localeMonthsShort (m, format) {
847 return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
848 this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
849 }
850
851 function units_month__handleStrictParse(monthName, format, strict) {
852 var i, ii, mom, llc = monthName.toLocaleLowerCase();
853 if (!this._monthsParse) {
854 // this is not used
855 this._monthsParse = [];
856 this._longMonthsParse = [];
857 this._shortMonthsParse = [];
858 for (i = 0; i < 12; ++i) {
859 mom = create_utc__createUTC([2000, i]);
860 this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
861 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
862 }
863 }
864
865 if (strict) {
866 if (format === 'MMM') {
867 ii = indexOf.call(this._shortMonthsParse, llc);
868 return ii !== -1 ? ii : null;
869 } else {
870 ii = indexOf.call(this._longMonthsParse, llc);
871 return ii !== -1 ? ii : null;
872 }
873 } else {
874 if (format === 'MMM') {
875 ii = indexOf.call(this._shortMonthsParse, llc);
876 if (ii !== -1) {
877 return ii;
878 }
879 ii = indexOf.call(this._longMonthsParse, llc);
880 return ii !== -1 ? ii : null;
881 } else {
882 ii = indexOf.call(this._longMonthsParse, llc);
883 if (ii !== -1) {
884 return ii;
885 }
886 ii = indexOf.call(this._shortMonthsParse, llc);
887 return ii !== -1 ? ii : null;
888 }
889 }
890 }
891
892 function localeMonthsParse (monthName, format, strict) {
893 var i, mom, regex;
894
895 if (this._monthsParseExact) {
896 return units_month__handleStrictParse.call(this, monthName, format, strict);
897 }
898
899 if (!this._monthsParse) {
900 this._monthsParse = [];
901 this._longMonthsParse = [];
902 this._shortMonthsParse = [];
903 }
904
905 // TODO: add sorting
906 // Sorting makes sure if one month (or abbr) is a prefix of another
907 // see sorting in computeMonthsParse
908 for (i = 0; i < 12; i++) {
909 // make the regex if we don't have it already
910 mom = create_utc__createUTC([2000, i]);
911 if (strict && !this._longMonthsParse[i]) {
912 this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
913 this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
914 }
915 if (!strict && !this._monthsParse[i]) {
916 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
917 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
918 }
919 // test the regex
920 if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
921 return i;
922 } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
923 return i;
924 } else if (!strict && this._monthsParse[i].test(monthName)) {
925 return i;
926 }
927 }
928 }
929
930 // MOMENTS
931
932 function setMonth (mom, value) {
933 var dayOfMonth;
934
935 if (!mom.isValid()) {
936 // No op
937 return mom;
938 }
939
940 if (typeof value === 'string') {
941 if (/^\d+$/.test(value)) {
942 value = toInt(value);
943 } else {
944 value = mom.localeData().monthsParse(value);
945 // TODO: Another silent failure?
946 if (typeof value !== 'number') {
947 return mom;
948 }
949 }
950 }
951
952 dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
953 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
954 return mom;
955 }
956
957 function getSetMonth (value) {
958 if (value != null) {
959 setMonth(this, value);
960 utils_hooks__hooks.updateOffset(this, true);
961 return this;
962 } else {
963 return get_set__get(this, 'Month');
964 }
965 }
966
967 function getDaysInMonth () {
968 return daysInMonth(this.year(), this.month());
969 }
970
971 var defaultMonthsShortRegex = matchWord;
972 function monthsShortRegex (isStrict) {
973 if (this._monthsParseExact) {
974 if (!hasOwnProp(this, '_monthsRegex')) {
975 computeMonthsParse.call(this);
976 }
977 if (isStrict) {
978 return this._monthsShortStrictRegex;
979 } else {
980 return this._monthsShortRegex;
981 }
982 } else {
983 return this._monthsShortStrictRegex && isStrict ?
984 this._monthsShortStrictRegex : this._monthsShortRegex;
985 }
986 }
987
988 var defaultMonthsRegex = matchWord;
989 function monthsRegex (isStrict) {
990 if (this._monthsParseExact) {
991 if (!hasOwnProp(this, '_monthsRegex')) {
992 computeMonthsParse.call(this);
993 }
994 if (isStrict) {
995 return this._monthsStrictRegex;
996 } else {
997 return this._monthsRegex;
998 }
999 } else {
1000 return this._monthsStrictRegex && isStrict ?
1001 this._monthsStrictRegex : this._monthsRegex;
1002 }
1003 }
1004
1005 function computeMonthsParse () {
1006 function cmpLenRev(a, b) {
1007 return b.length - a.length;
1008 }
1009
1010 var shortPieces = [], longPieces = [], mixedPieces = [],
1011 i, mom;
1012 for (i = 0; i < 12; i++) {
1013 // make the regex if we don't have it already
1014 mom = create_utc__createUTC([2000, i]);
1015 shortPieces.push(this.monthsShort(mom, ''));
1016 longPieces.push(this.months(mom, ''));
1017 mixedPieces.push(this.months(mom, ''));
1018 mixedPieces.push(this.monthsShort(mom, ''));
1019 }
1020 // Sorting makes sure if one month (or abbr) is a prefix of another it
1021 // will match the longer piece.
1022 shortPieces.sort(cmpLenRev);
1023 longPieces.sort(cmpLenRev);
1024 mixedPieces.sort(cmpLenRev);
1025 for (i = 0; i < 12; i++) {
1026 shortPieces[i] = regexEscape(shortPieces[i]);
1027 longPieces[i] = regexEscape(longPieces[i]);
1028 mixedPieces[i] = regexEscape(mixedPieces[i]);
1029 }
1030
1031 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
1032 this._monthsShortRegex = this._monthsRegex;
1033 this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
1034 this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
1035 }
1036
1037 function checkOverflow (m) {
1038 var overflow;
1039 var a = m._a;
1040
1041 if (a && getParsingFlags(m).overflow === -2) {
1042 overflow =
1043 a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
1044 a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
1045 a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
1046 a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
1047 a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
1048 a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
1049 -1;
1050
1051 if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
1052 overflow = DATE;
1053 }
1054 if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
1055 overflow = WEEK;
1056 }
1057 if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
1058 overflow = WEEKDAY;
1059 }
1060
1061 getParsingFlags(m).overflow = overflow;
1062 }
1063
1064 return m;
1065 }
1066
1067 // iso 8601 regex
1068 // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
1069 var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
1070 var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
1071
1072 var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
1073
1074 var isoDates = [
1075 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
1076 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
1077 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
1078 ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
1079 ['YYYY-DDD', /\d{4}-\d{3}/],
1080 ['YYYY-MM', /\d{4}-\d\d/, false],
1081 ['YYYYYYMMDD', /[+-]\d{10}/],
1082 ['YYYYMMDD', /\d{8}/],
1083 // YYYYMM is NOT allowed by the standard
1084 ['GGGG[W]WWE', /\d{4}W\d{3}/],
1085 ['GGGG[W]WW', /\d{4}W\d{2}/, false],
1086 ['YYYYDDD', /\d{7}/]
1087 ];
1088
1089 // iso time formats and regexes
1090 var isoTimes = [
1091 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
1092 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
1093 ['HH:mm:ss', /\d\d:\d\d:\d\d/],
1094 ['HH:mm', /\d\d:\d\d/],
1095 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
1096 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
1097 ['HHmmss', /\d\d\d\d\d\d/],
1098 ['HHmm', /\d\d\d\d/],
1099 ['HH', /\d\d/]
1100 ];
1101
1102 var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
1103
1104 // date from iso format
1105 function configFromISO(config) {
1106 var i, l,
1107 string = config._i,
1108 match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
1109 allowTime, dateFormat, timeFormat, tzFormat;
1110
1111 if (match) {
1112 getParsingFlags(config).iso = true;
1113
1114 for (i = 0, l = isoDates.length; i < l; i++) {
1115 if (isoDates[i][1].exec(match[1])) {
1116 dateFormat = isoDates[i][0];
1117 allowTime = isoDates[i][2] !== false;
1118 break;
1119 }
1120 }
1121 if (dateFormat == null) {
1122 config._isValid = false;
1123 return;
1124 }
1125 if (match[3]) {
1126 for (i = 0, l = isoTimes.length; i < l; i++) {
1127 if (isoTimes[i][1].exec(match[3])) {
1128 // match[2] should be 'T' or space
1129 timeFormat = (match[2] || ' ') + isoTimes[i][0];
1130 break;
1131 }
1132 }
1133 if (timeFormat == null) {
1134 config._isValid = false;
1135 return;
1136 }
1137 }
1138 if (!allowTime && timeFormat != null) {
1139 config._isValid = false;
1140 return;
1141 }
1142 if (match[4]) {
1143 if (tzRegex.exec(match[4])) {
1144 tzFormat = 'Z';
1145 } else {
1146 config._isValid = false;
1147 return;
1148 }
1149 }
1150 config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
1151 configFromStringAndFormat(config);
1152 } else {
1153 config._isValid = false;
1154 }
1155 }
1156
1157 // date from iso format or fallback
1158 function configFromString(config) {
1159 var matched = aspNetJsonRegex.exec(config._i);
1160
1161 if (matched !== null) {
1162 config._d = new Date(+matched[1]);
1163 return;
1164 }
1165
1166 configFromISO(config);
1167 if (config._isValid === false) {
1168 delete config._isValid;
1169 utils_hooks__hooks.createFromInputFallback(config);
1170 }
1171 }
1172
1173 utils_hooks__hooks.createFromInputFallback = deprecate(
1174 'moment construction falls back to js Date. This is ' +
1175 'discouraged and will be removed in upcoming major ' +
1176 'release. Please refer to ' +
1177 'https://github.com/moment/moment/issues/1407 for more info.',
1178 function (config) {
1179 config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
1180 }
1181 );
1182
1183 function createDate (y, m, d, h, M, s, ms) {
1184 //can't just apply() to create a date:
1185 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
1186 var date = new Date(y, m, d, h, M, s, ms);
1187
1188 //the date constructor remaps years 0-99 to 1900-1999
1189 if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
1190 date.setFullYear(y);
1191 }
1192 return date;
1193 }
1194
1195 function createUTCDate (y) {
1196 var date = new Date(Date.UTC.apply(null, arguments));
1197
1198 //the Date.UTC function remaps years 0-99 to 1900-1999
1199 if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
1200 date.setUTCFullYear(y);
1201 }
1202 return date;
1203 }
1204
1205 // FORMATTING
1206
1207 addFormatToken('Y', 0, 0, function () {
1208 var y = this.year();
1209 return y <= 9999 ? '' + y : '+' + y;
1210 });
1211
1212 addFormatToken(0, ['YY', 2], 0, function () {
1213 return this.year() % 100;
1214 });
1215
1216 addFormatToken(0, ['YYYY', 4], 0, 'year');
1217 addFormatToken(0, ['YYYYY', 5], 0, 'year');
1218 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
1219
1220 // ALIASES
1221
1222 addUnitAlias('year', 'y');
1223
1224 // PARSING
1225
1226 addRegexToken('Y', matchSigned);
1227 addRegexToken('YY', match1to2, match2);
1228 addRegexToken('YYYY', match1to4, match4);
1229 addRegexToken('YYYYY', match1to6, match6);
1230 addRegexToken('YYYYYY', match1to6, match6);
1231
1232 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
1233 addParseToken('YYYY', function (input, array) {
1234 array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
1235 });
1236 addParseToken('YY', function (input, array) {
1237 array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
1238 });
1239 addParseToken('Y', function (input, array) {
1240 array[YEAR] = parseInt(input, 10);
1241 });
1242
1243 // HELPERS
1244
1245 function daysInYear(year) {
1246 return isLeapYear(year) ? 366 : 365;
1247 }
1248
1249 function isLeapYear(year) {
1250 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
1251 }
1252
1253 // HOOKS
1254
1255 utils_hooks__hooks.parseTwoDigitYear = function (input) {
1256 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
1257 };
1258
1259 // MOMENTS
1260
1261 var getSetYear = makeGetSet('FullYear', true);
1262
1263 function getIsLeapYear () {
1264 return isLeapYear(this.year());
1265 }
1266
1267 // start-of-first-week - start-of-year
1268 function firstWeekOffset(year, dow, doy) {
1269 var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
1270 fwd = 7 + dow - doy,
1271 // first-week day local weekday -- which local weekday is fwd
1272 fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
1273
1274 return -fwdlw + fwd - 1;
1275 }
1276
1277 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1278 function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
1279 var localWeekday = (7 + weekday - dow) % 7,
1280 weekOffset = firstWeekOffset(year, dow, doy),
1281 dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
1282 resYear, resDayOfYear;
1283
1284 if (dayOfYear <= 0) {
1285 resYear = year - 1;
1286 resDayOfYear = daysInYear(resYear) + dayOfYear;
1287 } else if (dayOfYear > daysInYear(year)) {
1288 resYear = year + 1;
1289 resDayOfYear = dayOfYear - daysInYear(year);
1290 } else {
1291 resYear = year;
1292 resDayOfYear = dayOfYear;
1293 }
1294
1295 return {
1296 year: resYear,
1297 dayOfYear: resDayOfYear
1298 };
1299 }
1300
1301 function weekOfYear(mom, dow, doy) {
1302 var weekOffset = firstWeekOffset(mom.year(), dow, doy),
1303 week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
1304 resWeek, resYear;
1305
1306 if (week < 1) {
1307 resYear = mom.year() - 1;
1308 resWeek = week + weeksInYear(resYear, dow, doy);
1309 } else if (week > weeksInYear(mom.year(), dow, doy)) {
1310 resWeek = week - weeksInYear(mom.year(), dow, doy);
1311 resYear = mom.year() + 1;
1312 } else {
1313 resYear = mom.year();
1314 resWeek = week;
1315 }
1316
1317 return {
1318 week: resWeek,
1319 year: resYear
1320 };
1321 }
1322
1323 function weeksInYear(year, dow, doy) {
1324 var weekOffset = firstWeekOffset(year, dow, doy),
1325 weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
1326 return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
1327 }
1328
1329 // Pick the first defined of two or three arguments.
1330 function defaults(a, b, c) {
1331 if (a != null) {
1332 return a;
1333 }
1334 if (b != null) {
1335 return b;
1336 }
1337 return c;
1338 }
1339
1340 function currentDateArray(config) {
1341 // hooks is actually the exported moment object
1342 var nowValue = new Date(utils_hooks__hooks.now());
1343 if (config._useUTC) {
1344 return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
1345 }
1346 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
1347 }
1348
1349 // convert an array to a date.
1350 // the array should mirror the parameters below
1351 // note: all values past the year are optional and will default to the lowest possible value.
1352 // [year, month, day , hour, minute, second, millisecond]
1353 function configFromArray (config) {
1354 var i, date, input = [], currentDate, yearToUse;
1355
1356 if (config._d) {
1357 return;
1358 }
1359
1360 currentDate = currentDateArray(config);
1361
1362 //compute day of the year from weeks and weekdays
1363 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
1364 dayOfYearFromWeekInfo(config);
1365 }
1366
1367 //if the day of the year is set, figure out what it is
1368 if (config._dayOfYear) {
1369 yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
1370
1371 if (config._dayOfYear > daysInYear(yearToUse)) {
1372 getParsingFlags(config)._overflowDayOfYear = true;
1373 }
1374
1375 date = createUTCDate(yearToUse, 0, config._dayOfYear);
1376 config._a[MONTH] = date.getUTCMonth();
1377 config._a[DATE] = date.getUTCDate();
1378 }
1379
1380 // Default to current date.
1381 // * if no year, month, day of month are given, default to today
1382 // * if day of month is given, default month and year
1383 // * if month is given, default only year
1384 // * if year is given, don't default anything
1385 for (i = 0; i < 3 && config._a[i] == null; ++i) {
1386 config._a[i] = input[i] = currentDate[i];
1387 }
1388
1389 // Zero out whatever was not defaulted, including time
1390 for (; i < 7; i++) {
1391 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
1392 }
1393
1394 // Check for 24:00:00.000
1395 if (config._a[HOUR] === 24 &&
1396 config._a[MINUTE] === 0 &&
1397 config._a[SECOND] === 0 &&
1398 config._a[MILLISECOND] === 0) {
1399 config._nextDay = true;
1400 config._a[HOUR] = 0;
1401 }
1402
1403 config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
1404 // Apply timezone offset from input. The actual utcOffset can be changed
1405 // with parseZone.
1406 if (config._tzm != null) {
1407 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
1408 }
1409
1410 if (config._nextDay) {
1411 config._a[HOUR] = 24;
1412 }
1413 }
1414
1415 function dayOfYearFromWeekInfo(config) {
1416 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
1417
1418 w = config._w;
1419 if (w.GG != null || w.W != null || w.E != null) {
1420 dow = 1;
1421 doy = 4;
1422
1423 // TODO: We need to take the current isoWeekYear, but that depends on
1424 // how we interpret now (local, utc, fixed offset). So create
1425 // a now version of current config (take local/utc/offset flags, and
1426 // create now).
1427 weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
1428 week = defaults(w.W, 1);
1429 weekday = defaults(w.E, 1);
1430 if (weekday < 1 || weekday > 7) {
1431 weekdayOverflow = true;
1432 }
1433 } else {
1434 dow = config._locale._week.dow;
1435 doy = config._locale._week.doy;
1436
1437 weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
1438 week = defaults(w.w, 1);
1439
1440 if (w.d != null) {
1441 // weekday -- low day numbers are considered next week
1442 weekday = w.d;
1443 if (weekday < 0 || weekday > 6) {
1444 weekdayOverflow = true;
1445 }
1446 } else if (w.e != null) {
1447 // local weekday -- counting starts from begining of week
1448 weekday = w.e + dow;
1449 if (w.e < 0 || w.e > 6) {
1450 weekdayOverflow = true;
1451 }
1452 } else {
1453 // default to begining of week
1454 weekday = dow;
1455 }
1456 }
1457 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
1458 getParsingFlags(config)._overflowWeeks = true;
1459 } else if (weekdayOverflow != null) {
1460 getParsingFlags(config)._overflowWeekday = true;
1461 } else {
1462 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
1463 config._a[YEAR] = temp.year;
1464 config._dayOfYear = temp.dayOfYear;
1465 }
1466 }
1467
1468 // constant that refers to the ISO standard
1469 utils_hooks__hooks.ISO_8601 = function () {};
1470
1471 // date from string and format string
1472 function configFromStringAndFormat(config) {
1473 // TODO: Move this to another part of the creation flow to prevent circular deps
1474 if (config._f === utils_hooks__hooks.ISO_8601) {
1475 configFromISO(config);
1476 return;
1477 }
1478
1479 config._a = [];
1480 getParsingFlags(config).empty = true;
1481
1482 // This array is used to make a Date, either with `new Date` or `Date.UTC`
1483 var string = '' + config._i,
1484 i, parsedInput, tokens, token, skipped,
1485 stringLength = string.length,
1486 totalParsedInputLength = 0;
1487
1488 tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
1489
1490 for (i = 0; i < tokens.length; i++) {
1491 token = tokens[i];
1492 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
1493 // console.log('token', token, 'parsedInput', parsedInput,
1494 // 'regex', getParseRegexForToken(token, config));
1495 if (parsedInput) {
1496 skipped = string.substr(0, string.indexOf(parsedInput));
1497 if (skipped.length > 0) {
1498 getParsingFlags(config).unusedInput.push(skipped);
1499 }
1500 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
1501 totalParsedInputLength += parsedInput.length;
1502 }
1503 // don't parse if it's not a known token
1504 if (formatTokenFunctions[token]) {
1505 if (parsedInput) {
1506 getParsingFlags(config).empty = false;
1507 }
1508 else {
1509 getParsingFlags(config).unusedTokens.push(token);
1510 }
1511 addTimeToArrayFromToken(token, parsedInput, config);
1512 }
1513 else if (config._strict && !parsedInput) {
1514 getParsingFlags(config).unusedTokens.push(token);
1515 }
1516 }
1517
1518 // add remaining unparsed input length to the string
1519 getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
1520 if (string.length > 0) {
1521 getParsingFlags(config).unusedInput.push(string);
1522 }
1523
1524 // clear _12h flag if hour is <= 12
1525 if (getParsingFlags(config).bigHour === true &&
1526 config._a[HOUR] <= 12 &&
1527 config._a[HOUR] > 0) {
1528 getParsingFlags(config).bigHour = undefined;
1529 }
1530
1531 getParsingFlags(config).parsedDateParts = config._a.slice(0);
1532 getParsingFlags(config).meridiem = config._meridiem;
1533 // handle meridiem
1534 config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
1535
1536 configFromArray(config);
1537 checkOverflow(config);
1538 }
1539
1540
1541 function meridiemFixWrap (locale, hour, meridiem) {
1542 var isPm;
1543
1544 if (meridiem == null) {
1545 // nothing to do
1546 return hour;
1547 }
1548 if (locale.meridiemHour != null) {
1549 return locale.meridiemHour(hour, meridiem);
1550 } else if (locale.isPM != null) {
1551 // Fallback
1552 isPm = locale.isPM(meridiem);
1553 if (isPm && hour < 12) {
1554 hour += 12;
1555 }
1556 if (!isPm && hour === 12) {
1557 hour = 0;
1558 }
1559 return hour;
1560 } else {
1561 // this is not supposed to happen
1562 return hour;
1563 }
1564 }
1565
1566 // date from string and array of format strings
1567 function configFromStringAndArray(config) {
1568 var tempConfig,
1569 bestMoment,
1570
1571 scoreToBeat,
1572 i,
1573 currentScore;
1574
1575 if (config._f.length === 0) {
1576 getParsingFlags(config).invalidFormat = true;
1577 config._d = new Date(NaN);
1578 return;
1579 }
1580
1581 for (i = 0; i < config._f.length; i++) {
1582 currentScore = 0;
1583 tempConfig = copyConfig({}, config);
1584 if (config._useUTC != null) {
1585 tempConfig._useUTC = config._useUTC;
1586 }
1587 tempConfig._f = config._f[i];
1588 configFromStringAndFormat(tempConfig);
1589
1590 if (!valid__isValid(tempConfig)) {
1591 continue;
1592 }
1593
1594 // if there is any input that was not parsed add a penalty for that format
1595 currentScore += getParsingFlags(tempConfig).charsLeftOver;
1596
1597 //or tokens
1598 currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
1599
1600 getParsingFlags(tempConfig).score = currentScore;
1601
1602 if (scoreToBeat == null || currentScore < scoreToBeat) {
1603 scoreToBeat = currentScore;
1604 bestMoment = tempConfig;
1605 }
1606 }
1607
1608 extend(config, bestMoment || tempConfig);
1609 }
1610
1611 function configFromObject(config) {
1612 if (config._d) {
1613 return;
1614 }
1615
1616 var i = normalizeObjectUnits(config._i);
1617 config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
1618 return obj && parseInt(obj, 10);
1619 });
1620
1621 configFromArray(config);
1622 }
1623
1624 function createFromConfig (config) {
1625 var res = new Moment(checkOverflow(prepareConfig(config)));
1626 if (res._nextDay) {
1627 // Adding is smart enough around DST
1628 res.add(1, 'd');
1629 res._nextDay = undefined;
1630 }
1631
1632 return res;
1633 }
1634
1635 function prepareConfig (config) {
1636 var input = config._i,
1637 format = config._f;
1638
1639 config._locale = config._locale || locale_locales__getLocale(config._l);
1640
1641 if (input === null || (format === undefined && input === '')) {
1642 return valid__createInvalid({nullInput: true});
1643 }
1644
1645 if (typeof input === 'string') {
1646 config._i = input = config._locale.preparse(input);
1647 }
1648
1649 if (isMoment(input)) {
1650 return new Moment(checkOverflow(input));
1651 } else if (isArray(format)) {
1652 configFromStringAndArray(config);
1653 } else if (format) {
1654 configFromStringAndFormat(config);
1655 } else if (isDate(input)) {
1656 config._d = input;
1657 } else {
1658 configFromInput(config);
1659 }
1660
1661 if (!valid__isValid(config)) {
1662 config._d = null;
1663 }
1664
1665 return config;
1666 }
1667
1668 function configFromInput(config) {
1669 var input = config._i;
1670 if (input === undefined) {
1671 config._d = new Date(utils_hooks__hooks.now());
1672 } else if (isDate(input)) {
1673 config._d = new Date(input.valueOf());
1674 } else if (typeof input === 'string') {
1675 configFromString(config);
1676 } else if (isArray(input)) {
1677 config._a = map(input.slice(0), function (obj) {
1678 return parseInt(obj, 10);
1679 });
1680 configFromArray(config);
1681 } else if (typeof(input) === 'object') {
1682 configFromObject(config);
1683 } else if (typeof(input) === 'number') {
1684 // from milliseconds
1685 config._d = new Date(input);
1686 } else {
1687 utils_hooks__hooks.createFromInputFallback(config);
1688 }
1689 }
1690
1691 function createLocalOrUTC (input, format, locale, strict, isUTC) {
1692 var c = {};
1693
1694 if (typeof(locale) === 'boolean') {
1695 strict = locale;
1696 locale = undefined;
1697 }
1698 // object construction must be done this way.
1699 // https://github.com/moment/moment/issues/1423
1700 c._isAMomentObject = true;
1701 c._useUTC = c._isUTC = isUTC;
1702 c._l = locale;
1703 c._i = input;
1704 c._f = format;
1705 c._strict = strict;
1706
1707 return createFromConfig(c);
1708 }
1709
1710 function local__createLocal (input, format, locale, strict) {
1711 return createLocalOrUTC(input, format, locale, strict, false);
1712 }
1713
1714 var prototypeMin = deprecate(
1715 'moment().min is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
1716 function () {
1717 var other = local__createLocal.apply(null, arguments);
1718 if (this.isValid() && other.isValid()) {
1719 return other < this ? this : other;
1720 } else {
1721 return valid__createInvalid();
1722 }
1723 }
1724 );
1725
1726 var prototypeMax = deprecate(
1727 'moment().max is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
1728 function () {
1729 var other = local__createLocal.apply(null, arguments);
1730 if (this.isValid() && other.isValid()) {
1731 return other > this ? this : other;
1732 } else {
1733 return valid__createInvalid();
1734 }
1735 }
1736 );
1737
1738 // Pick a moment m from moments so that m[fn](other) is true for all
1739 // other. This relies on the function fn to be transitive.
1740 //
1741 // moments should either be an array of moment objects or an array, whose
1742 // first element is an array of moment objects.
1743 function pickBy(fn, moments) {
1744 var res, i;
1745 if (moments.length === 1 && isArray(moments[0])) {
1746 moments = moments[0];
1747 }
1748 if (!moments.length) {
1749 return local__createLocal();
1750 }
1751 res = moments[0];
1752 for (i = 1; i < moments.length; ++i) {
1753 if (!moments[i].isValid() || moments[i][fn](res)) {
1754 res = moments[i];
1755 }
1756 }
1757 return res;
1758 }
1759
1760 // TODO: Use [].sort instead?
1761 function min () {
1762 var args = [].slice.call(arguments, 0);
1763
1764 return pickBy('isBefore', args);
1765 }
1766
1767 function max () {
1768 var args = [].slice.call(arguments, 0);
1769
1770 return pickBy('isAfter', args);
1771 }
1772
1773 var now = function () {
1774 return Date.now ? Date.now() : +(new Date());
1775 };
1776
1777 function Duration (duration) {
1778 var normalizedInput = normalizeObjectUnits(duration),
1779 years = normalizedInput.year || 0,
1780 quarters = normalizedInput.quarter || 0,
1781 months = normalizedInput.month || 0,
1782 weeks = normalizedInput.week || 0,
1783 days = normalizedInput.day || 0,
1784 hours = normalizedInput.hour || 0,
1785 minutes = normalizedInput.minute || 0,
1786 seconds = normalizedInput.second || 0,
1787 milliseconds = normalizedInput.millisecond || 0;
1788
1789 // representation for dateAddRemove
1790 this._milliseconds = +milliseconds +
1791 seconds * 1e3 + // 1000
1792 minutes * 6e4 + // 1000 * 60
1793 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
1794 // Because of dateAddRemove treats 24 hours as different from a
1795 // day when working around DST, we need to store them separately
1796 this._days = +days +
1797 weeks * 7;
1798 // It is impossible translate months into days without knowing
1799 // which months you are are talking about, so we have to store
1800 // it separately.
1801 this._months = +months +
1802 quarters * 3 +
1803 years * 12;
1804
1805 this._data = {};
1806
1807 this._locale = locale_locales__getLocale();
1808
1809 this._bubble();
1810 }
1811
1812 function isDuration (obj) {
1813 return obj instanceof Duration;
1814 }
1815
1816 // FORMATTING
1817
1818 function offset (token, separator) {
1819 addFormatToken(token, 0, 0, function () {
1820 var offset = this.utcOffset();
1821 var sign = '+';
1822 if (offset < 0) {
1823 offset = -offset;
1824 sign = '-';
1825 }
1826 return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
1827 });
1828 }
1829
1830 offset('Z', ':');
1831 offset('ZZ', '');
1832
1833 // PARSING
1834
1835 addRegexToken('Z', matchShortOffset);
1836 addRegexToken('ZZ', matchShortOffset);
1837 addParseToken(['Z', 'ZZ'], function (input, array, config) {
1838 config._useUTC = true;
1839 config._tzm = offsetFromString(matchShortOffset, input);
1840 });
1841
1842 // HELPERS
1843
1844 // timezone chunker
1845 // '+10:00' > ['10', '00']
1846 // '-1530' > ['-15', '30']
1847 var chunkOffset = /([\+\-]|\d\d)/gi;
1848
1849 function offsetFromString(matcher, string) {
1850 var matches = ((string || '').match(matcher) || []);
1851 var chunk = matches[matches.length - 1] || [];
1852 var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
1853 var minutes = +(parts[1] * 60) + toInt(parts[2]);
1854
1855 return parts[0] === '+' ? minutes : -minutes;
1856 }
1857
1858 // Return a moment from input, that is local/utc/zone equivalent to model.
1859 function cloneWithOffset(input, model) {
1860 var res, diff;
1861 if (model._isUTC) {
1862 res = model.clone();
1863 diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf();
1864 // Use low-level api, because this fn is low-level api.
1865 res._d.setTime(res._d.valueOf() + diff);
1866 utils_hooks__hooks.updateOffset(res, false);
1867 return res;
1868 } else {
1869 return local__createLocal(input).local();
1870 }
1871 }
1872
1873 function getDateOffset (m) {
1874 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
1875 // https://github.com/moment/moment/pull/1871
1876 return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
1877 }
1878
1879 // HOOKS
1880
1881 // This function will be called whenever a moment is mutated.
1882 // It is intended to keep the offset in sync with the timezone.
1883 utils_hooks__hooks.updateOffset = function () {};
1884
1885 // MOMENTS
1886
1887 // keepLocalTime = true means only change the timezone, without
1888 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
1889 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
1890 // +0200, so we adjust the time as needed, to be valid.
1891 //
1892 // Keeping the time actually adds/subtracts (one hour)
1893 // from the actual represented time. That is why we call updateOffset
1894 // a second time. In case it wants us to change the offset again
1895 // _changeInProgress == true case, then we have to adjust, because
1896 // there is no such time in the given timezone.
1897 function getSetOffset (input, keepLocalTime) {
1898 var offset = this._offset || 0,
1899 localAdjust;
1900 if (!this.isValid()) {
1901 return input != null ? this : NaN;
1902 }
1903 if (input != null) {
1904 if (typeof input === 'string') {
1905 input = offsetFromString(matchShortOffset, input);
1906 } else if (Math.abs(input) < 16) {
1907 input = input * 60;
1908 }
1909 if (!this._isUTC && keepLocalTime) {
1910 localAdjust = getDateOffset(this);
1911 }
1912 this._offset = input;
1913 this._isUTC = true;
1914 if (localAdjust != null) {
1915 this.add(localAdjust, 'm');
1916 }
1917 if (offset !== input) {
1918 if (!keepLocalTime || this._changeInProgress) {
1919 add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
1920 } else if (!this._changeInProgress) {
1921 this._changeInProgress = true;
1922 utils_hooks__hooks.updateOffset(this, true);
1923 this._changeInProgress = null;
1924 }
1925 }
1926 return this;
1927 } else {
1928 return this._isUTC ? offset : getDateOffset(this);
1929 }
1930 }
1931
1932 function getSetZone (input, keepLocalTime) {
1933 if (input != null) {
1934 if (typeof input !== 'string') {
1935 input = -input;
1936 }
1937
1938 this.utcOffset(input, keepLocalTime);
1939
1940 return this;
1941 } else {
1942 return -this.utcOffset();
1943 }
1944 }
1945
1946 function setOffsetToUTC (keepLocalTime) {
1947 return this.utcOffset(0, keepLocalTime);
1948 }
1949
1950 function setOffsetToLocal (keepLocalTime) {
1951 if (this._isUTC) {
1952 this.utcOffset(0, keepLocalTime);
1953 this._isUTC = false;
1954
1955 if (keepLocalTime) {
1956 this.subtract(getDateOffset(this), 'm');
1957 }
1958 }
1959 return this;
1960 }
1961
1962 function setOffsetToParsedOffset () {
1963 if (this._tzm) {
1964 this.utcOffset(this._tzm);
1965 } else if (typeof this._i === 'string') {
1966 this.utcOffset(offsetFromString(matchOffset, this._i));
1967 }
1968 return this;
1969 }
1970
1971 function hasAlignedHourOffset (input) {
1972 if (!this.isValid()) {
1973 return false;
1974 }
1975 input = input ? local__createLocal(input).utcOffset() : 0;
1976
1977 return (this.utcOffset() - input) % 60 === 0;
1978 }
1979
1980 function isDaylightSavingTime () {
1981 return (
1982 this.utcOffset() > this.clone().month(0).utcOffset() ||
1983 this.utcOffset() > this.clone().month(5).utcOffset()
1984 );
1985 }
1986
1987 function isDaylightSavingTimeShifted () {
1988 if (!isUndefined(this._isDSTShifted)) {
1989 return this._isDSTShifted;
1990 }
1991
1992 var c = {};
1993
1994 copyConfig(c, this);
1995 c = prepareConfig(c);
1996
1997 if (c._a) {
1998 var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
1999 this._isDSTShifted = this.isValid() &&
2000 compareArrays(c._a, other.toArray()) > 0;
2001 } else {
2002 this._isDSTShifted = false;
2003 }
2004
2005 return this._isDSTShifted;
2006 }
2007
2008 function isLocal () {
2009 return this.isValid() ? !this._isUTC : false;
2010 }
2011
2012 function isUtcOffset () {
2013 return this.isValid() ? this._isUTC : false;
2014 }
2015
2016 function isUtc () {
2017 return this.isValid() ? this._isUTC && this._offset === 0 : false;
2018 }
2019
2020 // ASP.NET json date format regex
2021 var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
2022
2023 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
2024 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
2025 // and further modified to allow for strings containing both week and day
2026 var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/;
2027
2028 function create__createDuration (input, key) {
2029 var duration = input,
2030 // matching against regexp is expensive, do it on demand
2031 match = null,
2032 sign,
2033 ret,
2034 diffRes;
2035
2036 if (isDuration(input)) {
2037 duration = {
2038 ms : input._milliseconds,
2039 d : input._days,
2040 M : input._months
2041 };
2042 } else if (typeof input === 'number') {
2043 duration = {};
2044 if (key) {
2045 duration[key] = input;
2046 } else {
2047 duration.milliseconds = input;
2048 }
2049 } else if (!!(match = aspNetRegex.exec(input))) {
2050 sign = (match[1] === '-') ? -1 : 1;
2051 duration = {
2052 y : 0,
2053 d : toInt(match[DATE]) * sign,
2054 h : toInt(match[HOUR]) * sign,
2055 m : toInt(match[MINUTE]) * sign,
2056 s : toInt(match[SECOND]) * sign,
2057 ms : toInt(match[MILLISECOND]) * sign
2058 };
2059 } else if (!!(match = isoRegex.exec(input))) {
2060 sign = (match[1] === '-') ? -1 : 1;
2061 duration = {
2062 y : parseIso(match[2], sign),
2063 M : parseIso(match[3], sign),
2064 w : parseIso(match[4], sign),
2065 d : parseIso(match[5], sign),
2066 h : parseIso(match[6], sign),
2067 m : parseIso(match[7], sign),
2068 s : parseIso(match[8], sign)
2069 };
2070 } else if (duration == null) {// checks for null or undefined
2071 duration = {};
2072 } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
2073 diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
2074
2075 duration = {};
2076 duration.ms = diffRes.milliseconds;
2077 duration.M = diffRes.months;
2078 }
2079
2080 ret = new Duration(duration);
2081
2082 if (isDuration(input) && hasOwnProp(input, '_locale')) {
2083 ret._locale = input._locale;
2084 }
2085
2086 return ret;
2087 }
2088
2089 create__createDuration.fn = Duration.prototype;
2090
2091 function parseIso (inp, sign) {
2092 // We'd normally use ~~inp for this, but unfortunately it also
2093 // converts floats to ints.
2094 // inp may be undefined, so careful calling replace on it.
2095 var res = inp && parseFloat(inp.replace(',', '.'));
2096 // apply sign while we're at it
2097 return (isNaN(res) ? 0 : res) * sign;
2098 }
2099
2100 function positiveMomentsDifference(base, other) {
2101 var res = {milliseconds: 0, months: 0};
2102
2103 res.months = other.month() - base.month() +
2104 (other.year() - base.year()) * 12;
2105 if (base.clone().add(res.months, 'M').isAfter(other)) {
2106 --res.months;
2107 }
2108
2109 res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
2110
2111 return res;
2112 }
2113
2114 function momentsDifference(base, other) {
2115 var res;
2116 if (!(base.isValid() && other.isValid())) {
2117 return {milliseconds: 0, months: 0};
2118 }
2119
2120 other = cloneWithOffset(other, base);
2121 if (base.isBefore(other)) {
2122 res = positiveMomentsDifference(base, other);
2123 } else {
2124 res = positiveMomentsDifference(other, base);
2125 res.milliseconds = -res.milliseconds;
2126 res.months = -res.months;
2127 }
2128
2129 return res;
2130 }
2131
2132 function absRound (number) {
2133 if (number < 0) {
2134 return Math.round(-1 * number) * -1;
2135 } else {
2136 return Math.round(number);
2137 }
2138 }
2139
2140 // TODO: remove 'name' arg after deprecation is removed
2141 function createAdder(direction, name) {
2142 return function (val, period) {
2143 var dur, tmp;
2144 //invert the arguments, but complain about it
2145 if (period !== null && !isNaN(+period)) {
2146 deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
2147 tmp = val; val = period; period = tmp;
2148 }
2149
2150 val = typeof val === 'string' ? +val : val;
2151 dur = create__createDuration(val, period);
2152 add_subtract__addSubtract(this, dur, direction);
2153 return this;
2154 };
2155 }
2156
2157 function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
2158 var milliseconds = duration._milliseconds,
2159 days = absRound(duration._days),
2160 months = absRound(duration._months);
2161
2162 if (!mom.isValid()) {
2163 // No op
2164 return;
2165 }
2166
2167 updateOffset = updateOffset == null ? true : updateOffset;
2168
2169 if (milliseconds) {
2170 mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
2171 }
2172 if (days) {
2173 get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
2174 }
2175 if (months) {
2176 setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
2177 }
2178 if (updateOffset) {
2179 utils_hooks__hooks.updateOffset(mom, days || months);
2180 }
2181 }
2182
2183 var add_subtract__add = createAdder(1, 'add');
2184 var add_subtract__subtract = createAdder(-1, 'subtract');
2185
2186 function moment_calendar__calendar (time, formats) {
2187 // We want to compare the start of today, vs this.
2188 // Getting start-of-today depends on whether we're local/utc/offset or not.
2189 var now = time || local__createLocal(),
2190 sod = cloneWithOffset(now, this).startOf('day'),
2191 diff = this.diff(sod, 'days', true),
2192 format = diff < -6 ? 'sameElse' :
2193 diff < -1 ? 'lastWeek' :
2194 diff < 0 ? 'lastDay' :
2195 diff < 1 ? 'sameDay' :
2196 diff < 2 ? 'nextDay' :
2197 diff < 7 ? 'nextWeek' : 'sameElse';
2198
2199 var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
2200
2201 return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
2202 }
2203
2204 function clone () {
2205 return new Moment(this);
2206 }
2207
2208 function isAfter (input, units) {
2209 var localInput = isMoment(input) ? input : local__createLocal(input);
2210 if (!(this.isValid() && localInput.isValid())) {
2211 return false;
2212 }
2213 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
2214 if (units === 'millisecond') {
2215 return this.valueOf() > localInput.valueOf();
2216 } else {
2217 return localInput.valueOf() < this.clone().startOf(units).valueOf();
2218 }
2219 }
2220
2221 function isBefore (input, units) {
2222 var localInput = isMoment(input) ? input : local__createLocal(input);
2223 if (!(this.isValid() && localInput.isValid())) {
2224 return false;
2225 }
2226 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
2227 if (units === 'millisecond') {
2228 return this.valueOf() < localInput.valueOf();
2229 } else {
2230 return this.clone().endOf(units).valueOf() < localInput.valueOf();
2231 }
2232 }
2233
2234 function isBetween (from, to, units, inclusivity) {
2235 inclusivity = inclusivity || '()';
2236 return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
2237 (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
2238 }
2239
2240 function isSame (input, units) {
2241 var localInput = isMoment(input) ? input : local__createLocal(input),
2242 inputMs;
2243 if (!(this.isValid() && localInput.isValid())) {
2244 return false;
2245 }
2246 units = normalizeUnits(units || 'millisecond');
2247 if (units === 'millisecond') {
2248 return this.valueOf() === localInput.valueOf();
2249 } else {
2250 inputMs = localInput.valueOf();
2251 return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
2252 }
2253 }
2254
2255 function isSameOrAfter (input, units) {
2256 return this.isSame(input, units) || this.isAfter(input,units);
2257 }
2258
2259 function isSameOrBefore (input, units) {
2260 return this.isSame(input, units) || this.isBefore(input,units);
2261 }
2262
2263 function diff (input, units, asFloat) {
2264 var that,
2265 zoneDelta,
2266 delta, output;
2267
2268 if (!this.isValid()) {
2269 return NaN;
2270 }
2271
2272 that = cloneWithOffset(input, this);
2273
2274 if (!that.isValid()) {
2275 return NaN;
2276 }
2277
2278 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
2279
2280 units = normalizeUnits(units);
2281
2282 if (units === 'year' || units === 'month' || units === 'quarter') {
2283 output = monthDiff(this, that);
2284 if (units === 'quarter') {
2285 output = output / 3;
2286 } else if (units === 'year') {
2287 output = output / 12;
2288 }
2289 } else {
2290 delta = this - that;
2291 output = units === 'second' ? delta / 1e3 : // 1000
2292 units === 'minute' ? delta / 6e4 : // 1000 * 60
2293 units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
2294 units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
2295 units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
2296 delta;
2297 }
2298 return asFloat ? output : absFloor(output);
2299 }
2300
2301 function monthDiff (a, b) {
2302 // difference in months
2303 var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
2304 // b is in (anchor - 1 month, anchor + 1 month)
2305 anchor = a.clone().add(wholeMonthDiff, 'months'),
2306 anchor2, adjust;
2307
2308 if (b - anchor < 0) {
2309 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
2310 // linear across the month
2311 adjust = (b - anchor) / (anchor - anchor2);
2312 } else {
2313 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
2314 // linear across the month
2315 adjust = (b - anchor) / (anchor2 - anchor);
2316 }
2317
2318 //check for negative zero, return zero if negative zero
2319 return -(wholeMonthDiff + adjust) || 0;
2320 }
2321
2322 utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
2323 utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
2324
2325 function toString () {
2326 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
2327 }
2328
2329 function moment_format__toISOString () {
2330 var m = this.clone().utc();
2331 if (0 < m.year() && m.year() <= 9999) {
2332 if (isFunction(Date.prototype.toISOString)) {
2333 // native implementation is ~50x faster, use it when we can
2334 return this.toDate().toISOString();
2335 } else {
2336 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2337 }
2338 } else {
2339 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2340 }
2341 }
2342
2343 function format (inputString) {
2344 if (!inputString) {
2345 inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat;
2346 }
2347 var output = formatMoment(this, inputString);
2348 return this.localeData().postformat(output);
2349 }
2350
2351 function from (time, withoutSuffix) {
2352 if (this.isValid() &&
2353 ((isMoment(time) && time.isValid()) ||
2354 local__createLocal(time).isValid())) {
2355 return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
2356 } else {
2357 return this.localeData().invalidDate();
2358 }
2359 }
2360
2361 function fromNow (withoutSuffix) {
2362 return this.from(local__createLocal(), withoutSuffix);
2363 }
2364
2365 function to (time, withoutSuffix) {
2366 if (this.isValid() &&
2367 ((isMoment(time) && time.isValid()) ||
2368 local__createLocal(time).isValid())) {
2369 return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
2370 } else {
2371 return this.localeData().invalidDate();
2372 }
2373 }
2374
2375 function toNow (withoutSuffix) {
2376 return this.to(local__createLocal(), withoutSuffix);
2377 }
2378
2379 // If passed a locale key, it will set the locale for this
2380 // instance. Otherwise, it will return the locale configuration
2381 // variables for this instance.
2382 function locale (key) {
2383 var newLocaleData;
2384
2385 if (key === undefined) {
2386 return this._locale._abbr;
2387 } else {
2388 newLocaleData = locale_locales__getLocale(key);
2389 if (newLocaleData != null) {
2390 this._locale = newLocaleData;
2391 }
2392 return this;
2393 }
2394 }
2395
2396 var lang = deprecate(
2397 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
2398 function (key) {
2399 if (key === undefined) {
2400 return this.localeData();
2401 } else {
2402 return this.locale(key);
2403 }
2404 }
2405 );
2406
2407 function localeData () {
2408 return this._locale;
2409 }
2410
2411 function startOf (units) {
2412 units = normalizeUnits(units);
2413 // the following switch intentionally omits break keywords
2414 // to utilize falling through the cases.
2415 switch (units) {
2416 case 'year':
2417 this.month(0);
2418 /* falls through */
2419 case 'quarter':
2420 case 'month':
2421 this.date(1);
2422 /* falls through */
2423 case 'week':
2424 case 'isoWeek':
2425 case 'day':
2426 case 'date':
2427 this.hours(0);
2428 /* falls through */
2429 case 'hour':
2430 this.minutes(0);
2431 /* falls through */
2432 case 'minute':
2433 this.seconds(0);
2434 /* falls through */
2435 case 'second':
2436 this.milliseconds(0);
2437 }
2438
2439 // weeks are a special case
2440 if (units === 'week') {
2441 this.weekday(0);
2442 }
2443 if (units === 'isoWeek') {
2444 this.isoWeekday(1);
2445 }
2446
2447 // quarters are also special
2448 if (units === 'quarter') {
2449 this.month(Math.floor(this.month() / 3) * 3);
2450 }
2451
2452 return this;
2453 }
2454
2455 function endOf (units) {
2456 units = normalizeUnits(units);
2457 if (units === undefined || units === 'millisecond') {
2458 return this;
2459 }
2460
2461 // 'date' is an alias for 'day', so it should be considered as such.
2462 if (units === 'date') {
2463 units = 'day';
2464 }
2465
2466 return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
2467 }
2468
2469 function to_type__valueOf () {
2470 return this._d.valueOf() - ((this._offset || 0) * 60000);
2471 }
2472
2473 function unix () {
2474 return Math.floor(this.valueOf() / 1000);
2475 }
2476
2477 function toDate () {
2478 return this._offset ? new Date(this.valueOf()) : this._d;
2479 }
2480
2481 function toArray () {
2482 var m = this;
2483 return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
2484 }
2485
2486 function toObject () {
2487 var m = this;
2488 return {
2489 years: m.year(),
2490 months: m.month(),
2491 date: m.date(),
2492 hours: m.hours(),
2493 minutes: m.minutes(),
2494 seconds: m.seconds(),
2495 milliseconds: m.milliseconds()
2496 };
2497 }
2498
2499 function toJSON () {
2500 // new Date(NaN).toJSON() === null
2501 return this.isValid() ? this.toISOString() : null;
2502 }
2503
2504 function moment_valid__isValid () {
2505 return valid__isValid(this);
2506 }
2507
2508 function parsingFlags () {
2509 return extend({}, getParsingFlags(this));
2510 }
2511
2512 function invalidAt () {
2513 return getParsingFlags(this).overflow;
2514 }
2515
2516 function creationData() {
2517 return {
2518 input: this._i,
2519 format: this._f,
2520 locale: this._locale,
2521 isUTC: this._isUTC,
2522 strict: this._strict
2523 };
2524 }
2525
2526 // FORMATTING
2527
2528 addFormatToken(0, ['gg', 2], 0, function () {
2529 return this.weekYear() % 100;
2530 });
2531
2532 addFormatToken(0, ['GG', 2], 0, function () {
2533 return this.isoWeekYear() % 100;
2534 });
2535
2536 function addWeekYearFormatToken (token, getter) {
2537 addFormatToken(0, [token, token.length], 0, getter);
2538 }
2539
2540 addWeekYearFormatToken('gggg', 'weekYear');
2541 addWeekYearFormatToken('ggggg', 'weekYear');
2542 addWeekYearFormatToken('GGGG', 'isoWeekYear');
2543 addWeekYearFormatToken('GGGGG', 'isoWeekYear');
2544
2545 // ALIASES
2546
2547 addUnitAlias('weekYear', 'gg');
2548 addUnitAlias('isoWeekYear', 'GG');
2549
2550 // PARSING
2551
2552 addRegexToken('G', matchSigned);
2553 addRegexToken('g', matchSigned);
2554 addRegexToken('GG', match1to2, match2);
2555 addRegexToken('gg', match1to2, match2);
2556 addRegexToken('GGGG', match1to4, match4);
2557 addRegexToken('gggg', match1to4, match4);
2558 addRegexToken('GGGGG', match1to6, match6);
2559 addRegexToken('ggggg', match1to6, match6);
2560
2561 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
2562 week[token.substr(0, 2)] = toInt(input);
2563 });
2564
2565 addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
2566 week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
2567 });
2568
2569 // MOMENTS
2570
2571 function getSetWeekYear (input) {
2572 return getSetWeekYearHelper.call(this,
2573 input,
2574 this.week(),
2575 this.weekday(),
2576 this.localeData()._week.dow,
2577 this.localeData()._week.doy);
2578 }
2579
2580 function getSetISOWeekYear (input) {
2581 return getSetWeekYearHelper.call(this,
2582 input, this.isoWeek(), this.isoWeekday(), 1, 4);
2583 }
2584
2585 function getISOWeeksInYear () {
2586 return weeksInYear(this.year(), 1, 4);
2587 }
2588
2589 function getWeeksInYear () {
2590 var weekInfo = this.localeData()._week;
2591 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
2592 }
2593
2594 function getSetWeekYearHelper(input, week, weekday, dow, doy) {
2595 var weeksTarget;
2596 if (input == null) {
2597 return weekOfYear(this, dow, doy).year;
2598 } else {
2599 weeksTarget = weeksInYear(input, dow, doy);
2600 if (week > weeksTarget) {
2601 week = weeksTarget;
2602 }
2603 return setWeekAll.call(this, input, week, weekday, dow, doy);
2604 }
2605 }
2606
2607 function setWeekAll(weekYear, week, weekday, dow, doy) {
2608 var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
2609 date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
2610
2611 this.year(date.getUTCFullYear());
2612 this.month(date.getUTCMonth());
2613 this.date(date.getUTCDate());
2614 return this;
2615 }
2616
2617 // FORMATTING
2618
2619 addFormatToken('Q', 0, 'Qo', 'quarter');
2620
2621 // ALIASES
2622
2623 addUnitAlias('quarter', 'Q');
2624
2625 // PARSING
2626
2627 addRegexToken('Q', match1);
2628 addParseToken('Q', function (input, array) {
2629 array[MONTH] = (toInt(input) - 1) * 3;
2630 });
2631
2632 // MOMENTS
2633
2634 function getSetQuarter (input) {
2635 return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
2636 }
2637
2638 // FORMATTING
2639
2640 addFormatToken('w', ['ww', 2], 'wo', 'week');
2641 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
2642
2643 // ALIASES
2644
2645 addUnitAlias('week', 'w');
2646 addUnitAlias('isoWeek', 'W');
2647
2648 // PARSING
2649
2650 addRegexToken('w', match1to2);
2651 addRegexToken('ww', match1to2, match2);
2652 addRegexToken('W', match1to2);
2653 addRegexToken('WW', match1to2, match2);
2654
2655 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
2656 week[token.substr(0, 1)] = toInt(input);
2657 });
2658
2659 // HELPERS
2660
2661 // LOCALES
2662
2663 function localeWeek (mom) {
2664 return weekOfYear(mom, this._week.dow, this._week.doy).week;
2665 }
2666
2667 var defaultLocaleWeek = {
2668 dow : 0, // Sunday is the first day of the week.
2669 doy : 6 // The week that contains Jan 1st is the first week of the year.
2670 };
2671
2672 function localeFirstDayOfWeek () {
2673 return this._week.dow;
2674 }
2675
2676 function localeFirstDayOfYear () {
2677 return this._week.doy;
2678 }
2679
2680 // MOMENTS
2681
2682 function getSetWeek (input) {
2683 var week = this.localeData().week(this);
2684 return input == null ? week : this.add((input - week) * 7, 'd');
2685 }
2686
2687 function getSetISOWeek (input) {
2688 var week = weekOfYear(this, 1, 4).week;
2689 return input == null ? week : this.add((input - week) * 7, 'd');
2690 }
2691
2692 // FORMATTING
2693
2694 addFormatToken('D', ['DD', 2], 'Do', 'date');
2695
2696 // ALIASES
2697
2698 addUnitAlias('date', 'D');
2699
2700 // PARSING
2701
2702 addRegexToken('D', match1to2);
2703 addRegexToken('DD', match1to2, match2);
2704 addRegexToken('Do', function (isStrict, locale) {
2705 return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
2706 });
2707
2708 addParseToken(['D', 'DD'], DATE);
2709 addParseToken('Do', function (input, array) {
2710 array[DATE] = toInt(input.match(match1to2)[0], 10);
2711 });
2712
2713 // MOMENTS
2714
2715 var getSetDayOfMonth = makeGetSet('Date', true);
2716
2717 // FORMATTING
2718
2719 addFormatToken('d', 0, 'do', 'day');
2720
2721 addFormatToken('dd', 0, 0, function (format) {
2722 return this.localeData().weekdaysMin(this, format);
2723 });
2724
2725 addFormatToken('ddd', 0, 0, function (format) {
2726 return this.localeData().weekdaysShort(this, format);
2727 });
2728
2729 addFormatToken('dddd', 0, 0, function (format) {
2730 return this.localeData().weekdays(this, format);
2731 });
2732
2733 addFormatToken('e', 0, 0, 'weekday');
2734 addFormatToken('E', 0, 0, 'isoWeekday');
2735
2736 // ALIASES
2737
2738 addUnitAlias('day', 'd');
2739 addUnitAlias('weekday', 'e');
2740 addUnitAlias('isoWeekday', 'E');
2741
2742 // PARSING
2743
2744 addRegexToken('d', match1to2);
2745 addRegexToken('e', match1to2);
2746 addRegexToken('E', match1to2);
2747 addRegexToken('dd', function (isStrict, locale) {
2748 return locale.weekdaysMinRegex(isStrict);
2749 });
2750 addRegexToken('ddd', function (isStrict, locale) {
2751 return locale.weekdaysShortRegex(isStrict);
2752 });
2753 addRegexToken('dddd', function (isStrict, locale) {
2754 return locale.weekdaysRegex(isStrict);
2755 });
2756
2757 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
2758 var weekday = config._locale.weekdaysParse(input, token, config._strict);
2759 // if we didn't get a weekday name, mark the date as invalid
2760 if (weekday != null) {
2761 week.d = weekday;
2762 } else {
2763 getParsingFlags(config).invalidWeekday = input;
2764 }
2765 });
2766
2767 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
2768 week[token] = toInt(input);
2769 });
2770
2771 // HELPERS
2772
2773 function parseWeekday(input, locale) {
2774 if (typeof input !== 'string') {
2775 return input;
2776 }
2777
2778 if (!isNaN(input)) {
2779 return parseInt(input, 10);
2780 }
2781
2782 input = locale.weekdaysParse(input);
2783 if (typeof input === 'number') {
2784 return input;
2785 }
2786
2787 return null;
2788 }
2789
2790 // LOCALES
2791
2792 var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
2793 function localeWeekdays (m, format) {
2794 return isArray(this._weekdays) ? this._weekdays[m.day()] :
2795 this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
2796 }
2797
2798 var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
2799 function localeWeekdaysShort (m) {
2800 return this._weekdaysShort[m.day()];
2801 }
2802
2803 var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
2804 function localeWeekdaysMin (m) {
2805 return this._weekdaysMin[m.day()];
2806 }
2807
2808 function day_of_week__handleStrictParse(weekdayName, format, strict) {
2809 var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
2810 if (!this._weekdaysParse) {
2811 this._weekdaysParse = [];
2812 this._shortWeekdaysParse = [];
2813 this._minWeekdaysParse = [];
2814
2815 for (i = 0; i < 7; ++i) {
2816 mom = create_utc__createUTC([2000, 1]).day(i);
2817 this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
2818 this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
2819 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
2820 }
2821 }
2822
2823 if (strict) {
2824 if (format === 'dddd') {
2825 ii = indexOf.call(this._weekdaysParse, llc);
2826 return ii !== -1 ? ii : null;
2827 } else if (format === 'ddd') {
2828 ii = indexOf.call(this._shortWeekdaysParse, llc);
2829 return ii !== -1 ? ii : null;
2830 } else {
2831 ii = indexOf.call(this._minWeekdaysParse, llc);
2832 return ii !== -1 ? ii : null;
2833 }
2834 } else {
2835 if (format === 'dddd') {
2836 ii = indexOf.call(this._weekdaysParse, llc);
2837 if (ii !== -1) {
2838 return ii;
2839 }
2840 ii = indexOf.call(this._shortWeekdaysParse, llc);
2841 if (ii !== -1) {
2842 return ii;
2843 }
2844 ii = indexOf.call(this._minWeekdaysParse, llc);
2845 return ii !== -1 ? ii : null;
2846 } else if (format === 'ddd') {
2847 ii = indexOf.call(this._shortWeekdaysParse, llc);
2848 if (ii !== -1) {
2849 return ii;
2850 }
2851 ii = indexOf.call(this._weekdaysParse, llc);
2852 if (ii !== -1) {
2853 return ii;
2854 }
2855 ii = indexOf.call(this._minWeekdaysParse, llc);
2856 return ii !== -1 ? ii : null;
2857 } else {
2858 ii = indexOf.call(this._minWeekdaysParse, llc);
2859 if (ii !== -1) {
2860 return ii;
2861 }
2862 ii = indexOf.call(this._weekdaysParse, llc);
2863 if (ii !== -1) {
2864 return ii;
2865 }
2866 ii = indexOf.call(this._shortWeekdaysParse, llc);
2867 return ii !== -1 ? ii : null;
2868 }
2869 }
2870 }
2871
2872 function localeWeekdaysParse (weekdayName, format, strict) {
2873 var i, mom, regex;
2874
2875 if (this._weekdaysParseExact) {
2876 return day_of_week__handleStrictParse.call(this, weekdayName, format, strict);
2877 }
2878
2879 if (!this._weekdaysParse) {
2880 this._weekdaysParse = [];
2881 this._minWeekdaysParse = [];
2882 this._shortWeekdaysParse = [];
2883 this._fullWeekdaysParse = [];
2884 }
2885
2886 for (i = 0; i < 7; i++) {
2887 // make the regex if we don't have it already
2888
2889 mom = create_utc__createUTC([2000, 1]).day(i);
2890 if (strict && !this._fullWeekdaysParse[i]) {
2891 this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
2892 this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
2893 this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
2894 }
2895 if (!this._weekdaysParse[i]) {
2896 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
2897 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
2898 }
2899 // test the regex
2900 if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
2901 return i;
2902 } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
2903 return i;
2904 } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
2905 return i;
2906 } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
2907 return i;
2908 }
2909 }
2910 }
2911
2912 // MOMENTS
2913
2914 function getSetDayOfWeek (input) {
2915 if (!this.isValid()) {
2916 return input != null ? this : NaN;
2917 }
2918 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
2919 if (input != null) {
2920 input = parseWeekday(input, this.localeData());
2921 return this.add(input - day, 'd');
2922 } else {
2923 return day;
2924 }
2925 }
2926
2927 function getSetLocaleDayOfWeek (input) {
2928 if (!this.isValid()) {
2929 return input != null ? this : NaN;
2930 }
2931 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
2932 return input == null ? weekday : this.add(input - weekday, 'd');
2933 }
2934
2935 function getSetISODayOfWeek (input) {
2936 if (!this.isValid()) {
2937 return input != null ? this : NaN;
2938 }
2939 // behaves the same as moment#day except
2940 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
2941 // as a setter, sunday should belong to the previous week.
2942 return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
2943 }
2944
2945 var defaultWeekdaysRegex = matchWord;
2946 function weekdaysRegex (isStrict) {
2947 if (this._weekdaysParseExact) {
2948 if (!hasOwnProp(this, '_weekdaysRegex')) {
2949 computeWeekdaysParse.call(this);
2950 }
2951 if (isStrict) {
2952 return this._weekdaysStrictRegex;
2953 } else {
2954 return this._weekdaysRegex;
2955 }
2956 } else {
2957 return this._weekdaysStrictRegex && isStrict ?
2958 this._weekdaysStrictRegex : this._weekdaysRegex;
2959 }
2960 }
2961
2962 var defaultWeekdaysShortRegex = matchWord;
2963 function weekdaysShortRegex (isStrict) {
2964 if (this._weekdaysParseExact) {
2965 if (!hasOwnProp(this, '_weekdaysRegex')) {
2966 computeWeekdaysParse.call(this);
2967 }
2968 if (isStrict) {
2969 return this._weekdaysShortStrictRegex;
2970 } else {
2971 return this._weekdaysShortRegex;
2972 }
2973 } else {
2974 return this._weekdaysShortStrictRegex && isStrict ?
2975 this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
2976 }
2977 }
2978
2979 var defaultWeekdaysMinRegex = matchWord;
2980 function weekdaysMinRegex (isStrict) {
2981 if (this._weekdaysParseExact) {
2982 if (!hasOwnProp(this, '_weekdaysRegex')) {
2983 computeWeekdaysParse.call(this);
2984 }
2985 if (isStrict) {
2986 return this._weekdaysMinStrictRegex;
2987 } else {
2988 return this._weekdaysMinRegex;
2989 }
2990 } else {
2991 return this._weekdaysMinStrictRegex && isStrict ?
2992 this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
2993 }
2994 }
2995
2996
2997 function computeWeekdaysParse () {
2998 function cmpLenRev(a, b) {
2999 return b.length - a.length;
3000 }
3001
3002 var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
3003 i, mom, minp, shortp, longp;
3004 for (i = 0; i < 7; i++) {
3005 // make the regex if we don't have it already
3006 mom = create_utc__createUTC([2000, 1]).day(i);
3007 minp = this.weekdaysMin(mom, '');
3008 shortp = this.weekdaysShort(mom, '');
3009 longp = this.weekdays(mom, '');
3010 minPieces.push(minp);
3011 shortPieces.push(shortp);
3012 longPieces.push(longp);
3013 mixedPieces.push(minp);
3014 mixedPieces.push(shortp);
3015 mixedPieces.push(longp);
3016 }
3017 // Sorting makes sure if one weekday (or abbr) is a prefix of another it
3018 // will match the longer piece.
3019 minPieces.sort(cmpLenRev);
3020 shortPieces.sort(cmpLenRev);
3021 longPieces.sort(cmpLenRev);
3022 mixedPieces.sort(cmpLenRev);
3023 for (i = 0; i < 7; i++) {
3024 shortPieces[i] = regexEscape(shortPieces[i]);
3025 longPieces[i] = regexEscape(longPieces[i]);
3026 mixedPieces[i] = regexEscape(mixedPieces[i]);
3027 }
3028
3029 this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
3030 this._weekdaysShortRegex = this._weekdaysRegex;
3031 this._weekdaysMinRegex = this._weekdaysRegex;
3032
3033 this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
3034 this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
3035 this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
3036 }
3037
3038 // FORMATTING
3039
3040 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
3041
3042 // ALIASES
3043
3044 addUnitAlias('dayOfYear', 'DDD');
3045
3046 // PARSING
3047
3048 addRegexToken('DDD', match1to3);
3049 addRegexToken('DDDD', match3);
3050 addParseToken(['DDD', 'DDDD'], function (input, array, config) {
3051 config._dayOfYear = toInt(input);
3052 });
3053
3054 // HELPERS
3055
3056 // MOMENTS
3057
3058 function getSetDayOfYear (input) {
3059 var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
3060 return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
3061 }
3062
3063 // FORMATTING
3064
3065 function hFormat() {
3066 return this.hours() % 12 || 12;
3067 }
3068
3069 function kFormat() {
3070 return this.hours() || 24;
3071 }
3072
3073 addFormatToken('H', ['HH', 2], 0, 'hour');
3074 addFormatToken('h', ['hh', 2], 0, hFormat);
3075 addFormatToken('k', ['kk', 2], 0, kFormat);
3076
3077 addFormatToken('hmm', 0, 0, function () {
3078 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
3079 });
3080
3081 addFormatToken('hmmss', 0, 0, function () {
3082 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
3083 zeroFill(this.seconds(), 2);
3084 });
3085
3086 addFormatToken('Hmm', 0, 0, function () {
3087 return '' + this.hours() + zeroFill(this.minutes(), 2);
3088 });
3089
3090 addFormatToken('Hmmss', 0, 0, function () {
3091 return '' + this.hours() + zeroFill(this.minutes(), 2) +
3092 zeroFill(this.seconds(), 2);
3093 });
3094
3095 function meridiem (token, lowercase) {
3096 addFormatToken(token, 0, 0, function () {
3097 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
3098 });
3099 }
3100
3101 meridiem('a', true);
3102 meridiem('A', false);
3103
3104 // ALIASES
3105
3106 addUnitAlias('hour', 'h');
3107
3108 // PARSING
3109
3110 function matchMeridiem (isStrict, locale) {
3111 return locale._meridiemParse;
3112 }
3113
3114 addRegexToken('a', matchMeridiem);
3115 addRegexToken('A', matchMeridiem);
3116 addRegexToken('H', match1to2);
3117 addRegexToken('h', match1to2);
3118 addRegexToken('HH', match1to2, match2);
3119 addRegexToken('hh', match1to2, match2);
3120
3121 addRegexToken('hmm', match3to4);
3122 addRegexToken('hmmss', match5to6);
3123 addRegexToken('Hmm', match3to4);
3124 addRegexToken('Hmmss', match5to6);
3125
3126 addParseToken(['H', 'HH'], HOUR);
3127 addParseToken(['a', 'A'], function (input, array, config) {
3128 config._isPm = config._locale.isPM(input);
3129 config._meridiem = input;
3130 });
3131 addParseToken(['h', 'hh'], function (input, array, config) {
3132 array[HOUR] = toInt(input);
3133 getParsingFlags(config).bigHour = true;
3134 });
3135 addParseToken('hmm', function (input, array, config) {
3136 var pos = input.length - 2;
3137 array[HOUR] = toInt(input.substr(0, pos));
3138 array[MINUTE] = toInt(input.substr(pos));
3139 getParsingFlags(config).bigHour = true;
3140 });
3141 addParseToken('hmmss', function (input, array, config) {
3142 var pos1 = input.length - 4;
3143 var pos2 = input.length - 2;
3144 array[HOUR] = toInt(input.substr(0, pos1));
3145 array[MINUTE] = toInt(input.substr(pos1, 2));
3146 array[SECOND] = toInt(input.substr(pos2));
3147 getParsingFlags(config).bigHour = true;
3148 });
3149 addParseToken('Hmm', function (input, array, config) {
3150 var pos = input.length - 2;
3151 array[HOUR] = toInt(input.substr(0, pos));
3152 array[MINUTE] = toInt(input.substr(pos));
3153 });
3154 addParseToken('Hmmss', function (input, array, config) {
3155 var pos1 = input.length - 4;
3156 var pos2 = input.length - 2;
3157 array[HOUR] = toInt(input.substr(0, pos1));
3158 array[MINUTE] = toInt(input.substr(pos1, 2));
3159 array[SECOND] = toInt(input.substr(pos2));
3160 });
3161
3162 // LOCALES
3163
3164 function localeIsPM (input) {
3165 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
3166 // Using charAt should be more compatible.
3167 return ((input + '').toLowerCase().charAt(0) === 'p');
3168 }
3169
3170 var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
3171 function localeMeridiem (hours, minutes, isLower) {
3172 if (hours > 11) {
3173 return isLower ? 'pm' : 'PM';
3174 } else {
3175 return isLower ? 'am' : 'AM';
3176 }
3177 }
3178
3179
3180 // MOMENTS
3181
3182 // Setting the hour should keep the time, because the user explicitly
3183 // specified which hour he wants. So trying to maintain the same hour (in
3184 // a new timezone) makes sense. Adding/subtracting hours does not follow
3185 // this rule.
3186 var getSetHour = makeGetSet('Hours', true);
3187
3188 // FORMATTING
3189
3190 addFormatToken('m', ['mm', 2], 0, 'minute');
3191
3192 // ALIASES
3193
3194 addUnitAlias('minute', 'm');
3195
3196 // PARSING
3197
3198 addRegexToken('m', match1to2);
3199 addRegexToken('mm', match1to2, match2);
3200 addParseToken(['m', 'mm'], MINUTE);
3201
3202 // MOMENTS
3203
3204 var getSetMinute = makeGetSet('Minutes', false);
3205
3206 // FORMATTING
3207
3208 addFormatToken('s', ['ss', 2], 0, 'second');
3209
3210 // ALIASES
3211
3212 addUnitAlias('second', 's');
3213
3214 // PARSING
3215
3216 addRegexToken('s', match1to2);
3217 addRegexToken('ss', match1to2, match2);
3218 addParseToken(['s', 'ss'], SECOND);
3219
3220 // MOMENTS
3221
3222 var getSetSecond = makeGetSet('Seconds', false);
3223
3224 // FORMATTING
3225
3226 addFormatToken('S', 0, 0, function () {
3227 return ~~(this.millisecond() / 100);
3228 });
3229
3230 addFormatToken(0, ['SS', 2], 0, function () {
3231 return ~~(this.millisecond() / 10);
3232 });
3233
3234 addFormatToken(0, ['SSS', 3], 0, 'millisecond');
3235 addFormatToken(0, ['SSSS', 4], 0, function () {
3236 return this.millisecond() * 10;
3237 });
3238 addFormatToken(0, ['SSSSS', 5], 0, function () {
3239 return this.millisecond() * 100;
3240 });
3241 addFormatToken(0, ['SSSSSS', 6], 0, function () {
3242 return this.millisecond() * 1000;
3243 });
3244 addFormatToken(0, ['SSSSSSS', 7], 0, function () {
3245 return this.millisecond() * 10000;
3246 });
3247 addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
3248 return this.millisecond() * 100000;
3249 });
3250 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
3251 return this.millisecond() * 1000000;
3252 });
3253
3254
3255 // ALIASES
3256
3257 addUnitAlias('millisecond', 'ms');
3258
3259 // PARSING
3260
3261 addRegexToken('S', match1to3, match1);
3262 addRegexToken('SS', match1to3, match2);
3263 addRegexToken('SSS', match1to3, match3);
3264
3265 var token;
3266 for (token = 'SSSS'; token.length <= 9; token += 'S') {
3267 addRegexToken(token, matchUnsigned);
3268 }
3269
3270 function parseMs(input, array) {
3271 array[MILLISECOND] = toInt(('0.' + input) * 1000);
3272 }
3273
3274 for (token = 'S'; token.length <= 9; token += 'S') {
3275 addParseToken(token, parseMs);
3276 }
3277 // MOMENTS
3278
3279 var getSetMillisecond = makeGetSet('Milliseconds', false);
3280
3281 // FORMATTING
3282
3283 addFormatToken('z', 0, 0, 'zoneAbbr');
3284 addFormatToken('zz', 0, 0, 'zoneName');
3285
3286 // MOMENTS
3287
3288 function getZoneAbbr () {
3289 return this._isUTC ? 'UTC' : '';
3290 }
3291
3292 function getZoneName () {
3293 return this._isUTC ? 'Coordinated Universal Time' : '';
3294 }
3295
3296 var momentPrototype__proto = Moment.prototype;
3297
3298 momentPrototype__proto.add = add_subtract__add;
3299 momentPrototype__proto.calendar = moment_calendar__calendar;
3300 momentPrototype__proto.clone = clone;
3301 momentPrototype__proto.diff = diff;
3302 momentPrototype__proto.endOf = endOf;
3303 momentPrototype__proto.format = format;
3304 momentPrototype__proto.from = from;
3305 momentPrototype__proto.fromNow = fromNow;
3306 momentPrototype__proto.to = to;
3307 momentPrototype__proto.toNow = toNow;
3308 momentPrototype__proto.get = getSet;
3309 momentPrototype__proto.invalidAt = invalidAt;
3310 momentPrototype__proto.isAfter = isAfter;
3311 momentPrototype__proto.isBefore = isBefore;
3312 momentPrototype__proto.isBetween = isBetween;
3313 momentPrototype__proto.isSame = isSame;
3314 momentPrototype__proto.isSameOrAfter = isSameOrAfter;
3315 momentPrototype__proto.isSameOrBefore = isSameOrBefore;
3316 momentPrototype__proto.isValid = moment_valid__isValid;
3317 momentPrototype__proto.lang = lang;
3318 momentPrototype__proto.locale = locale;
3319 momentPrototype__proto.localeData = localeData;
3320 momentPrototype__proto.max = prototypeMax;
3321 momentPrototype__proto.min = prototypeMin;
3322 momentPrototype__proto.parsingFlags = parsingFlags;
3323 momentPrototype__proto.set = getSet;
3324 momentPrototype__proto.startOf = startOf;
3325 momentPrototype__proto.subtract = add_subtract__subtract;
3326 momentPrototype__proto.toArray = toArray;
3327 momentPrototype__proto.toObject = toObject;
3328 momentPrototype__proto.toDate = toDate;
3329 momentPrototype__proto.toISOString = moment_format__toISOString;
3330 momentPrototype__proto.toJSON = toJSON;
3331 momentPrototype__proto.toString = toString;
3332 momentPrototype__proto.unix = unix;
3333 momentPrototype__proto.valueOf = to_type__valueOf;
3334 momentPrototype__proto.creationData = creationData;
3335
3336 // Year
3337 momentPrototype__proto.year = getSetYear;
3338 momentPrototype__proto.isLeapYear = getIsLeapYear;
3339
3340 // Week Year
3341 momentPrototype__proto.weekYear = getSetWeekYear;
3342 momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
3343
3344 // Quarter
3345 momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
3346
3347 // Month
3348 momentPrototype__proto.month = getSetMonth;
3349 momentPrototype__proto.daysInMonth = getDaysInMonth;
3350
3351 // Week
3352 momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
3353 momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
3354 momentPrototype__proto.weeksInYear = getWeeksInYear;
3355 momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
3356
3357 // Day
3358 momentPrototype__proto.date = getSetDayOfMonth;
3359 momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
3360 momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
3361 momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
3362 momentPrototype__proto.dayOfYear = getSetDayOfYear;
3363
3364 // Hour
3365 momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
3366
3367 // Minute
3368 momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
3369
3370 // Second
3371 momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
3372
3373 // Millisecond
3374 momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
3375
3376 // Offset
3377 momentPrototype__proto.utcOffset = getSetOffset;
3378 momentPrototype__proto.utc = setOffsetToUTC;
3379 momentPrototype__proto.local = setOffsetToLocal;
3380 momentPrototype__proto.parseZone = setOffsetToParsedOffset;
3381 momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
3382 momentPrototype__proto.isDST = isDaylightSavingTime;
3383 momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
3384 momentPrototype__proto.isLocal = isLocal;
3385 momentPrototype__proto.isUtcOffset = isUtcOffset;
3386 momentPrototype__proto.isUtc = isUtc;
3387 momentPrototype__proto.isUTC = isUtc;
3388
3389 // Timezone
3390 momentPrototype__proto.zoneAbbr = getZoneAbbr;
3391 momentPrototype__proto.zoneName = getZoneName;
3392
3393 // Deprecations
3394 momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
3395 momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
3396 momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
3397 momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
3398
3399 var momentPrototype = momentPrototype__proto;
3400
3401 function moment__createUnix (input) {
3402 return local__createLocal(input * 1000);
3403 }
3404
3405 function moment__createInZone () {
3406 return local__createLocal.apply(null, arguments).parseZone();
3407 }
3408
3409 var defaultCalendar = {
3410 sameDay : '[Today at] LT',
3411 nextDay : '[Tomorrow at] LT',
3412 nextWeek : 'dddd [at] LT',
3413 lastDay : '[Yesterday at] LT',
3414 lastWeek : '[Last] dddd [at] LT',
3415 sameElse : 'L'
3416 };
3417
3418 function locale_calendar__calendar (key, mom, now) {
3419 var output = this._calendar[key];
3420 return isFunction(output) ? output.call(mom, now) : output;
3421 }
3422
3423 var defaultLongDateFormat = {
3424 LTS : 'h:mm:ss A',
3425 LT : 'h:mm A',
3426 L : 'MM/DD/YYYY',
3427 LL : 'MMMM D, YYYY',
3428 LLL : 'MMMM D, YYYY h:mm A',
3429 LLLL : 'dddd, MMMM D, YYYY h:mm A'
3430 };
3431
3432 function longDateFormat (key) {
3433 var format = this._longDateFormat[key],
3434 formatUpper = this._longDateFormat[key.toUpperCase()];
3435
3436 if (format || !formatUpper) {
3437 return format;
3438 }
3439
3440 this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
3441 return val.slice(1);
3442 });
3443
3444 return this._longDateFormat[key];
3445 }
3446
3447 var defaultInvalidDate = 'Invalid date';
3448
3449 function invalidDate () {
3450 return this._invalidDate;
3451 }
3452
3453 var defaultOrdinal = '%d';
3454 var defaultOrdinalParse = /\d{1,2}/;
3455
3456 function ordinal (number) {
3457 return this._ordinal.replace('%d', number);
3458 }
3459
3460 function preParsePostFormat (string) {
3461 return string;
3462 }
3463
3464 var defaultRelativeTime = {
3465 future : 'in %s',
3466 past : '%s ago',
3467 s : 'a few seconds',
3468 m : 'a minute',
3469 mm : '%d minutes',
3470 h : 'an hour',
3471 hh : '%d hours',
3472 d : 'a day',
3473 dd : '%d days',
3474 M : 'a month',
3475 MM : '%d months',
3476 y : 'a year',
3477 yy : '%d years'
3478 };
3479
3480 function relative__relativeTime (number, withoutSuffix, string, isFuture) {
3481 var output = this._relativeTime[string];
3482 return (isFunction(output)) ?
3483 output(number, withoutSuffix, string, isFuture) :
3484 output.replace(/%d/i, number);
3485 }
3486
3487 function pastFuture (diff, output) {
3488 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
3489 return isFunction(format) ? format(output) : format.replace(/%s/i, output);
3490 }
3491
3492 var prototype__proto = Locale.prototype;
3493
3494 prototype__proto._calendar = defaultCalendar;
3495 prototype__proto.calendar = locale_calendar__calendar;
3496 prototype__proto._longDateFormat = defaultLongDateFormat;
3497 prototype__proto.longDateFormat = longDateFormat;
3498 prototype__proto._invalidDate = defaultInvalidDate;
3499 prototype__proto.invalidDate = invalidDate;
3500 prototype__proto._ordinal = defaultOrdinal;
3501 prototype__proto.ordinal = ordinal;
3502 prototype__proto._ordinalParse = defaultOrdinalParse;
3503 prototype__proto.preparse = preParsePostFormat;
3504 prototype__proto.postformat = preParsePostFormat;
3505 prototype__proto._relativeTime = defaultRelativeTime;
3506 prototype__proto.relativeTime = relative__relativeTime;
3507 prototype__proto.pastFuture = pastFuture;
3508 prototype__proto.set = locale_set__set;
3509
3510 // Month
3511 prototype__proto.months = localeMonths;
3512 prototype__proto._months = defaultLocaleMonths;
3513 prototype__proto.monthsShort = localeMonthsShort;
3514 prototype__proto._monthsShort = defaultLocaleMonthsShort;
3515 prototype__proto.monthsParse = localeMonthsParse;
3516 prototype__proto._monthsRegex = defaultMonthsRegex;
3517 prototype__proto.monthsRegex = monthsRegex;
3518 prototype__proto._monthsShortRegex = defaultMonthsShortRegex;
3519 prototype__proto.monthsShortRegex = monthsShortRegex;
3520
3521 // Week
3522 prototype__proto.week = localeWeek;
3523 prototype__proto._week = defaultLocaleWeek;
3524 prototype__proto.firstDayOfYear = localeFirstDayOfYear;
3525 prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
3526
3527 // Day of Week
3528 prototype__proto.weekdays = localeWeekdays;
3529 prototype__proto._weekdays = defaultLocaleWeekdays;
3530 prototype__proto.weekdaysMin = localeWeekdaysMin;
3531 prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
3532 prototype__proto.weekdaysShort = localeWeekdaysShort;
3533 prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
3534 prototype__proto.weekdaysParse = localeWeekdaysParse;
3535
3536 prototype__proto._weekdaysRegex = defaultWeekdaysRegex;
3537 prototype__proto.weekdaysRegex = weekdaysRegex;
3538 prototype__proto._weekdaysShortRegex = defaultWeekdaysShortRegex;
3539 prototype__proto.weekdaysShortRegex = weekdaysShortRegex;
3540 prototype__proto._weekdaysMinRegex = defaultWeekdaysMinRegex;
3541 prototype__proto.weekdaysMinRegex = weekdaysMinRegex;
3542
3543 // Hours
3544 prototype__proto.isPM = localeIsPM;
3545 prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
3546 prototype__proto.meridiem = localeMeridiem;
3547
3548 function lists__get (format, index, field, setter) {
3549 var locale = locale_locales__getLocale();
3550 var utc = create_utc__createUTC().set(setter, index);
3551 return locale[field](utc, format);
3552 }
3553
3554 function listMonthsImpl (format, index, field) {
3555 if (typeof format === 'number') {
3556 index = format;
3557 format = undefined;
3558 }
3559
3560 format = format || '';
3561
3562 if (index != null) {
3563 return lists__get(format, index, field, 'month');
3564 }
3565
3566 var i;
3567 var out = [];
3568 for (i = 0; i < 12; i++) {
3569 out[i] = lists__get(format, i, field, 'month');
3570 }
3571 return out;
3572 }
3573
3574 // ()
3575 // (5)
3576 // (fmt, 5)
3577 // (fmt)
3578 // (true)
3579 // (true, 5)
3580 // (true, fmt, 5)
3581 // (true, fmt)
3582 function listWeekdaysImpl (localeSorted, format, index, field) {
3583 if (typeof localeSorted === 'boolean') {
3584 if (typeof format === 'number') {
3585 index = format;
3586 format = undefined;
3587 }
3588
3589 format = format || '';
3590 } else {
3591 format = localeSorted;
3592 index = format;
3593 localeSorted = false;
3594
3595 if (typeof format === 'number') {
3596 index = format;
3597 format = undefined;
3598 }
3599
3600 format = format || '';
3601 }
3602
3603 var locale = locale_locales__getLocale(),
3604 shift = localeSorted ? locale._week.dow : 0;
3605
3606 if (index != null) {
3607 return lists__get(format, (index + shift) % 7, field, 'day');
3608 }
3609
3610 var i;
3611 var out = [];
3612 for (i = 0; i < 7; i++) {
3613 out[i] = lists__get(format, (i + shift) % 7, field, 'day');
3614 }
3615 return out;
3616 }
3617
3618 function lists__listMonths (format, index) {
3619 return listMonthsImpl(format, index, 'months');
3620 }
3621
3622 function lists__listMonthsShort (format, index) {
3623 return listMonthsImpl(format, index, 'monthsShort');
3624 }
3625
3626 function lists__listWeekdays (localeSorted, format, index) {
3627 return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
3628 }
3629
3630 function lists__listWeekdaysShort (localeSorted, format, index) {
3631 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
3632 }
3633
3634 function lists__listWeekdaysMin (localeSorted, format, index) {
3635 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
3636 }
3637
3638 locale_locales__getSetGlobalLocale('en', {
3639 ordinalParse: /\d{1,2}(th|st|nd|rd)/,
3640 ordinal : function (number) {
3641 var b = number % 10,
3642 output = (toInt(number % 100 / 10) === 1) ? 'th' :
3643 (b === 1) ? 'st' :
3644 (b === 2) ? 'nd' :
3645 (b === 3) ? 'rd' : 'th';
3646 return number + output;
3647 }
3648 });
3649
3650 // Side effect imports
3651 utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
3652 utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
3653
3654 var mathAbs = Math.abs;
3655
3656 function duration_abs__abs () {
3657 var data = this._data;
3658
3659 this._milliseconds = mathAbs(this._milliseconds);
3660 this._days = mathAbs(this._days);
3661 this._months = mathAbs(this._months);
3662
3663 data.milliseconds = mathAbs(data.milliseconds);
3664 data.seconds = mathAbs(data.seconds);
3665 data.minutes = mathAbs(data.minutes);
3666 data.hours = mathAbs(data.hours);
3667 data.months = mathAbs(data.months);
3668 data.years = mathAbs(data.years);
3669
3670 return this;
3671 }
3672
3673 function duration_add_subtract__addSubtract (duration, input, value, direction) {
3674 var other = create__createDuration(input, value);
3675
3676 duration._milliseconds += direction * other._milliseconds;
3677 duration._days += direction * other._days;
3678 duration._months += direction * other._months;
3679
3680 return duration._bubble();
3681 }
3682
3683 // supports only 2.0-style add(1, 's') or add(duration)
3684 function duration_add_subtract__add (input, value) {
3685 return duration_add_subtract__addSubtract(this, input, value, 1);
3686 }
3687
3688 // supports only 2.0-style subtract(1, 's') or subtract(duration)
3689 function duration_add_subtract__subtract (input, value) {
3690 return duration_add_subtract__addSubtract(this, input, value, -1);
3691 }
3692
3693 function absCeil (number) {
3694 if (number < 0) {
3695 return Math.floor(number);
3696 } else {
3697 return Math.ceil(number);
3698 }
3699 }
3700
3701 function bubble () {
3702 var milliseconds = this._milliseconds;
3703 var days = this._days;
3704 var months = this._months;
3705 var data = this._data;
3706 var seconds, minutes, hours, years, monthsFromDays;
3707
3708 // if we have a mix of positive and negative values, bubble down first
3709 // check: https://github.com/moment/moment/issues/2166
3710 if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
3711 (milliseconds <= 0 && days <= 0 && months <= 0))) {
3712 milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
3713 days = 0;
3714 months = 0;
3715 }
3716
3717 // The following code bubbles up values, see the tests for
3718 // examples of what that means.
3719 data.milliseconds = milliseconds % 1000;
3720
3721 seconds = absFloor(milliseconds / 1000);
3722 data.seconds = seconds % 60;
3723
3724 minutes = absFloor(seconds / 60);
3725 data.minutes = minutes % 60;
3726
3727 hours = absFloor(minutes / 60);
3728 data.hours = hours % 24;
3729
3730 days += absFloor(hours / 24);
3731
3732 // convert days to months
3733 monthsFromDays = absFloor(daysToMonths(days));
3734 months += monthsFromDays;
3735 days -= absCeil(monthsToDays(monthsFromDays));
3736
3737 // 12 months -> 1 year
3738 years = absFloor(months / 12);
3739 months %= 12;
3740
3741 data.days = days;
3742 data.months = months;
3743 data.years = years;
3744
3745 return this;
3746 }
3747
3748 function daysToMonths (days) {
3749 // 400 years have 146097 days (taking into account leap year rules)
3750 // 400 years have 12 months === 4800
3751 return days * 4800 / 146097;
3752 }
3753
3754 function monthsToDays (months) {
3755 // the reverse of daysToMonths
3756 return months * 146097 / 4800;
3757 }
3758
3759 function as (units) {
3760 var days;
3761 var months;
3762 var milliseconds = this._milliseconds;
3763
3764 units = normalizeUnits(units);
3765
3766 if (units === 'month' || units === 'year') {
3767 days = this._days + milliseconds / 864e5;
3768 months = this._months + daysToMonths(days);
3769 return units === 'month' ? months : months / 12;
3770 } else {
3771 // handle milliseconds separately because of floating point math errors (issue #1867)
3772 days = this._days + Math.round(monthsToDays(this._months));
3773 switch (units) {
3774 case 'week' : return days / 7 + milliseconds / 6048e5;
3775 case 'day' : return days + milliseconds / 864e5;
3776 case 'hour' : return days * 24 + milliseconds / 36e5;
3777 case 'minute' : return days * 1440 + milliseconds / 6e4;
3778 case 'second' : return days * 86400 + milliseconds / 1000;
3779 // Math.floor prevents floating point math errors here
3780 case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
3781 default: throw new Error('Unknown unit ' + units);
3782 }
3783 }
3784 }
3785
3786 // TODO: Use this.as('ms')?
3787 function duration_as__valueOf () {
3788 return (
3789 this._milliseconds +
3790 this._days * 864e5 +
3791 (this._months % 12) * 2592e6 +
3792 toInt(this._months / 12) * 31536e6
3793 );
3794 }
3795
3796 function makeAs (alias) {
3797 return function () {
3798 return this.as(alias);
3799 };
3800 }
3801
3802 var asMilliseconds = makeAs('ms');
3803 var asSeconds = makeAs('s');
3804 var asMinutes = makeAs('m');
3805 var asHours = makeAs('h');
3806 var asDays = makeAs('d');
3807 var asWeeks = makeAs('w');
3808 var asMonths = makeAs('M');
3809 var asYears = makeAs('y');
3810
3811 function duration_get__get (units) {
3812 units = normalizeUnits(units);
3813 return this[units + 's']();
3814 }
3815
3816 function makeGetter(name) {
3817 return function () {
3818 return this._data[name];
3819 };
3820 }
3821
3822 var milliseconds = makeGetter('milliseconds');
3823 var seconds = makeGetter('seconds');
3824 var minutes = makeGetter('minutes');
3825 var hours = makeGetter('hours');
3826 var days = makeGetter('days');
3827 var months = makeGetter('months');
3828 var years = makeGetter('years');
3829
3830 function weeks () {
3831 return absFloor(this.days() / 7);
3832 }
3833
3834 var round = Math.round;
3835 var thresholds = {
3836 s: 45, // seconds to minute
3837 m: 45, // minutes to hour
3838 h: 22, // hours to day
3839 d: 26, // days to month
3840 M: 11 // months to year
3841 };
3842
3843 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
3844 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
3845 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
3846 }
3847
3848 function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
3849 var duration = create__createDuration(posNegDuration).abs();
3850 var seconds = round(duration.as('s'));
3851 var minutes = round(duration.as('m'));
3852 var hours = round(duration.as('h'));
3853 var days = round(duration.as('d'));
3854 var months = round(duration.as('M'));
3855 var years = round(duration.as('y'));
3856
3857 var a = seconds < thresholds.s && ['s', seconds] ||
3858 minutes <= 1 && ['m'] ||
3859 minutes < thresholds.m && ['mm', minutes] ||
3860 hours <= 1 && ['h'] ||
3861 hours < thresholds.h && ['hh', hours] ||
3862 days <= 1 && ['d'] ||
3863 days < thresholds.d && ['dd', days] ||
3864 months <= 1 && ['M'] ||
3865 months < thresholds.M && ['MM', months] ||
3866 years <= 1 && ['y'] || ['yy', years];
3867
3868 a[2] = withoutSuffix;
3869 a[3] = +posNegDuration > 0;
3870 a[4] = locale;
3871 return substituteTimeAgo.apply(null, a);
3872 }
3873
3874 // This function allows you to set a threshold for relative time strings
3875 function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
3876 if (thresholds[threshold] === undefined) {
3877 return false;
3878 }
3879 if (limit === undefined) {
3880 return thresholds[threshold];
3881 }
3882 thresholds[threshold] = limit;
3883 return true;
3884 }
3885
3886 function humanize (withSuffix) {
3887 var locale = this.localeData();
3888 var output = duration_humanize__relativeTime(this, !withSuffix, locale);
3889
3890 if (withSuffix) {
3891 output = locale.pastFuture(+this, output);
3892 }
3893
3894 return locale.postformat(output);
3895 }
3896
3897 var iso_string__abs = Math.abs;
3898
3899 function iso_string__toISOString() {
3900 // for ISO strings we do not use the normal bubbling rules:
3901 // * milliseconds bubble up until they become hours
3902 // * days do not bubble at all
3903 // * months bubble up until they become years
3904 // This is because there is no context-free conversion between hours and days
3905 // (think of clock changes)
3906 // and also not between days and months (28-31 days per month)
3907 var seconds = iso_string__abs(this._milliseconds) / 1000;
3908 var days = iso_string__abs(this._days);
3909 var months = iso_string__abs(this._months);
3910 var minutes, hours, years;
3911
3912 // 3600 seconds -> 60 minutes -> 1 hour
3913 minutes = absFloor(seconds / 60);
3914 hours = absFloor(minutes / 60);
3915 seconds %= 60;
3916 minutes %= 60;
3917
3918 // 12 months -> 1 year
3919 years = absFloor(months / 12);
3920 months %= 12;
3921
3922
3923 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
3924 var Y = years;
3925 var M = months;
3926 var D = days;
3927 var h = hours;
3928 var m = minutes;
3929 var s = seconds;
3930 var total = this.asSeconds();
3931
3932 if (!total) {
3933 // this is the same as C#'s (Noda) and python (isodate)...
3934 // but not other JS (goog.date)
3935 return 'P0D';
3936 }
3937
3938 return (total < 0 ? '-' : '') +
3939 'P' +
3940 (Y ? Y + 'Y' : '') +
3941 (M ? M + 'M' : '') +
3942 (D ? D + 'D' : '') +
3943 ((h || m || s) ? 'T' : '') +
3944 (h ? h + 'H' : '') +
3945 (m ? m + 'M' : '') +
3946 (s ? s + 'S' : '');
3947 }
3948
3949 var duration_prototype__proto = Duration.prototype;
3950
3951 duration_prototype__proto.abs = duration_abs__abs;
3952 duration_prototype__proto.add = duration_add_subtract__add;
3953 duration_prototype__proto.subtract = duration_add_subtract__subtract;
3954 duration_prototype__proto.as = as;
3955 duration_prototype__proto.asMilliseconds = asMilliseconds;
3956 duration_prototype__proto.asSeconds = asSeconds;
3957 duration_prototype__proto.asMinutes = asMinutes;
3958 duration_prototype__proto.asHours = asHours;
3959 duration_prototype__proto.asDays = asDays;
3960 duration_prototype__proto.asWeeks = asWeeks;
3961 duration_prototype__proto.asMonths = asMonths;
3962 duration_prototype__proto.asYears = asYears;
3963 duration_prototype__proto.valueOf = duration_as__valueOf;
3964 duration_prototype__proto._bubble = bubble;
3965 duration_prototype__proto.get = duration_get__get;
3966 duration_prototype__proto.milliseconds = milliseconds;
3967 duration_prototype__proto.seconds = seconds;
3968 duration_prototype__proto.minutes = minutes;
3969 duration_prototype__proto.hours = hours;
3970 duration_prototype__proto.days = days;
3971 duration_prototype__proto.weeks = weeks;
3972 duration_prototype__proto.months = months;
3973 duration_prototype__proto.years = years;
3974 duration_prototype__proto.humanize = humanize;
3975 duration_prototype__proto.toISOString = iso_string__toISOString;
3976 duration_prototype__proto.toString = iso_string__toISOString;
3977 duration_prototype__proto.toJSON = iso_string__toISOString;
3978 duration_prototype__proto.locale = locale;
3979 duration_prototype__proto.localeData = localeData;
3980
3981 // Deprecations
3982 duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
3983 duration_prototype__proto.lang = lang;
3984
3985 // Side effect imports
3986
3987 // FORMATTING
3988
3989 addFormatToken('X', 0, 0, 'unix');
3990 addFormatToken('x', 0, 0, 'valueOf');
3991
3992 // PARSING
3993
3994 addRegexToken('x', matchSigned);
3995 addRegexToken('X', matchTimestamp);
3996 addParseToken('X', function (input, array, config) {
3997 config._d = new Date(parseFloat(input, 10) * 1000);
3998 });
3999 addParseToken('x', function (input, array, config) {
4000 config._d = new Date(toInt(input));
4001 });
4002
4003 // Side effect imports
4004
4005
4006 utils_hooks__hooks.version = '2.13.0';
4007
4008 setHookCallback(local__createLocal);
4009
4010 utils_hooks__hooks.fn = momentPrototype;
4011 utils_hooks__hooks.min = min;
4012 utils_hooks__hooks.max = max;
4013 utils_hooks__hooks.now = now;
4014 utils_hooks__hooks.utc = create_utc__createUTC;
4015 utils_hooks__hooks.unix = moment__createUnix;
4016 utils_hooks__hooks.months = lists__listMonths;
4017 utils_hooks__hooks.isDate = isDate;
4018 utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
4019 utils_hooks__hooks.invalid = valid__createInvalid;
4020 utils_hooks__hooks.duration = create__createDuration;
4021 utils_hooks__hooks.isMoment = isMoment;
4022 utils_hooks__hooks.weekdays = lists__listWeekdays;
4023 utils_hooks__hooks.parseZone = moment__createInZone;
4024 utils_hooks__hooks.localeData = locale_locales__getLocale;
4025 utils_hooks__hooks.isDuration = isDuration;
4026 utils_hooks__hooks.monthsShort = lists__listMonthsShort;
4027 utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
4028 utils_hooks__hooks.defineLocale = defineLocale;
4029 utils_hooks__hooks.updateLocale = updateLocale;
4030 utils_hooks__hooks.locales = locale_locales__listLocales;
4031 utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
4032 utils_hooks__hooks.normalizeUnits = normalizeUnits;
4033 utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
4034 utils_hooks__hooks.prototype = momentPrototype;
4035
4036 var _moment = utils_hooks__hooks;
4037
4038 return _moment;
4039
4040}));