You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4039 lines
132 KiB

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