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.

4506 lines
143 KiB

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