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.

3110 lines
100 KiB

  1. //! moment.js
  2. //! version : 2.10.3
  3. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  4. //! license : MIT
  5. //! momentjs.com
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. global.moment = factory()
  10. }(this, function () { 'use strict';
  11. var hookCallback;
  12. function utils_hooks__hooks () {
  13. return hookCallback.apply(null, arguments);
  14. }
  15. // This is done to register the method called with moment()
  16. // without creating circular dependencies.
  17. function setHookCallback (callback) {
  18. hookCallback = callback;
  19. }
  20. function isArray(input) {
  21. return Object.prototype.toString.call(input) === '[object Array]';
  22. }
  23. function isDate(input) {
  24. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  25. }
  26. function map(arr, fn) {
  27. var res = [], i;
  28. for (i = 0; i < arr.length; ++i) {
  29. res.push(fn(arr[i], i));
  30. }
  31. return res;
  32. }
  33. function hasOwnProp(a, b) {
  34. return Object.prototype.hasOwnProperty.call(a, b);
  35. }
  36. function extend(a, b) {
  37. for (var i in b) {
  38. if (hasOwnProp(b, i)) {
  39. a[i] = b[i];
  40. }
  41. }
  42. if (hasOwnProp(b, 'toString')) {
  43. a.toString = b.toString;
  44. }
  45. if (hasOwnProp(b, 'valueOf')) {
  46. a.valueOf = b.valueOf;
  47. }
  48. return a;
  49. }
  50. function create_utc__createUTC (input, format, locale, strict) {
  51. return createLocalOrUTC(input, format, locale, strict, true).utc();
  52. }
  53. function defaultParsingFlags() {
  54. // We need to deep clone this object.
  55. return {
  56. empty : false,
  57. unusedTokens : [],
  58. unusedInput : [],
  59. overflow : -2,
  60. charsLeftOver : 0,
  61. nullInput : false,
  62. invalidMonth : null,
  63. invalidFormat : false,
  64. userInvalidated : false,
  65. iso : false
  66. };
  67. }
  68. function getParsingFlags(m) {
  69. if (m._pf == null) {
  70. m._pf = defaultParsingFlags();
  71. }
  72. return m._pf;
  73. }
  74. function valid__isValid(m) {
  75. if (m._isValid == null) {
  76. var flags = getParsingFlags(m);
  77. m._isValid = !isNaN(m._d.getTime()) &&
  78. flags.overflow < 0 &&
  79. !flags.empty &&
  80. !flags.invalidMonth &&
  81. !flags.nullInput &&
  82. !flags.invalidFormat &&
  83. !flags.userInvalidated;
  84. if (m._strict) {
  85. m._isValid = m._isValid &&
  86. flags.charsLeftOver === 0 &&
  87. flags.unusedTokens.length === 0 &&
  88. flags.bigHour === undefined;
  89. }
  90. }
  91. return m._isValid;
  92. }
  93. function valid__createInvalid (flags) {
  94. var m = create_utc__createUTC(NaN);
  95. if (flags != null) {
  96. extend(getParsingFlags(m), flags);
  97. }
  98. else {
  99. getParsingFlags(m).userInvalidated = true;
  100. }
  101. return m;
  102. }
  103. var momentProperties = utils_hooks__hooks.momentProperties = [];
  104. function copyConfig(to, from) {
  105. var i, prop, val;
  106. if (typeof from._isAMomentObject !== 'undefined') {
  107. to._isAMomentObject = from._isAMomentObject;
  108. }
  109. if (typeof from._i !== 'undefined') {
  110. to._i = from._i;
  111. }
  112. if (typeof from._f !== 'undefined') {
  113. to._f = from._f;
  114. }
  115. if (typeof from._l !== 'undefined') {
  116. to._l = from._l;
  117. }
  118. if (typeof from._strict !== 'undefined') {
  119. to._strict = from._strict;
  120. }
  121. if (typeof from._tzm !== 'undefined') {
  122. to._tzm = from._tzm;
  123. }
  124. if (typeof from._isUTC !== 'undefined') {
  125. to._isUTC = from._isUTC;
  126. }
  127. if (typeof from._offset !== 'undefined') {
  128. to._offset = from._offset;
  129. }
  130. if (typeof from._pf !== 'undefined') {
  131. to._pf = getParsingFlags(from);
  132. }
  133. if (typeof from._locale !== 'undefined') {
  134. to._locale = from._locale;
  135. }
  136. if (momentProperties.length > 0) {
  137. for (i in momentProperties) {
  138. prop = momentProperties[i];
  139. val = from[prop];
  140. if (typeof val !== 'undefined') {
  141. to[prop] = val;
  142. }
  143. }
  144. }
  145. return to;
  146. }
  147. var updateInProgress = false;
  148. // Moment prototype object
  149. function Moment(config) {
  150. copyConfig(this, config);
  151. this._d = new Date(+config._d);
  152. // Prevent infinite loop in case updateOffset creates new moment
  153. // objects.
  154. if (updateInProgress === false) {
  155. updateInProgress = true;
  156. utils_hooks__hooks.updateOffset(this);
  157. updateInProgress = false;
  158. }
  159. }
  160. function isMoment (obj) {
  161. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  162. }
  163. function toInt(argumentForCoercion) {
  164. var coercedNumber = +argumentForCoercion,
  165. value = 0;
  166. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  167. if (coercedNumber >= 0) {
  168. value = Math.floor(coercedNumber);
  169. } else {
  170. value = Math.ceil(coercedNumber);
  171. }
  172. }
  173. return value;
  174. }
  175. function compareArrays(array1, array2, dontConvert) {
  176. var len = Math.min(array1.length, array2.length),
  177. lengthDiff = Math.abs(array1.length - array2.length),
  178. diffs = 0,
  179. i;
  180. for (i = 0; i < len; i++) {
  181. if ((dontConvert && array1[i] !== array2[i]) ||
  182. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  183. diffs++;
  184. }
  185. }
  186. return diffs + lengthDiff;
  187. }
  188. function Locale() {
  189. }
  190. var locales = {};
  191. var globalLocale;
  192. function normalizeLocale(key) {
  193. return key ? key.toLowerCase().replace('_', '-') : key;
  194. }
  195. // pick the locale from the array
  196. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  197. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  198. function chooseLocale(names) {
  199. var i = 0, j, next, locale, split;
  200. while (i < names.length) {
  201. split = normalizeLocale(names[i]).split('-');
  202. j = split.length;
  203. next = normalizeLocale(names[i + 1]);
  204. next = next ? next.split('-') : null;
  205. while (j > 0) {
  206. locale = loadLocale(split.slice(0, j).join('-'));
  207. if (locale) {
  208. return locale;
  209. }
  210. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  211. //the next array item is better than a shallower substring of this one
  212. break;
  213. }
  214. j--;
  215. }
  216. i++;
  217. }
  218. return null;
  219. }
  220. function loadLocale(name) {
  221. var oldLocale = null;
  222. // TODO: Find a better way to register and load all the locales in Node
  223. if (!locales[name] && typeof module !== 'undefined' &&
  224. module && module.exports) {
  225. try {
  226. oldLocale = globalLocale._abbr;
  227. require('./locale/' + name);
  228. // because defineLocale currently also sets the global locale, we
  229. // want to undo that for lazy loaded locales
  230. locale_locales__getSetGlobalLocale(oldLocale);
  231. } catch (e) { }
  232. }
  233. return locales[name];
  234. }
  235. // This function will load locale and then set the global locale. If
  236. // no arguments are passed in, it will simply return the current global
  237. // locale key.
  238. function locale_locales__getSetGlobalLocale (key, values) {
  239. var data;
  240. if (key) {
  241. if (typeof values === 'undefined') {
  242. data = locale_locales__getLocale(key);
  243. }
  244. else {
  245. data = defineLocale(key, values);
  246. }
  247. if (data) {
  248. // moment.duration._locale = moment._locale = data;
  249. globalLocale = data;
  250. }
  251. }
  252. return globalLocale._abbr;
  253. }
  254. function defineLocale (name, values) {
  255. if (values !== null) {
  256. values.abbr = name;
  257. if (!locales[name]) {
  258. locales[name] = new Locale();
  259. }
  260. locales[name].set(values);
  261. // backwards compat for now: also set the locale
  262. locale_locales__getSetGlobalLocale(name);
  263. return locales[name];
  264. } else {
  265. // useful for testing
  266. delete locales[name];
  267. return null;
  268. }
  269. }
  270. // returns locale data
  271. function locale_locales__getLocale (key) {
  272. var locale;
  273. if (key && key._locale && key._locale._abbr) {
  274. key = key._locale._abbr;
  275. }
  276. if (!key) {
  277. return globalLocale;
  278. }
  279. if (!isArray(key)) {
  280. //short-circuit everything else
  281. locale = loadLocale(key);
  282. if (locale) {
  283. return locale;
  284. }
  285. key = [key];
  286. }
  287. return chooseLocale(key);
  288. }
  289. var aliases = {};
  290. function addUnitAlias (unit, shorthand) {
  291. var lowerCase = unit.toLowerCase();
  292. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  293. }
  294. function normalizeUnits(units) {
  295. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  296. }
  297. function normalizeObjectUnits(inputObject) {
  298. var normalizedInput = {},
  299. normalizedProp,
  300. prop;
  301. for (prop in inputObject) {
  302. if (hasOwnProp(inputObject, prop)) {
  303. normalizedProp = normalizeUnits(prop);
  304. if (normalizedProp) {
  305. normalizedInput[normalizedProp] = inputObject[prop];
  306. }
  307. }
  308. }
  309. return normalizedInput;
  310. }
  311. function makeGetSet (unit, keepTime) {
  312. return function (value) {
  313. if (value != null) {
  314. get_set__set(this, unit, value);
  315. utils_hooks__hooks.updateOffset(this, keepTime);
  316. return this;
  317. } else {
  318. return get_set__get(this, unit);
  319. }
  320. };
  321. }
  322. function get_set__get (mom, unit) {
  323. return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
  324. }
  325. function get_set__set (mom, unit, value) {
  326. return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  327. }
  328. // MOMENTS
  329. function getSet (units, value) {
  330. var unit;
  331. if (typeof units === 'object') {
  332. for (unit in units) {
  333. this.set(unit, units[unit]);
  334. }
  335. } else {
  336. units = normalizeUnits(units);
  337. if (typeof this[units] === 'function') {
  338. return this[units](value);
  339. }
  340. }
  341. return this;
  342. }
  343. function zeroFill(number, targetLength, forceSign) {
  344. var output = '' + Math.abs(number),
  345. sign = number >= 0;
  346. while (output.length < targetLength) {
  347. output = '0' + output;
  348. }
  349. return (sign ? (forceSign ? '+' : '') : '-') + output;
  350. }
  351. var formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|x|X|zz?|ZZ?|.)/g;
  352. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  353. var formatFunctions = {};
  354. var formatTokenFunctions = {};
  355. // token: 'M'
  356. // padded: ['MM', 2]
  357. // ordinal: 'Mo'
  358. // callback: function () { this.month() + 1 }
  359. function addFormatToken (token, padded, ordinal, callback) {
  360. var func = callback;
  361. if (typeof callback === 'string') {
  362. func = function () {
  363. return this[callback]();
  364. };
  365. }
  366. if (token) {
  367. formatTokenFunctions[token] = func;
  368. }
  369. if (padded) {
  370. formatTokenFunctions[padded[0]] = function () {
  371. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  372. };
  373. }
  374. if (ordinal) {
  375. formatTokenFunctions[ordinal] = function () {
  376. return this.localeData().ordinal(func.apply(this, arguments), token);
  377. };
  378. }
  379. }
  380. function removeFormattingTokens(input) {
  381. if (input.match(/\[[\s\S]/)) {
  382. return input.replace(/^\[|\]$/g, '');
  383. }
  384. return input.replace(/\\/g, '');
  385. }
  386. function makeFormatFunction(format) {
  387. var array = format.match(formattingTokens), i, length;
  388. for (i = 0, length = array.length; i < length; i++) {
  389. if (formatTokenFunctions[array[i]]) {
  390. array[i] = formatTokenFunctions[array[i]];
  391. } else {
  392. array[i] = removeFormattingTokens(array[i]);
  393. }
  394. }
  395. return function (mom) {
  396. var output = '';
  397. for (i = 0; i < length; i++) {
  398. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  399. }
  400. return output;
  401. };
  402. }
  403. // format date using native date object
  404. function formatMoment(m, format) {
  405. if (!m.isValid()) {
  406. return m.localeData().invalidDate();
  407. }
  408. format = expandFormat(format, m.localeData());
  409. if (!formatFunctions[format]) {
  410. formatFunctions[format] = makeFormatFunction(format);
  411. }
  412. return formatFunctions[format](m);
  413. }
  414. function expandFormat(format, locale) {
  415. var i = 5;
  416. function replaceLongDateFormatTokens(input) {
  417. return locale.longDateFormat(input) || input;
  418. }
  419. localFormattingTokens.lastIndex = 0;
  420. while (i >= 0 && localFormattingTokens.test(format)) {
  421. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  422. localFormattingTokens.lastIndex = 0;
  423. i -= 1;
  424. }
  425. return format;
  426. }
  427. var match1 = /\d/; // 0 - 9
  428. var match2 = /\d\d/; // 00 - 99
  429. var match3 = /\d{3}/; // 000 - 999
  430. var match4 = /\d{4}/; // 0000 - 9999
  431. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  432. var match1to2 = /\d\d?/; // 0 - 99
  433. var match1to3 = /\d{1,3}/; // 0 - 999
  434. var match1to4 = /\d{1,4}/; // 0 - 9999
  435. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  436. var matchUnsigned = /\d+/; // 0 - inf
  437. var matchSigned = /[+-]?\d+/; // -inf - inf
  438. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  439. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  440. // any word (or two) characters or numbers including two/three word month in arabic.
  441. var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  442. var regexes = {};
  443. function addRegexToken (token, regex, strictRegex) {
  444. regexes[token] = typeof regex === 'function' ? regex : function (isStrict) {
  445. return (isStrict && strictRegex) ? strictRegex : regex;
  446. };
  447. }
  448. function getParseRegexForToken (token, config) {
  449. if (!hasOwnProp(regexes, token)) {
  450. return new RegExp(unescapeFormat(token));
  451. }
  452. return regexes[token](config._strict, config._locale);
  453. }
  454. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  455. function unescapeFormat(s) {
  456. return s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  457. return p1 || p2 || p3 || p4;
  458. }).replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  459. }
  460. var tokens = {};
  461. function addParseToken (token, callback) {
  462. var i, func = callback;
  463. if (typeof token === 'string') {
  464. token = [token];
  465. }
  466. if (typeof callback === 'number') {
  467. func = function (input, array) {
  468. array[callback] = toInt(input);
  469. };
  470. }
  471. for (i = 0; i < token.length; i++) {
  472. tokens[token[i]] = func;
  473. }
  474. }
  475. function addWeekParseToken (token, callback) {
  476. addParseToken(token, function (input, array, config, token) {
  477. config._w = config._w || {};
  478. callback(input, config._w, config, token);
  479. });
  480. }
  481. function addTimeToArrayFromToken(token, input, config) {
  482. if (input != null && hasOwnProp(tokens, token)) {
  483. tokens[token](input, config._a, config, token);
  484. }
  485. }
  486. var YEAR = 0;
  487. var MONTH = 1;
  488. var DATE = 2;
  489. var HOUR = 3;
  490. var MINUTE = 4;
  491. var SECOND = 5;
  492. var MILLISECOND = 6;
  493. function daysInMonth(year, month) {
  494. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  495. }
  496. // FORMATTING
  497. addFormatToken('M', ['MM', 2], 'Mo', function () {
  498. return this.month() + 1;
  499. });
  500. addFormatToken('MMM', 0, 0, function (format) {
  501. return this.localeData().monthsShort(this, format);
  502. });
  503. addFormatToken('MMMM', 0, 0, function (format) {
  504. return this.localeData().months(this, format);
  505. });
  506. // ALIASES
  507. addUnitAlias('month', 'M');
  508. // PARSING
  509. addRegexToken('M', match1to2);
  510. addRegexToken('MM', match1to2, match2);
  511. addRegexToken('MMM', matchWord);
  512. addRegexToken('MMMM', matchWord);
  513. addParseToken(['M', 'MM'], function (input, array) {
  514. array[MONTH] = toInt(input) - 1;
  515. });
  516. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  517. var month = config._locale.monthsParse(input, token, config._strict);
  518. // if we didn't find a month name, mark the date as invalid.
  519. if (month != null) {
  520. array[MONTH] = month;
  521. } else {
  522. getParsingFlags(config).invalidMonth = input;
  523. }
  524. });
  525. // LOCALES
  526. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  527. function localeMonths (m) {
  528. return this._months[m.month()];
  529. }
  530. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  531. function localeMonthsShort (m) {
  532. return this._monthsShort[m.month()];
  533. }
  534. function localeMonthsParse (monthName, format, strict) {
  535. var i, mom, regex;
  536. if (!this._monthsParse) {
  537. this._monthsParse = [];
  538. this._longMonthsParse = [];
  539. this._shortMonthsParse = [];
  540. }
  541. for (i = 0; i < 12; i++) {
  542. // make the regex if we don't have it already
  543. mom = create_utc__createUTC([2000, i]);
  544. if (strict && !this._longMonthsParse[i]) {
  545. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  546. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  547. }
  548. if (!strict && !this._monthsParse[i]) {
  549. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  550. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  551. }
  552. // test the regex
  553. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  554. return i;
  555. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  556. return i;
  557. } else if (!strict && this._monthsParse[i].test(monthName)) {
  558. return i;
  559. }
  560. }
  561. }
  562. // MOMENTS
  563. function setMonth (mom, value) {
  564. var dayOfMonth;
  565. // TODO: Move this out of here!
  566. if (typeof value === 'string') {
  567. value = mom.localeData().monthsParse(value);
  568. // TODO: Another silent failure?
  569. if (typeof value !== 'number') {
  570. return mom;
  571. }
  572. }
  573. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  574. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  575. return mom;
  576. }
  577. function getSetMonth (value) {
  578. if (value != null) {
  579. setMonth(this, value);
  580. utils_hooks__hooks.updateOffset(this, true);
  581. return this;
  582. } else {
  583. return get_set__get(this, 'Month');
  584. }
  585. }
  586. function getDaysInMonth () {
  587. return daysInMonth(this.year(), this.month());
  588. }
  589. function checkOverflow (m) {
  590. var overflow;
  591. var a = m._a;
  592. if (a && getParsingFlags(m).overflow === -2) {
  593. overflow =
  594. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  595. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  596. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  597. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  598. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  599. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  600. -1;
  601. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  602. overflow = DATE;
  603. }
  604. getParsingFlags(m).overflow = overflow;
  605. }
  606. return m;
  607. }
  608. function warn(msg) {
  609. if (utils_hooks__hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) {
  610. console.warn('Deprecation warning: ' + msg);
  611. }
  612. }
  613. function deprecate(msg, fn) {
  614. var firstTime = true,
  615. msgWithStack = msg + '\n' + (new Error()).stack;
  616. return extend(function () {
  617. if (firstTime) {
  618. warn(msgWithStack);
  619. firstTime = false;
  620. }
  621. return fn.apply(this, arguments);
  622. }, fn);
  623. }
  624. var deprecations = {};
  625. function deprecateSimple(name, msg) {
  626. if (!deprecations[name]) {
  627. warn(msg);
  628. deprecations[name] = true;
  629. }
  630. }
  631. utils_hooks__hooks.suppressDeprecationWarnings = false;
  632. var from_string__isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
  633. var isoDates = [
  634. ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
  635. ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
  636. ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
  637. ['GGGG-[W]WW', /\d{4}-W\d{2}/],
  638. ['YYYY-DDD', /\d{4}-\d{3}/]
  639. ];
  640. // iso time formats and regexes
  641. var isoTimes = [
  642. ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
  643. ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
  644. ['HH:mm', /(T| )\d\d:\d\d/],
  645. ['HH', /(T| )\d\d/]
  646. ];
  647. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  648. // date from iso format
  649. function configFromISO(config) {
  650. var i, l,
  651. string = config._i,
  652. match = from_string__isoRegex.exec(string);
  653. if (match) {
  654. getParsingFlags(config).iso = true;
  655. for (i = 0, l = isoDates.length; i < l; i++) {
  656. if (isoDates[i][1].exec(string)) {
  657. // match[5] should be 'T' or undefined
  658. config._f = isoDates[i][0] + (match[6] || ' ');
  659. break;
  660. }
  661. }
  662. for (i = 0, l = isoTimes.length; i < l; i++) {
  663. if (isoTimes[i][1].exec(string)) {
  664. config._f += isoTimes[i][0];
  665. break;
  666. }
  667. }
  668. if (string.match(matchOffset)) {
  669. config._f += 'Z';
  670. }
  671. configFromStringAndFormat(config);
  672. } else {
  673. config._isValid = false;
  674. }
  675. }
  676. // date from iso format or fallback
  677. function configFromString(config) {
  678. var matched = aspNetJsonRegex.exec(config._i);
  679. if (matched !== null) {
  680. config._d = new Date(+matched[1]);
  681. return;
  682. }
  683. configFromISO(config);
  684. if (config._isValid === false) {
  685. delete config._isValid;
  686. utils_hooks__hooks.createFromInputFallback(config);
  687. }
  688. }
  689. utils_hooks__hooks.createFromInputFallback = deprecate(
  690. 'moment construction falls back to js Date. This is ' +
  691. 'discouraged and will be removed in upcoming major ' +
  692. 'release. Please refer to ' +
  693. 'https://github.com/moment/moment/issues/1407 for more info.',
  694. function (config) {
  695. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  696. }
  697. );
  698. function createDate (y, m, d, h, M, s, ms) {
  699. //can't just apply() to create a date:
  700. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  701. var date = new Date(y, m, d, h, M, s, ms);
  702. //the date constructor doesn't accept years < 1970
  703. if (y < 1970) {
  704. date.setFullYear(y);
  705. }
  706. return date;
  707. }
  708. function createUTCDate (y) {
  709. var date = new Date(Date.UTC.apply(null, arguments));
  710. if (y < 1970) {
  711. date.setUTCFullYear(y);
  712. }
  713. return date;
  714. }
  715. addFormatToken(0, ['YY', 2], 0, function () {
  716. return this.year() % 100;
  717. });
  718. addFormatToken(0, ['YYYY', 4], 0, 'year');
  719. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  720. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  721. // ALIASES
  722. addUnitAlias('year', 'y');
  723. // PARSING
  724. addRegexToken('Y', matchSigned);
  725. addRegexToken('YY', match1to2, match2);
  726. addRegexToken('YYYY', match1to4, match4);
  727. addRegexToken('YYYYY', match1to6, match6);
  728. addRegexToken('YYYYYY', match1to6, match6);
  729. addParseToken(['YYYY', 'YYYYY', 'YYYYYY'], YEAR);
  730. addParseToken('YY', function (input, array) {
  731. array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
  732. });
  733. // HELPERS
  734. function daysInYear(year) {
  735. return isLeapYear(year) ? 366 : 365;
  736. }
  737. function isLeapYear(year) {
  738. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  739. }
  740. // HOOKS
  741. utils_hooks__hooks.parseTwoDigitYear = function (input) {
  742. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  743. };
  744. // MOMENTS
  745. var getSetYear = makeGetSet('FullYear', false);
  746. function getIsLeapYear () {
  747. return isLeapYear(this.year());
  748. }
  749. addFormatToken('w', ['ww', 2], 'wo', 'week');
  750. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  751. // ALIASES
  752. addUnitAlias('week', 'w');
  753. addUnitAlias('isoWeek', 'W');
  754. // PARSING
  755. addRegexToken('w', match1to2);
  756. addRegexToken('ww', match1to2, match2);
  757. addRegexToken('W', match1to2);
  758. addRegexToken('WW', match1to2, match2);
  759. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  760. week[token.substr(0, 1)] = toInt(input);
  761. });
  762. // HELPERS
  763. // firstDayOfWeek 0 = sun, 6 = sat
  764. // the day of the week that starts the week
  765. // (usually sunday or monday)
  766. // firstDayOfWeekOfYear 0 = sun, 6 = sat
  767. // the first week is the week that contains the first
  768. // of this day of the week
  769. // (eg. ISO weeks use thursday (4))
  770. function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
  771. var end = firstDayOfWeekOfYear - firstDayOfWeek,
  772. daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
  773. adjustedMoment;
  774. if (daysToDayOfWeek > end) {
  775. daysToDayOfWeek -= 7;
  776. }
  777. if (daysToDayOfWeek < end - 7) {
  778. daysToDayOfWeek += 7;
  779. }
  780. adjustedMoment = local__createLocal(mom).add(daysToDayOfWeek, 'd');
  781. return {
  782. week: Math.ceil(adjustedMoment.dayOfYear() / 7),
  783. year: adjustedMoment.year()
  784. };
  785. }
  786. // LOCALES
  787. function localeWeek (mom) {
  788. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  789. }
  790. var defaultLocaleWeek = {
  791. dow : 0, // Sunday is the first day of the week.
  792. doy : 6 // The week that contains Jan 1st is the first week of the year.
  793. };
  794. function localeFirstDayOfWeek () {
  795. return this._week.dow;
  796. }
  797. function localeFirstDayOfYear () {
  798. return this._week.doy;
  799. }
  800. // MOMENTS
  801. function getSetWeek (input) {
  802. var week = this.localeData().week(this);
  803. return input == null ? week : this.add((input - week) * 7, 'd');
  804. }
  805. function getSetISOWeek (input) {
  806. var week = weekOfYear(this, 1, 4).week;
  807. return input == null ? week : this.add((input - week) * 7, 'd');
  808. }
  809. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  810. // ALIASES
  811. addUnitAlias('dayOfYear', 'DDD');
  812. // PARSING
  813. addRegexToken('DDD', match1to3);
  814. addRegexToken('DDDD', match3);
  815. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  816. config._dayOfYear = toInt(input);
  817. });
  818. // HELPERS
  819. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  820. function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
  821. var d = createUTCDate(year, 0, 1).getUTCDay();
  822. var daysToAdd;
  823. var dayOfYear;
  824. d = d === 0 ? 7 : d;
  825. weekday = weekday != null ? weekday : firstDayOfWeek;
  826. daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
  827. dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
  828. return {
  829. year : dayOfYear > 0 ? year : year - 1,
  830. dayOfYear : dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
  831. };
  832. }
  833. // MOMENTS
  834. function getSetDayOfYear (input) {
  835. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  836. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  837. }
  838. // Pick the first defined of two or three arguments.
  839. function defaults(a, b, c) {
  840. if (a != null) {
  841. return a;
  842. }
  843. if (b != null) {
  844. return b;
  845. }
  846. return c;
  847. }
  848. function currentDateArray(config) {
  849. var now = new Date();
  850. if (config._useUTC) {
  851. return [now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()];
  852. }
  853. return [now.getFullYear(), now.getMonth(), now.getDate()];
  854. }
  855. // convert an array to a date.
  856. // the array should mirror the parameters below
  857. // note: all values past the year are optional and will default to the lowest possible value.
  858. // [year, month, day , hour, minute, second, millisecond]
  859. function configFromArray (config) {
  860. var i, date, input = [], currentDate, yearToUse;
  861. if (config._d) {
  862. return;
  863. }
  864. currentDate = currentDateArray(config);
  865. //compute day of the year from weeks and weekdays
  866. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  867. dayOfYearFromWeekInfo(config);
  868. }
  869. //if the day of the year is set, figure out what it is
  870. if (config._dayOfYear) {
  871. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  872. if (config._dayOfYear > daysInYear(yearToUse)) {
  873. getParsingFlags(config)._overflowDayOfYear = true;
  874. }
  875. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  876. config._a[MONTH] = date.getUTCMonth();
  877. config._a[DATE] = date.getUTCDate();
  878. }
  879. // Default to current date.
  880. // * if no year, month, day of month are given, default to today
  881. // * if day of month is given, default month and year
  882. // * if month is given, default only year
  883. // * if year is given, don't default anything
  884. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  885. config._a[i] = input[i] = currentDate[i];
  886. }
  887. // Zero out whatever was not defaulted, including time
  888. for (; i < 7; i++) {
  889. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  890. }
  891. // Check for 24:00:00.000
  892. if (config._a[HOUR] === 24 &&
  893. config._a[MINUTE] === 0 &&
  894. config._a[SECOND] === 0 &&
  895. config._a[MILLISECOND] === 0) {
  896. config._nextDay = true;
  897. config._a[HOUR] = 0;
  898. }
  899. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  900. // Apply timezone offset from input. The actual utcOffset can be changed
  901. // with parseZone.
  902. if (config._tzm != null) {
  903. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  904. }
  905. if (config._nextDay) {
  906. config._a[HOUR] = 24;
  907. }
  908. }
  909. function dayOfYearFromWeekInfo(config) {
  910. var w, weekYear, week, weekday, dow, doy, temp;
  911. w = config._w;
  912. if (w.GG != null || w.W != null || w.E != null) {
  913. dow = 1;
  914. doy = 4;
  915. // TODO: We need to take the current isoWeekYear, but that depends on
  916. // how we interpret now (local, utc, fixed offset). So create
  917. // a now version of current config (take local/utc/offset flags, and
  918. // create now).
  919. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
  920. week = defaults(w.W, 1);
  921. weekday = defaults(w.E, 1);
  922. } else {
  923. dow = config._locale._week.dow;
  924. doy = config._locale._week.doy;
  925. weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
  926. week = defaults(w.w, 1);
  927. if (w.d != null) {
  928. // weekday -- low day numbers are considered next week
  929. weekday = w.d;
  930. if (weekday < dow) {
  931. ++week;
  932. }
  933. } else if (w.e != null) {
  934. // local weekday -- counting starts from begining of week
  935. weekday = w.e + dow;
  936. } else {
  937. // default to begining of week
  938. weekday = dow;
  939. }
  940. }
  941. temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
  942. config._a[YEAR] = temp.year;
  943. config._dayOfYear = temp.dayOfYear;
  944. }
  945. utils_hooks__hooks.ISO_8601 = function () {};
  946. // date from string and format string
  947. function configFromStringAndFormat(config) {
  948. // TODO: Move this to another part of the creation flow to prevent circular deps
  949. if (config._f === utils_hooks__hooks.ISO_8601) {
  950. configFromISO(config);
  951. return;
  952. }
  953. config._a = [];
  954. getParsingFlags(config).empty = true;
  955. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  956. var string = '' + config._i,
  957. i, parsedInput, tokens, token, skipped,
  958. stringLength = string.length,
  959. totalParsedInputLength = 0;
  960. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  961. for (i = 0; i < tokens.length; i++) {
  962. token = tokens[i];
  963. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  964. if (parsedInput) {
  965. skipped = string.substr(0, string.indexOf(parsedInput));
  966. if (skipped.length > 0) {
  967. getParsingFlags(config).unusedInput.push(skipped);
  968. }
  969. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  970. totalParsedInputLength += parsedInput.length;
  971. }
  972. // don't parse if it's not a known token
  973. if (formatTokenFunctions[token]) {
  974. if (parsedInput) {
  975. getParsingFlags(config).empty = false;
  976. }
  977. else {
  978. getParsingFlags(config).unusedTokens.push(token);
  979. }
  980. addTimeToArrayFromToken(token, parsedInput, config);
  981. }
  982. else if (config._strict && !parsedInput) {
  983. getParsingFlags(config).unusedTokens.push(token);
  984. }
  985. }
  986. // add remaining unparsed input length to the string
  987. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  988. if (string.length > 0) {
  989. getParsingFlags(config).unusedInput.push(string);
  990. }
  991. // clear _12h flag if hour is <= 12
  992. if (getParsingFlags(config).bigHour === true &&
  993. config._a[HOUR] <= 12 &&
  994. config._a[HOUR] > 0) {
  995. getParsingFlags(config).bigHour = undefined;
  996. }
  997. // handle meridiem
  998. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  999. configFromArray(config);
  1000. checkOverflow(config);
  1001. }
  1002. function meridiemFixWrap (locale, hour, meridiem) {
  1003. var isPm;
  1004. if (meridiem == null) {
  1005. // nothing to do
  1006. return hour;
  1007. }
  1008. if (locale.meridiemHour != null) {
  1009. return locale.meridiemHour(hour, meridiem);
  1010. } else if (locale.isPM != null) {
  1011. // Fallback
  1012. isPm = locale.isPM(meridiem);
  1013. if (isPm && hour < 12) {
  1014. hour += 12;
  1015. }
  1016. if (!isPm && hour === 12) {
  1017. hour = 0;
  1018. }
  1019. return hour;
  1020. } else {
  1021. // this is not supposed to happen
  1022. return hour;
  1023. }
  1024. }
  1025. function configFromStringAndArray(config) {
  1026. var tempConfig,
  1027. bestMoment,
  1028. scoreToBeat,
  1029. i,
  1030. currentScore;
  1031. if (config._f.length === 0) {
  1032. getParsingFlags(config).invalidFormat = true;
  1033. config._d = new Date(NaN);
  1034. return;
  1035. }
  1036. for (i = 0; i < config._f.length; i++) {
  1037. currentScore = 0;
  1038. tempConfig = copyConfig({}, config);
  1039. if (config._useUTC != null) {
  1040. tempConfig._useUTC = config._useUTC;
  1041. }
  1042. tempConfig._f = config._f[i];
  1043. configFromStringAndFormat(tempConfig);
  1044. if (!valid__isValid(tempConfig)) {
  1045. continue;
  1046. }
  1047. // if there is any input that was not parsed add a penalty for that format
  1048. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  1049. //or tokens
  1050. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  1051. getParsingFlags(tempConfig).score = currentScore;
  1052. if (scoreToBeat == null || currentScore < scoreToBeat) {
  1053. scoreToBeat = currentScore;
  1054. bestMoment = tempConfig;
  1055. }
  1056. }
  1057. extend(config, bestMoment || tempConfig);
  1058. }
  1059. function configFromObject(config) {
  1060. if (config._d) {
  1061. return;
  1062. }
  1063. var i = normalizeObjectUnits(config._i);
  1064. config._a = [i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond];
  1065. configFromArray(config);
  1066. }
  1067. function createFromConfig (config) {
  1068. var input = config._i,
  1069. format = config._f,
  1070. res;
  1071. config._locale = config._locale || locale_locales__getLocale(config._l);
  1072. if (input === null || (format === undefined && input === '')) {
  1073. return valid__createInvalid({nullInput: true});
  1074. }
  1075. if (typeof input === 'string') {
  1076. config._i = input = config._locale.preparse(input);
  1077. }
  1078. if (isMoment(input)) {
  1079. return new Moment(checkOverflow(input));
  1080. } else if (isArray(format)) {
  1081. configFromStringAndArray(config);
  1082. } else if (format) {
  1083. configFromStringAndFormat(config);
  1084. } else if (isDate(input)) {
  1085. config._d = input;
  1086. } else {
  1087. configFromInput(config);
  1088. }
  1089. res = new Moment(checkOverflow(config));
  1090. if (res._nextDay) {
  1091. // Adding is smart enough around DST
  1092. res.add(1, 'd');
  1093. res._nextDay = undefined;
  1094. }
  1095. return res;
  1096. }
  1097. function configFromInput(config) {
  1098. var input = config._i;
  1099. if (input === undefined) {
  1100. config._d = new Date();
  1101. } else if (isDate(input)) {
  1102. config._d = new Date(+input);
  1103. } else if (typeof input === 'string') {
  1104. configFromString(config);
  1105. } else if (isArray(input)) {
  1106. config._a = map(input.slice(0), function (obj) {
  1107. return parseInt(obj, 10);
  1108. });
  1109. configFromArray(config);
  1110. } else if (typeof(input) === 'object') {
  1111. configFromObject(config);
  1112. } else if (typeof(input) === 'number') {
  1113. // from milliseconds
  1114. config._d = new Date(input);
  1115. } else {
  1116. utils_hooks__hooks.createFromInputFallback(config);
  1117. }
  1118. }
  1119. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  1120. var c = {};
  1121. if (typeof(locale) === 'boolean') {
  1122. strict = locale;
  1123. locale = undefined;
  1124. }
  1125. // object construction must be done this way.
  1126. // https://github.com/moment/moment/issues/1423
  1127. c._isAMomentObject = true;
  1128. c._useUTC = c._isUTC = isUTC;
  1129. c._l = locale;
  1130. c._i = input;
  1131. c._f = format;
  1132. c._strict = strict;
  1133. return createFromConfig(c);
  1134. }
  1135. function local__createLocal (input, format, locale, strict) {
  1136. return createLocalOrUTC(input, format, locale, strict, false);
  1137. }
  1138. var prototypeMin = deprecate(
  1139. 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
  1140. function () {
  1141. var other = local__createLocal.apply(null, arguments);
  1142. return other < this ? this : other;
  1143. }
  1144. );
  1145. var prototypeMax = deprecate(
  1146. 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
  1147. function () {
  1148. var other = local__createLocal.apply(null, arguments);
  1149. return other > this ? this : other;
  1150. }
  1151. );
  1152. // Pick a moment m from moments so that m[fn](other) is true for all
  1153. // other. This relies on the function fn to be transitive.
  1154. //
  1155. // moments should either be an array of moment objects or an array, whose
  1156. // first element is an array of moment objects.
  1157. function pickBy(fn, moments) {
  1158. var res, i;
  1159. if (moments.length === 1 && isArray(moments[0])) {
  1160. moments = moments[0];
  1161. }
  1162. if (!moments.length) {
  1163. return local__createLocal();
  1164. }
  1165. res = moments[0];
  1166. for (i = 1; i < moments.length; ++i) {
  1167. if (moments[i][fn](res)) {
  1168. res = moments[i];
  1169. }
  1170. }
  1171. return res;
  1172. }
  1173. // TODO: Use [].sort instead?
  1174. function min () {
  1175. var args = [].slice.call(arguments, 0);
  1176. return pickBy('isBefore', args);
  1177. }
  1178. function max () {
  1179. var args = [].slice.call(arguments, 0);
  1180. return pickBy('isAfter', args);
  1181. }
  1182. function Duration (duration) {
  1183. var normalizedInput = normalizeObjectUnits(duration),
  1184. years = normalizedInput.year || 0,
  1185. quarters = normalizedInput.quarter || 0,
  1186. months = normalizedInput.month || 0,
  1187. weeks = normalizedInput.week || 0,
  1188. days = normalizedInput.day || 0,
  1189. hours = normalizedInput.hour || 0,
  1190. minutes = normalizedInput.minute || 0,
  1191. seconds = normalizedInput.second || 0,
  1192. milliseconds = normalizedInput.millisecond || 0;
  1193. // representation for dateAddRemove
  1194. this._milliseconds = +milliseconds +
  1195. seconds * 1e3 + // 1000
  1196. minutes * 6e4 + // 1000 * 60
  1197. hours * 36e5; // 1000 * 60 * 60
  1198. // Because of dateAddRemove treats 24 hours as different from a
  1199. // day when working around DST, we need to store them separately
  1200. this._days = +days +
  1201. weeks * 7;
  1202. // It is impossible translate months into days without knowing
  1203. // which months you are are talking about, so we have to store
  1204. // it separately.
  1205. this._months = +months +
  1206. quarters * 3 +
  1207. years * 12;
  1208. this._data = {};
  1209. this._locale = locale_locales__getLocale();
  1210. this._bubble();
  1211. }
  1212. function isDuration (obj) {
  1213. return obj instanceof Duration;
  1214. }
  1215. function offset (token, separator) {
  1216. addFormatToken(token, 0, 0, function () {
  1217. var offset = this.utcOffset();
  1218. var sign = '+';
  1219. if (offset < 0) {
  1220. offset = -offset;
  1221. sign = '-';
  1222. }
  1223. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  1224. });
  1225. }
  1226. offset('Z', ':');
  1227. offset('ZZ', '');
  1228. // PARSING
  1229. addRegexToken('Z', matchOffset);
  1230. addRegexToken('ZZ', matchOffset);
  1231. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  1232. config._useUTC = true;
  1233. config._tzm = offsetFromString(input);
  1234. });
  1235. // HELPERS
  1236. // timezone chunker
  1237. // '+10:00' > ['10', '00']
  1238. // '-1530' > ['-15', '30']
  1239. var chunkOffset = /([\+\-]|\d\d)/gi;
  1240. function offsetFromString(string) {
  1241. var matches = ((string || '').match(matchOffset) || []);
  1242. var chunk = matches[matches.length - 1] || [];
  1243. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  1244. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  1245. return parts[0] === '+' ? minutes : -minutes;
  1246. }
  1247. // Return a moment from input, that is local/utc/zone equivalent to model.
  1248. function cloneWithOffset(input, model) {
  1249. var res, diff;
  1250. if (model._isUTC) {
  1251. res = model.clone();
  1252. diff = (isMoment(input) || isDate(input) ? +input : +local__createLocal(input)) - (+res);
  1253. // Use low-level api, because this fn is low-level api.
  1254. res._d.setTime(+res._d + diff);
  1255. utils_hooks__hooks.updateOffset(res, false);
  1256. return res;
  1257. } else {
  1258. return local__createLocal(input).local();
  1259. }
  1260. return model._isUTC ? local__createLocal(input).zone(model._offset || 0) : local__createLocal(input).local();
  1261. }
  1262. function getDateOffset (m) {
  1263. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  1264. // https://github.com/moment/moment/pull/1871
  1265. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  1266. }
  1267. // HOOKS
  1268. // This function will be called whenever a moment is mutated.
  1269. // It is intended to keep the offset in sync with the timezone.
  1270. utils_hooks__hooks.updateOffset = function () {};
  1271. // MOMENTS
  1272. // keepLocalTime = true means only change the timezone, without
  1273. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  1274. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  1275. // +0200, so we adjust the time as needed, to be valid.
  1276. //
  1277. // Keeping the time actually adds/subtracts (one hour)
  1278. // from the actual represented time. That is why we call updateOffset
  1279. // a second time. In case it wants us to change the offset again
  1280. // _changeInProgress == true case, then we have to adjust, because
  1281. // there is no such time in the given timezone.
  1282. function getSetOffset (input, keepLocalTime) {
  1283. var offset = this._offset || 0,
  1284. localAdjust;
  1285. if (input != null) {
  1286. if (typeof input === 'string') {
  1287. input = offsetFromString(input);
  1288. }
  1289. if (Math.abs(input) < 16) {
  1290. input = input * 60;
  1291. }
  1292. if (!this._isUTC && keepLocalTime) {
  1293. localAdjust = getDateOffset(this);
  1294. }
  1295. this._offset = input;
  1296. this._isUTC = true;
  1297. if (localAdjust != null) {
  1298. this.add(localAdjust, 'm');
  1299. }
  1300. if (offset !== input) {
  1301. if (!keepLocalTime || this._changeInProgress) {
  1302. add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
  1303. } else if (!this._changeInProgress) {
  1304. this._changeInProgress = true;
  1305. utils_hooks__hooks.updateOffset(this, true);
  1306. this._changeInProgress = null;
  1307. }
  1308. }
  1309. return this;
  1310. } else {
  1311. return this._isUTC ? offset : getDateOffset(this);
  1312. }
  1313. }
  1314. function getSetZone (input, keepLocalTime) {
  1315. if (input != null) {
  1316. if (typeof input !== 'string') {
  1317. input = -input;
  1318. }
  1319. this.utcOffset(input, keepLocalTime);
  1320. return this;
  1321. } else {
  1322. return -this.utcOffset();
  1323. }
  1324. }
  1325. function setOffsetToUTC (keepLocalTime) {
  1326. return this.utcOffset(0, keepLocalTime);
  1327. }
  1328. function setOffsetToLocal (keepLocalTime) {
  1329. if (this._isUTC) {
  1330. this.utcOffset(0, keepLocalTime);
  1331. this._isUTC = false;
  1332. if (keepLocalTime) {
  1333. this.subtract(getDateOffset(this), 'm');
  1334. }
  1335. }
  1336. return this;
  1337. }
  1338. function setOffsetToParsedOffset () {
  1339. if (this._tzm) {
  1340. this.utcOffset(this._tzm);
  1341. } else if (typeof this._i === 'string') {
  1342. this.utcOffset(offsetFromString(this._i));
  1343. }
  1344. return this;
  1345. }
  1346. function hasAlignedHourOffset (input) {
  1347. if (!input) {
  1348. input = 0;
  1349. }
  1350. else {
  1351. input = local__createLocal(input).utcOffset();
  1352. }
  1353. return (this.utcOffset() - input) % 60 === 0;
  1354. }
  1355. function isDaylightSavingTime () {
  1356. return (
  1357. this.utcOffset() > this.clone().month(0).utcOffset() ||
  1358. this.utcOffset() > this.clone().month(5).utcOffset()
  1359. );
  1360. }
  1361. function isDaylightSavingTimeShifted () {
  1362. if (this._a) {
  1363. var other = this._isUTC ? create_utc__createUTC(this._a) : local__createLocal(this._a);
  1364. return this.isValid() && compareArrays(this._a, other.toArray()) > 0;
  1365. }
  1366. return false;
  1367. }
  1368. function isLocal () {
  1369. return !this._isUTC;
  1370. }
  1371. function isUtcOffset () {
  1372. return this._isUTC;
  1373. }
  1374. function isUtc () {
  1375. return this._isUTC && this._offset === 0;
  1376. }
  1377. var aspNetRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/;
  1378. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  1379. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  1380. var create__isoRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;
  1381. function create__createDuration (input, key) {
  1382. var duration = input,
  1383. // matching against regexp is expensive, do it on demand
  1384. match = null,
  1385. sign,
  1386. ret,
  1387. diffRes;
  1388. if (isDuration(input)) {
  1389. duration = {
  1390. ms : input._milliseconds,
  1391. d : input._days,
  1392. M : input._months
  1393. };
  1394. } else if (typeof input === 'number') {
  1395. duration = {};
  1396. if (key) {
  1397. duration[key] = input;
  1398. } else {
  1399. duration.milliseconds = input;
  1400. }
  1401. } else if (!!(match = aspNetRegex.exec(input))) {
  1402. sign = (match[1] === '-') ? -1 : 1;
  1403. duration = {
  1404. y : 0,
  1405. d : toInt(match[DATE]) * sign,
  1406. h : toInt(match[HOUR]) * sign,
  1407. m : toInt(match[MINUTE]) * sign,
  1408. s : toInt(match[SECOND]) * sign,
  1409. ms : toInt(match[MILLISECOND]) * sign
  1410. };
  1411. } else if (!!(match = create__isoRegex.exec(input))) {
  1412. sign = (match[1] === '-') ? -1 : 1;
  1413. duration = {
  1414. y : parseIso(match[2], sign),
  1415. M : parseIso(match[3], sign),
  1416. d : parseIso(match[4], sign),
  1417. h : parseIso(match[5], sign),
  1418. m : parseIso(match[6], sign),
  1419. s : parseIso(match[7], sign),
  1420. w : parseIso(match[8], sign)
  1421. };
  1422. } else if (duration == null) {// checks for null or undefined
  1423. duration = {};
  1424. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  1425. diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
  1426. duration = {};
  1427. duration.ms = diffRes.milliseconds;
  1428. duration.M = diffRes.months;
  1429. }
  1430. ret = new Duration(duration);
  1431. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  1432. ret._locale = input._locale;
  1433. }
  1434. return ret;
  1435. }
  1436. create__createDuration.fn = Duration.prototype;
  1437. function parseIso (inp, sign) {
  1438. // We'd normally use ~~inp for this, but unfortunately it also
  1439. // converts floats to ints.
  1440. // inp may be undefined, so careful calling replace on it.
  1441. var res = inp && parseFloat(inp.replace(',', '.'));
  1442. // apply sign while we're at it
  1443. return (isNaN(res) ? 0 : res) * sign;
  1444. }
  1445. function positiveMomentsDifference(base, other) {
  1446. var res = {milliseconds: 0, months: 0};
  1447. res.months = other.month() - base.month() +
  1448. (other.year() - base.year()) * 12;
  1449. if (base.clone().add(res.months, 'M').isAfter(other)) {
  1450. --res.months;
  1451. }
  1452. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  1453. return res;
  1454. }
  1455. function momentsDifference(base, other) {
  1456. var res;
  1457. other = cloneWithOffset(other, base);
  1458. if (base.isBefore(other)) {
  1459. res = positiveMomentsDifference(base, other);
  1460. } else {
  1461. res = positiveMomentsDifference(other, base);
  1462. res.milliseconds = -res.milliseconds;
  1463. res.months = -res.months;
  1464. }
  1465. return res;
  1466. }
  1467. function createAdder(direction, name) {
  1468. return function (val, period) {
  1469. var dur, tmp;
  1470. //invert the arguments, but complain about it
  1471. if (period !== null && !isNaN(+period)) {
  1472. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
  1473. tmp = val; val = period; period = tmp;
  1474. }
  1475. val = typeof val === 'string' ? +val : val;
  1476. dur = create__createDuration(val, period);
  1477. add_subtract__addSubtract(this, dur, direction);
  1478. return this;
  1479. };
  1480. }
  1481. function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
  1482. var milliseconds = duration._milliseconds,
  1483. days = duration._days,
  1484. months = duration._months;
  1485. updateOffset = updateOffset == null ? true : updateOffset;
  1486. if (milliseconds) {
  1487. mom._d.setTime(+mom._d + milliseconds * isAdding);
  1488. }
  1489. if (days) {
  1490. get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
  1491. }
  1492. if (months) {
  1493. setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
  1494. }
  1495. if (updateOffset) {
  1496. utils_hooks__hooks.updateOffset(mom, days || months);
  1497. }
  1498. }
  1499. var add_subtract__add = createAdder(1, 'add');
  1500. var add_subtract__subtract = createAdder(-1, 'subtract');
  1501. function moment_calendar__calendar (time) {
  1502. // We want to compare the start of today, vs this.
  1503. // Getting start-of-today depends on whether we're local/utc/offset or not.
  1504. var now = time || local__createLocal(),
  1505. sod = cloneWithOffset(now, this).startOf('day'),
  1506. diff = this.diff(sod, 'days', true),
  1507. format = diff < -6 ? 'sameElse' :
  1508. diff < -1 ? 'lastWeek' :
  1509. diff < 0 ? 'lastDay' :
  1510. diff < 1 ? 'sameDay' :
  1511. diff < 2 ? 'nextDay' :
  1512. diff < 7 ? 'nextWeek' : 'sameElse';
  1513. return this.format(this.localeData().calendar(format, this, local__createLocal(now)));
  1514. }
  1515. function clone () {
  1516. return new Moment(this);
  1517. }
  1518. function isAfter (input, units) {
  1519. var inputMs;
  1520. units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
  1521. if (units === 'millisecond') {
  1522. input = isMoment(input) ? input : local__createLocal(input);
  1523. return +this > +input;
  1524. } else {
  1525. inputMs = isMoment(input) ? +input : +local__createLocal(input);
  1526. return inputMs < +this.clone().startOf(units);
  1527. }
  1528. }
  1529. function isBefore (input, units) {
  1530. var inputMs;
  1531. units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
  1532. if (units === 'millisecond') {
  1533. input = isMoment(input) ? input : local__createLocal(input);
  1534. return +this < +input;
  1535. } else {
  1536. inputMs = isMoment(input) ? +input : +local__createLocal(input);
  1537. return +this.clone().endOf(units) < inputMs;
  1538. }
  1539. }
  1540. function isBetween (from, to, units) {
  1541. return this.isAfter(from, units) && this.isBefore(to, units);
  1542. }
  1543. function isSame (input, units) {
  1544. var inputMs;
  1545. units = normalizeUnits(units || 'millisecond');
  1546. if (units === 'millisecond') {
  1547. input = isMoment(input) ? input : local__createLocal(input);
  1548. return +this === +input;
  1549. } else {
  1550. inputMs = +local__createLocal(input);
  1551. return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units));
  1552. }
  1553. }
  1554. function absFloor (number) {
  1555. if (number < 0) {
  1556. return Math.ceil(number);
  1557. } else {
  1558. return Math.floor(number);
  1559. }
  1560. }
  1561. function diff (input, units, asFloat) {
  1562. var that = cloneWithOffset(input, this),
  1563. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4,
  1564. delta, output;
  1565. units = normalizeUnits(units);
  1566. if (units === 'year' || units === 'month' || units === 'quarter') {
  1567. output = monthDiff(this, that);
  1568. if (units === 'quarter') {
  1569. output = output / 3;
  1570. } else if (units === 'year') {
  1571. output = output / 12;
  1572. }
  1573. } else {
  1574. delta = this - that;
  1575. output = units === 'second' ? delta / 1e3 : // 1000
  1576. units === 'minute' ? delta / 6e4 : // 1000 * 60
  1577. units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
  1578. units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  1579. units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  1580. delta;
  1581. }
  1582. return asFloat ? output : absFloor(output);
  1583. }
  1584. function monthDiff (a, b) {
  1585. // difference in months
  1586. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  1587. // b is in (anchor - 1 month, anchor + 1 month)
  1588. anchor = a.clone().add(wholeMonthDiff, 'months'),
  1589. anchor2, adjust;
  1590. if (b - anchor < 0) {
  1591. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  1592. // linear across the month
  1593. adjust = (b - anchor) / (anchor - anchor2);
  1594. } else {
  1595. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  1596. // linear across the month
  1597. adjust = (b - anchor) / (anchor2 - anchor);
  1598. }
  1599. return -(wholeMonthDiff + adjust);
  1600. }
  1601. utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  1602. function toString () {
  1603. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  1604. }
  1605. function moment_format__toISOString () {
  1606. var m = this.clone().utc();
  1607. if (0 < m.year() && m.year() <= 9999) {
  1608. if ('function' === typeof Date.prototype.toISOString) {
  1609. // native implementation is ~50x faster, use it when we can
  1610. return this.toDate().toISOString();
  1611. } else {
  1612. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1613. }
  1614. } else {
  1615. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1616. }
  1617. }
  1618. function format (inputString) {
  1619. var output = formatMoment(this, inputString || utils_hooks__hooks.defaultFormat);
  1620. return this.localeData().postformat(output);
  1621. }
  1622. function from (time, withoutSuffix) {
  1623. if (!this.isValid()) {
  1624. return this.localeData().invalidDate();
  1625. }
  1626. return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  1627. }
  1628. function fromNow (withoutSuffix) {
  1629. return this.from(local__createLocal(), withoutSuffix);
  1630. }
  1631. function to (time, withoutSuffix) {
  1632. if (!this.isValid()) {
  1633. return this.localeData().invalidDate();
  1634. }
  1635. return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  1636. }
  1637. function toNow (withoutSuffix) {
  1638. return this.to(local__createLocal(), withoutSuffix);
  1639. }
  1640. function locale (key) {
  1641. var newLocaleData;
  1642. if (key === undefined) {
  1643. return this._locale._abbr;
  1644. } else {
  1645. newLocaleData = locale_locales__getLocale(key);
  1646. if (newLocaleData != null) {
  1647. this._locale = newLocaleData;
  1648. }
  1649. return this;
  1650. }
  1651. }
  1652. var lang = deprecate(
  1653. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  1654. function (key) {
  1655. if (key === undefined) {
  1656. return this.localeData();
  1657. } else {
  1658. return this.locale(key);
  1659. }
  1660. }
  1661. );
  1662. function localeData () {
  1663. return this._locale;
  1664. }
  1665. function startOf (units) {
  1666. units = normalizeUnits(units);
  1667. // the following switch intentionally omits break keywords
  1668. // to utilize falling through the cases.
  1669. switch (units) {
  1670. case 'year':
  1671. this.month(0);
  1672. /* falls through */
  1673. case 'quarter':
  1674. case 'month':
  1675. this.date(1);
  1676. /* falls through */
  1677. case 'week':
  1678. case 'isoWeek':
  1679. case 'day':
  1680. this.hours(0);
  1681. /* falls through */
  1682. case 'hour':
  1683. this.minutes(0);
  1684. /* falls through */
  1685. case 'minute':
  1686. this.seconds(0);
  1687. /* falls through */
  1688. case 'second':
  1689. this.milliseconds(0);
  1690. }
  1691. // weeks are a special case
  1692. if (units === 'week') {
  1693. this.weekday(0);
  1694. }
  1695. if (units === 'isoWeek') {
  1696. this.isoWeekday(1);
  1697. }
  1698. // quarters are also special
  1699. if (units === 'quarter') {
  1700. this.month(Math.floor(this.month() / 3) * 3);
  1701. }
  1702. return this;
  1703. }
  1704. function endOf (units) {
  1705. units = normalizeUnits(units);
  1706. if (units === undefined || units === 'millisecond') {
  1707. return this;
  1708. }
  1709. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  1710. }
  1711. function to_type__valueOf () {
  1712. return +this._d - ((this._offset || 0) * 60000);
  1713. }
  1714. function unix () {
  1715. return Math.floor(+this / 1000);
  1716. }
  1717. function toDate () {
  1718. return this._offset ? new Date(+this) : this._d;
  1719. }
  1720. function toArray () {
  1721. var m = this;
  1722. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  1723. }
  1724. function moment_valid__isValid () {
  1725. return valid__isValid(this);
  1726. }
  1727. function parsingFlags () {
  1728. return extend({}, getParsingFlags(this));
  1729. }
  1730. function invalidAt () {
  1731. return getParsingFlags(this).overflow;
  1732. }
  1733. addFormatToken(0, ['gg', 2], 0, function () {
  1734. return this.weekYear() % 100;
  1735. });
  1736. addFormatToken(0, ['GG', 2], 0, function () {
  1737. return this.isoWeekYear() % 100;
  1738. });
  1739. function addWeekYearFormatToken (token, getter) {
  1740. addFormatToken(0, [token, token.length], 0, getter);
  1741. }
  1742. addWeekYearFormatToken('gggg', 'weekYear');
  1743. addWeekYearFormatToken('ggggg', 'weekYear');
  1744. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  1745. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  1746. // ALIASES
  1747. addUnitAlias('weekYear', 'gg');
  1748. addUnitAlias('isoWeekYear', 'GG');
  1749. // PARSING
  1750. addRegexToken('G', matchSigned);
  1751. addRegexToken('g', matchSigned);
  1752. addRegexToken('GG', match1to2, match2);
  1753. addRegexToken('gg', match1to2, match2);
  1754. addRegexToken('GGGG', match1to4, match4);
  1755. addRegexToken('gggg', match1to4, match4);
  1756. addRegexToken('GGGGG', match1to6, match6);
  1757. addRegexToken('ggggg', match1to6, match6);
  1758. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  1759. week[token.substr(0, 2)] = toInt(input);
  1760. });
  1761. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  1762. week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
  1763. });
  1764. // HELPERS
  1765. function weeksInYear(year, dow, doy) {
  1766. return weekOfYear(local__createLocal([year, 11, 31 + dow - doy]), dow, doy).week;
  1767. }
  1768. // MOMENTS
  1769. function getSetWeekYear (input) {
  1770. var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;
  1771. return input == null ? year : this.add((input - year), 'y');
  1772. }
  1773. function getSetISOWeekYear (input) {
  1774. var year = weekOfYear(this, 1, 4).year;
  1775. return input == null ? year : this.add((input - year), 'y');
  1776. }
  1777. function getISOWeeksInYear () {
  1778. return weeksInYear(this.year(), 1, 4);
  1779. }
  1780. function getWeeksInYear () {
  1781. var weekInfo = this.localeData()._week;
  1782. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  1783. }
  1784. addFormatToken('Q', 0, 0, 'quarter');
  1785. // ALIASES
  1786. addUnitAlias('quarter', 'Q');
  1787. // PARSING
  1788. addRegexToken('Q', match1);
  1789. addParseToken('Q', function (input, array) {
  1790. array[MONTH] = (toInt(input) - 1) * 3;
  1791. });
  1792. // MOMENTS
  1793. function getSetQuarter (input) {
  1794. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  1795. }
  1796. addFormatToken('D', ['DD', 2], 'Do', 'date');
  1797. // ALIASES
  1798. addUnitAlias('date', 'D');
  1799. // PARSING
  1800. addRegexToken('D', match1to2);
  1801. addRegexToken('DD', match1to2, match2);
  1802. addRegexToken('Do', function (isStrict, locale) {
  1803. return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
  1804. });
  1805. addParseToken(['D', 'DD'], DATE);
  1806. addParseToken('Do', function (input, array) {
  1807. array[DATE] = toInt(input.match(match1to2)[0], 10);
  1808. });
  1809. // MOMENTS
  1810. var getSetDayOfMonth = makeGetSet('Date', true);
  1811. addFormatToken('d', 0, 'do', 'day');
  1812. addFormatToken('dd', 0, 0, function (format) {
  1813. return this.localeData().weekdaysMin(this, format);
  1814. });
  1815. addFormatToken('ddd', 0, 0, function (format) {
  1816. return this.localeData().weekdaysShort(this, format);
  1817. });
  1818. addFormatToken('dddd', 0, 0, function (format) {
  1819. return this.localeData().weekdays(this, format);
  1820. });
  1821. addFormatToken('e', 0, 0, 'weekday');
  1822. addFormatToken('E', 0, 0, 'isoWeekday');
  1823. // ALIASES
  1824. addUnitAlias('day', 'd');
  1825. addUnitAlias('weekday', 'e');
  1826. addUnitAlias('isoWeekday', 'E');
  1827. // PARSING
  1828. addRegexToken('d', match1to2);
  1829. addRegexToken('e', match1to2);
  1830. addRegexToken('E', match1to2);
  1831. addRegexToken('dd', matchWord);
  1832. addRegexToken('ddd', matchWord);
  1833. addRegexToken('dddd', matchWord);
  1834. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config) {
  1835. var weekday = config._locale.weekdaysParse(input);
  1836. // if we didn't get a weekday name, mark the date as invalid
  1837. if (weekday != null) {
  1838. week.d = weekday;
  1839. } else {
  1840. getParsingFlags(config).invalidWeekday = input;
  1841. }
  1842. });
  1843. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  1844. week[token] = toInt(input);
  1845. });
  1846. // HELPERS
  1847. function parseWeekday(input, locale) {
  1848. if (typeof input === 'string') {
  1849. if (!isNaN(input)) {
  1850. input = parseInt(input, 10);
  1851. }
  1852. else {
  1853. input = locale.weekdaysParse(input);
  1854. if (typeof input !== 'number') {
  1855. return null;
  1856. }
  1857. }
  1858. }
  1859. return input;
  1860. }
  1861. // LOCALES
  1862. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  1863. function localeWeekdays (m) {
  1864. return this._weekdays[m.day()];
  1865. }
  1866. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  1867. function localeWeekdaysShort (m) {
  1868. return this._weekdaysShort[m.day()];
  1869. }
  1870. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  1871. function localeWeekdaysMin (m) {
  1872. return this._weekdaysMin[m.day()];
  1873. }
  1874. function localeWeekdaysParse (weekdayName) {
  1875. var i, mom, regex;
  1876. if (!this._weekdaysParse) {
  1877. this._weekdaysParse = [];
  1878. }
  1879. for (i = 0; i < 7; i++) {
  1880. // make the regex if we don't have it already
  1881. if (!this._weekdaysParse[i]) {
  1882. mom = local__createLocal([2000, 1]).day(i);
  1883. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  1884. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1885. }
  1886. // test the regex
  1887. if (this._weekdaysParse[i].test(weekdayName)) {
  1888. return i;
  1889. }
  1890. }
  1891. }
  1892. // MOMENTS
  1893. function getSetDayOfWeek (input) {
  1894. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1895. if (input != null) {
  1896. input = parseWeekday(input, this.localeData());
  1897. return this.add(input - day, 'd');
  1898. } else {
  1899. return day;
  1900. }
  1901. }
  1902. function getSetLocaleDayOfWeek (input) {
  1903. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  1904. return input == null ? weekday : this.add(input - weekday, 'd');
  1905. }
  1906. function getSetISODayOfWeek (input) {
  1907. // behaves the same as moment#day except
  1908. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  1909. // as a setter, sunday should belong to the previous week.
  1910. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  1911. }
  1912. addFormatToken('H', ['HH', 2], 0, 'hour');
  1913. addFormatToken('h', ['hh', 2], 0, function () {
  1914. return this.hours() % 12 || 12;
  1915. });
  1916. function meridiem (token, lowercase) {
  1917. addFormatToken(token, 0, 0, function () {
  1918. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  1919. });
  1920. }
  1921. meridiem('a', true);
  1922. meridiem('A', false);
  1923. // ALIASES
  1924. addUnitAlias('hour', 'h');
  1925. // PARSING
  1926. function matchMeridiem (isStrict, locale) {
  1927. return locale._meridiemParse;
  1928. }
  1929. addRegexToken('a', matchMeridiem);
  1930. addRegexToken('A', matchMeridiem);
  1931. addRegexToken('H', match1to2);
  1932. addRegexToken('h', match1to2);
  1933. addRegexToken('HH', match1to2, match2);
  1934. addRegexToken('hh', match1to2, match2);
  1935. addParseToken(['H', 'HH'], HOUR);
  1936. addParseToken(['a', 'A'], function (input, array, config) {
  1937. config._isPm = config._locale.isPM(input);
  1938. config._meridiem = input;
  1939. });
  1940. addParseToken(['h', 'hh'], function (input, array, config) {
  1941. array[HOUR] = toInt(input);
  1942. getParsingFlags(config).bigHour = true;
  1943. });
  1944. // LOCALES
  1945. function localeIsPM (input) {
  1946. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  1947. // Using charAt should be more compatible.
  1948. return ((input + '').toLowerCase().charAt(0) === 'p');
  1949. }
  1950. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  1951. function localeMeridiem (hours, minutes, isLower) {
  1952. if (hours > 11) {
  1953. return isLower ? 'pm' : 'PM';
  1954. } else {
  1955. return isLower ? 'am' : 'AM';
  1956. }
  1957. }
  1958. // MOMENTS
  1959. // Setting the hour should keep the time, because the user explicitly
  1960. // specified which hour he wants. So trying to maintain the same hour (in
  1961. // a new timezone) makes sense. Adding/subtracting hours does not follow
  1962. // this rule.
  1963. var getSetHour = makeGetSet('Hours', true);
  1964. addFormatToken('m', ['mm', 2], 0, 'minute');
  1965. // ALIASES
  1966. addUnitAlias('minute', 'm');
  1967. // PARSING
  1968. addRegexToken('m', match1to2);
  1969. addRegexToken('mm', match1to2, match2);
  1970. addParseToken(['m', 'mm'], MINUTE);
  1971. // MOMENTS
  1972. var getSetMinute = makeGetSet('Minutes', false);
  1973. addFormatToken('s', ['ss', 2], 0, 'second');
  1974. // ALIASES
  1975. addUnitAlias('second', 's');
  1976. // PARSING
  1977. addRegexToken('s', match1to2);
  1978. addRegexToken('ss', match1to2, match2);
  1979. addParseToken(['s', 'ss'], SECOND);
  1980. // MOMENTS
  1981. var getSetSecond = makeGetSet('Seconds', false);
  1982. addFormatToken('S', 0, 0, function () {
  1983. return ~~(this.millisecond() / 100);
  1984. });
  1985. addFormatToken(0, ['SS', 2], 0, function () {
  1986. return ~~(this.millisecond() / 10);
  1987. });
  1988. function millisecond__milliseconds (token) {
  1989. addFormatToken(0, [token, 3], 0, 'millisecond');
  1990. }
  1991. millisecond__milliseconds('SSS');
  1992. millisecond__milliseconds('SSSS');
  1993. // ALIASES
  1994. addUnitAlias('millisecond', 'ms');
  1995. // PARSING
  1996. addRegexToken('S', match1to3, match1);
  1997. addRegexToken('SS', match1to3, match2);
  1998. addRegexToken('SSS', match1to3, match3);
  1999. addRegexToken('SSSS', matchUnsigned);
  2000. addParseToken(['S', 'SS', 'SSS', 'SSSS'], function (input, array) {
  2001. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  2002. });
  2003. // MOMENTS
  2004. var getSetMillisecond = makeGetSet('Milliseconds', false);
  2005. addFormatToken('z', 0, 0, 'zoneAbbr');
  2006. addFormatToken('zz', 0, 0, 'zoneName');
  2007. // MOMENTS
  2008. function getZoneAbbr () {
  2009. return this._isUTC ? 'UTC' : '';
  2010. }
  2011. function getZoneName () {
  2012. return this._isUTC ? 'Coordinated Universal Time' : '';
  2013. }
  2014. var momentPrototype__proto = Moment.prototype;
  2015. momentPrototype__proto.add = add_subtract__add;
  2016. momentPrototype__proto.calendar = moment_calendar__calendar;
  2017. momentPrototype__proto.clone = clone;
  2018. momentPrototype__proto.diff = diff;
  2019. momentPrototype__proto.endOf = endOf;
  2020. momentPrototype__proto.format = format;
  2021. momentPrototype__proto.from = from;
  2022. momentPrototype__proto.fromNow = fromNow;
  2023. momentPrototype__proto.to = to;
  2024. momentPrototype__proto.toNow = toNow;
  2025. momentPrototype__proto.get = getSet;
  2026. momentPrototype__proto.invalidAt = invalidAt;
  2027. momentPrototype__proto.isAfter = isAfter;
  2028. momentPrototype__proto.isBefore = isBefore;
  2029. momentPrototype__proto.isBetween = isBetween;
  2030. momentPrototype__proto.isSame = isSame;
  2031. momentPrototype__proto.isValid = moment_valid__isValid;
  2032. momentPrototype__proto.lang = lang;
  2033. momentPrototype__proto.locale = locale;
  2034. momentPrototype__proto.localeData = localeData;
  2035. momentPrototype__proto.max = prototypeMax;
  2036. momentPrototype__proto.min = prototypeMin;
  2037. momentPrototype__proto.parsingFlags = parsingFlags;
  2038. momentPrototype__proto.set = getSet;
  2039. momentPrototype__proto.startOf = startOf;
  2040. momentPrototype__proto.subtract = add_subtract__subtract;
  2041. momentPrototype__proto.toArray = toArray;
  2042. momentPrototype__proto.toDate = toDate;
  2043. momentPrototype__proto.toISOString = moment_format__toISOString;
  2044. momentPrototype__proto.toJSON = moment_format__toISOString;
  2045. momentPrototype__proto.toString = toString;
  2046. momentPrototype__proto.unix = unix;
  2047. momentPrototype__proto.valueOf = to_type__valueOf;
  2048. // Year
  2049. momentPrototype__proto.year = getSetYear;
  2050. momentPrototype__proto.isLeapYear = getIsLeapYear;
  2051. // Week Year
  2052. momentPrototype__proto.weekYear = getSetWeekYear;
  2053. momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
  2054. // Quarter
  2055. momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
  2056. // Month
  2057. momentPrototype__proto.month = getSetMonth;
  2058. momentPrototype__proto.daysInMonth = getDaysInMonth;
  2059. // Week
  2060. momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
  2061. momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
  2062. momentPrototype__proto.weeksInYear = getWeeksInYear;
  2063. momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
  2064. // Day
  2065. momentPrototype__proto.date = getSetDayOfMonth;
  2066. momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
  2067. momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
  2068. momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
  2069. momentPrototype__proto.dayOfYear = getSetDayOfYear;
  2070. // Hour
  2071. momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
  2072. // Minute
  2073. momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
  2074. // Second
  2075. momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
  2076. // Millisecond
  2077. momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
  2078. // Offset
  2079. momentPrototype__proto.utcOffset = getSetOffset;
  2080. momentPrototype__proto.utc = setOffsetToUTC;
  2081. momentPrototype__proto.local = setOffsetToLocal;
  2082. momentPrototype__proto.parseZone = setOffsetToParsedOffset;
  2083. momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
  2084. momentPrototype__proto.isDST = isDaylightSavingTime;
  2085. momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
  2086. momentPrototype__proto.isLocal = isLocal;
  2087. momentPrototype__proto.isUtcOffset = isUtcOffset;
  2088. momentPrototype__proto.isUtc = isUtc;
  2089. momentPrototype__proto.isUTC = isUtc;
  2090. // Timezone
  2091. momentPrototype__proto.zoneAbbr = getZoneAbbr;
  2092. momentPrototype__proto.zoneName = getZoneName;
  2093. // Deprecations
  2094. momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  2095. momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  2096. momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  2097. momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
  2098. var momentPrototype = momentPrototype__proto;
  2099. function moment__createUnix (input) {
  2100. return local__createLocal(input * 1000);
  2101. }
  2102. function moment__createInZone () {
  2103. return local__createLocal.apply(null, arguments).parseZone();
  2104. }
  2105. var defaultCalendar = {
  2106. sameDay : '[Today at] LT',
  2107. nextDay : '[Tomorrow at] LT',
  2108. nextWeek : 'dddd [at] LT',
  2109. lastDay : '[Yesterday at] LT',
  2110. lastWeek : '[Last] dddd [at] LT',
  2111. sameElse : 'L'
  2112. };
  2113. function locale_calendar__calendar (key, mom, now) {
  2114. var output = this._calendar[key];
  2115. return typeof output === 'function' ? output.call(mom, now) : output;
  2116. }
  2117. var defaultLongDateFormat = {
  2118. LTS : 'h:mm:ss A',
  2119. LT : 'h:mm A',
  2120. L : 'MM/DD/YYYY',
  2121. LL : 'MMMM D, YYYY',
  2122. LLL : 'MMMM D, YYYY LT',
  2123. LLLL : 'dddd, MMMM D, YYYY LT'
  2124. };
  2125. function longDateFormat (key) {
  2126. var output = this._longDateFormat[key];
  2127. if (!output && this._longDateFormat[key.toUpperCase()]) {
  2128. output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
  2129. return val.slice(1);
  2130. });
  2131. this._longDateFormat[key] = output;
  2132. }
  2133. return output;
  2134. }
  2135. var defaultInvalidDate = 'Invalid date';
  2136. function invalidDate () {
  2137. return this._invalidDate;
  2138. }
  2139. var defaultOrdinal = '%d';
  2140. var defaultOrdinalParse = /\d{1,2}/;
  2141. function ordinal (number) {
  2142. return this._ordinal.replace('%d', number);
  2143. }
  2144. function preParsePostFormat (string) {
  2145. return string;
  2146. }
  2147. var defaultRelativeTime = {
  2148. future : 'in %s',
  2149. past : '%s ago',
  2150. s : 'a few seconds',
  2151. m : 'a minute',
  2152. mm : '%d minutes',
  2153. h : 'an hour',
  2154. hh : '%d hours',
  2155. d : 'a day',
  2156. dd : '%d days',
  2157. M : 'a month',
  2158. MM : '%d months',
  2159. y : 'a year',
  2160. yy : '%d years'
  2161. };
  2162. function relative__relativeTime (number, withoutSuffix, string, isFuture) {
  2163. var output = this._relativeTime[string];
  2164. return (typeof output === 'function') ?
  2165. output(number, withoutSuffix, string, isFuture) :
  2166. output.replace(/%d/i, number);
  2167. }
  2168. function pastFuture (diff, output) {
  2169. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  2170. return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
  2171. }
  2172. function locale_set__set (config) {
  2173. var prop, i;
  2174. for (i in config) {
  2175. prop = config[i];
  2176. if (typeof prop === 'function') {
  2177. this[i] = prop;
  2178. } else {
  2179. this['_' + i] = prop;
  2180. }
  2181. }
  2182. // Lenient ordinal parsing accepts just a number in addition to
  2183. // number + (possibly) stuff coming from _ordinalParseLenient.
  2184. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  2185. }
  2186. var prototype__proto = Locale.prototype;
  2187. prototype__proto._calendar = defaultCalendar;
  2188. prototype__proto.calendar = locale_calendar__calendar;
  2189. prototype__proto._longDateFormat = defaultLongDateFormat;
  2190. prototype__proto.longDateFormat = longDateFormat;
  2191. prototype__proto._invalidDate = defaultInvalidDate;
  2192. prototype__proto.invalidDate = invalidDate;
  2193. prototype__proto._ordinal = defaultOrdinal;
  2194. prototype__proto.ordinal = ordinal;
  2195. prototype__proto._ordinalParse = defaultOrdinalParse;
  2196. prototype__proto.preparse = preParsePostFormat;
  2197. prototype__proto.postformat = preParsePostFormat;
  2198. prototype__proto._relativeTime = defaultRelativeTime;
  2199. prototype__proto.relativeTime = relative__relativeTime;
  2200. prototype__proto.pastFuture = pastFuture;
  2201. prototype__proto.set = locale_set__set;
  2202. // Month
  2203. prototype__proto.months = localeMonths;
  2204. prototype__proto._months = defaultLocaleMonths;
  2205. prototype__proto.monthsShort = localeMonthsShort;
  2206. prototype__proto._monthsShort = defaultLocaleMonthsShort;
  2207. prototype__proto.monthsParse = localeMonthsParse;
  2208. // Week
  2209. prototype__proto.week = localeWeek;
  2210. prototype__proto._week = defaultLocaleWeek;
  2211. prototype__proto.firstDayOfYear = localeFirstDayOfYear;
  2212. prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
  2213. // Day of Week
  2214. prototype__proto.weekdays = localeWeekdays;
  2215. prototype__proto._weekdays = defaultLocaleWeekdays;
  2216. prototype__proto.weekdaysMin = localeWeekdaysMin;
  2217. prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
  2218. prototype__proto.weekdaysShort = localeWeekdaysShort;
  2219. prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
  2220. prototype__proto.weekdaysParse = localeWeekdaysParse;
  2221. // Hours
  2222. prototype__proto.isPM = localeIsPM;
  2223. prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
  2224. prototype__proto.meridiem = localeMeridiem;
  2225. function lists__get (format, index, field, setter) {
  2226. var locale = locale_locales__getLocale();
  2227. var utc = create_utc__createUTC().set(setter, index);
  2228. return locale[field](utc, format);
  2229. }
  2230. function list (format, index, field, count, setter) {
  2231. if (typeof format === 'number') {
  2232. index = format;
  2233. format = undefined;
  2234. }
  2235. format = format || '';
  2236. if (index != null) {
  2237. return lists__get(format, index, field, setter);
  2238. }
  2239. var i;
  2240. var out = [];
  2241. for (i = 0; i < count; i++) {
  2242. out[i] = lists__get(format, i, field, setter);
  2243. }
  2244. return out;
  2245. }
  2246. function lists__listMonths (format, index) {
  2247. return list(format, index, 'months', 12, 'month');
  2248. }
  2249. function lists__listMonthsShort (format, index) {
  2250. return list(format, index, 'monthsShort', 12, 'month');
  2251. }
  2252. function lists__listWeekdays (format, index) {
  2253. return list(format, index, 'weekdays', 7, 'day');
  2254. }
  2255. function lists__listWeekdaysShort (format, index) {
  2256. return list(format, index, 'weekdaysShort', 7, 'day');
  2257. }
  2258. function lists__listWeekdaysMin (format, index) {
  2259. return list(format, index, 'weekdaysMin', 7, 'day');
  2260. }
  2261. locale_locales__getSetGlobalLocale('en', {
  2262. ordinalParse: /\d{1,2}(th|st|nd|rd)/,
  2263. ordinal : function (number) {
  2264. var b = number % 10,
  2265. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  2266. (b === 1) ? 'st' :
  2267. (b === 2) ? 'nd' :
  2268. (b === 3) ? 'rd' : 'th';
  2269. return number + output;
  2270. }
  2271. });
  2272. // Side effect imports
  2273. utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
  2274. utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
  2275. var mathAbs = Math.abs;
  2276. function duration_abs__abs () {
  2277. var data = this._data;
  2278. this._milliseconds = mathAbs(this._milliseconds);
  2279. this._days = mathAbs(this._days);
  2280. this._months = mathAbs(this._months);
  2281. data.milliseconds = mathAbs(data.milliseconds);
  2282. data.seconds = mathAbs(data.seconds);
  2283. data.minutes = mathAbs(data.minutes);
  2284. data.hours = mathAbs(data.hours);
  2285. data.months = mathAbs(data.months);
  2286. data.years = mathAbs(data.years);
  2287. return this;
  2288. }
  2289. function duration_add_subtract__addSubtract (duration, input, value, direction) {
  2290. var other = create__createDuration(input, value);
  2291. duration._milliseconds += direction * other._milliseconds;
  2292. duration._days += direction * other._days;
  2293. duration._months += direction * other._months;
  2294. return duration._bubble();
  2295. }
  2296. // supports only 2.0-style add(1, 's') or add(duration)
  2297. function duration_add_subtract__add (input, value) {
  2298. return duration_add_subtract__addSubtract(this, input, value, 1);
  2299. }
  2300. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  2301. function duration_add_subtract__subtract (input, value) {
  2302. return duration_add_subtract__addSubtract(this, input, value, -1);
  2303. }
  2304. function bubble () {
  2305. var milliseconds = this._milliseconds;
  2306. var days = this._days;
  2307. var months = this._months;
  2308. var data = this._data;
  2309. var seconds, minutes, hours, years = 0;
  2310. // The following code bubbles up values, see the tests for
  2311. // examples of what that means.
  2312. data.milliseconds = milliseconds % 1000;
  2313. seconds = absFloor(milliseconds / 1000);
  2314. data.seconds = seconds % 60;
  2315. minutes = absFloor(seconds / 60);
  2316. data.minutes = minutes % 60;
  2317. hours = absFloor(minutes / 60);
  2318. data.hours = hours % 24;
  2319. days += absFloor(hours / 24);
  2320. // Accurately convert days to years, assume start from year 0.
  2321. years = absFloor(daysToYears(days));
  2322. days -= absFloor(yearsToDays(years));
  2323. // 30 days to a month
  2324. // TODO (iskren): Use anchor date (like 1st Jan) to compute this.
  2325. months += absFloor(days / 30);
  2326. days %= 30;
  2327. // 12 months -> 1 year
  2328. years += absFloor(months / 12);
  2329. months %= 12;
  2330. data.days = days;
  2331. data.months = months;
  2332. data.years = years;
  2333. return this;
  2334. }
  2335. function daysToYears (days) {
  2336. // 400 years have 146097 days (taking into account leap year rules)
  2337. return days * 400 / 146097;
  2338. }
  2339. function yearsToDays (years) {
  2340. // years * 365 + absFloor(years / 4) -
  2341. // absFloor(years / 100) + absFloor(years / 400);
  2342. return years * 146097 / 400;
  2343. }
  2344. function as (units) {
  2345. var days;
  2346. var months;
  2347. var milliseconds = this._milliseconds;
  2348. units = normalizeUnits(units);
  2349. if (units === 'month' || units === 'year') {
  2350. days = this._days + milliseconds / 864e5;
  2351. months = this._months + daysToYears(days) * 12;
  2352. return units === 'month' ? months : months / 12;
  2353. } else {
  2354. // handle milliseconds separately because of floating point math errors (issue #1867)
  2355. days = this._days + Math.round(yearsToDays(this._months / 12));
  2356. switch (units) {
  2357. case 'week' : return days / 7 + milliseconds / 6048e5;
  2358. case 'day' : return days + milliseconds / 864e5;
  2359. case 'hour' : return days * 24 + milliseconds / 36e5;
  2360. case 'minute' : return days * 1440 + milliseconds / 6e4;
  2361. case 'second' : return days * 86400 + milliseconds / 1000;
  2362. // Math.floor prevents floating point math errors here
  2363. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  2364. default: throw new Error('Unknown unit ' + units);
  2365. }
  2366. }
  2367. }
  2368. // TODO: Use this.as('ms')?
  2369. function duration_as__valueOf () {
  2370. return (
  2371. this._milliseconds +
  2372. this._days * 864e5 +
  2373. (this._months % 12) * 2592e6 +
  2374. toInt(this._months / 12) * 31536e6
  2375. );
  2376. }
  2377. function makeAs (alias) {
  2378. return function () {
  2379. return this.as(alias);
  2380. };
  2381. }
  2382. var asMilliseconds = makeAs('ms');
  2383. var asSeconds = makeAs('s');
  2384. var asMinutes = makeAs('m');
  2385. var asHours = makeAs('h');
  2386. var asDays = makeAs('d');
  2387. var asWeeks = makeAs('w');
  2388. var asMonths = makeAs('M');
  2389. var asYears = makeAs('y');
  2390. function duration_get__get (units) {
  2391. units = normalizeUnits(units);
  2392. return this[units + 's']();
  2393. }
  2394. function makeGetter(name) {
  2395. return function () {
  2396. return this._data[name];
  2397. };
  2398. }
  2399. var duration_get__milliseconds = makeGetter('milliseconds');
  2400. var seconds = makeGetter('seconds');
  2401. var minutes = makeGetter('minutes');
  2402. var hours = makeGetter('hours');
  2403. var days = makeGetter('days');
  2404. var months = makeGetter('months');
  2405. var years = makeGetter('years');
  2406. function weeks () {
  2407. return absFloor(this.days() / 7);
  2408. }
  2409. var round = Math.round;
  2410. var thresholds = {
  2411. s: 45, // seconds to minute
  2412. m: 45, // minutes to hour
  2413. h: 22, // hours to day
  2414. d: 26, // days to month
  2415. M: 11 // months to year
  2416. };
  2417. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  2418. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  2419. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  2420. }
  2421. function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
  2422. var duration = create__createDuration(posNegDuration).abs();
  2423. var seconds = round(duration.as('s'));
  2424. var minutes = round(duration.as('m'));
  2425. var hours = round(duration.as('h'));
  2426. var days = round(duration.as('d'));
  2427. var months = round(duration.as('M'));
  2428. var years = round(duration.as('y'));
  2429. var a = seconds < thresholds.s && ['s', seconds] ||
  2430. minutes === 1 && ['m'] ||
  2431. minutes < thresholds.m && ['mm', minutes] ||
  2432. hours === 1 && ['h'] ||
  2433. hours < thresholds.h && ['hh', hours] ||
  2434. days === 1 && ['d'] ||
  2435. days < thresholds.d && ['dd', days] ||
  2436. months === 1 && ['M'] ||
  2437. months < thresholds.M && ['MM', months] ||
  2438. years === 1 && ['y'] || ['yy', years];
  2439. a[2] = withoutSuffix;
  2440. a[3] = +posNegDuration > 0;
  2441. a[4] = locale;
  2442. return substituteTimeAgo.apply(null, a);
  2443. }
  2444. // This function allows you to set a threshold for relative time strings
  2445. function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
  2446. if (thresholds[threshold] === undefined) {
  2447. return false;
  2448. }
  2449. if (limit === undefined) {
  2450. return thresholds[threshold];
  2451. }
  2452. thresholds[threshold] = limit;
  2453. return true;
  2454. }
  2455. function humanize (withSuffix) {
  2456. var locale = this.localeData();
  2457. var output = duration_humanize__relativeTime(this, !withSuffix, locale);
  2458. if (withSuffix) {
  2459. output = locale.pastFuture(+this, output);
  2460. }
  2461. return locale.postformat(output);
  2462. }
  2463. var iso_string__abs = Math.abs;
  2464. function iso_string__toISOString() {
  2465. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  2466. var Y = iso_string__abs(this.years());
  2467. var M = iso_string__abs(this.months());
  2468. var D = iso_string__abs(this.days());
  2469. var h = iso_string__abs(this.hours());
  2470. var m = iso_string__abs(this.minutes());
  2471. var s = iso_string__abs(this.seconds() + this.milliseconds() / 1000);
  2472. var total = this.asSeconds();
  2473. if (!total) {
  2474. // this is the same as C#'s (Noda) and python (isodate)...
  2475. // but not other JS (goog.date)
  2476. return 'P0D';
  2477. }
  2478. return (total < 0 ? '-' : '') +
  2479. 'P' +
  2480. (Y ? Y + 'Y' : '') +
  2481. (M ? M + 'M' : '') +
  2482. (D ? D + 'D' : '') +
  2483. ((h || m || s) ? 'T' : '') +
  2484. (h ? h + 'H' : '') +
  2485. (m ? m + 'M' : '') +
  2486. (s ? s + 'S' : '');
  2487. }
  2488. var duration_prototype__proto = Duration.prototype;
  2489. duration_prototype__proto.abs = duration_abs__abs;
  2490. duration_prototype__proto.add = duration_add_subtract__add;
  2491. duration_prototype__proto.subtract = duration_add_subtract__subtract;
  2492. duration_prototype__proto.as = as;
  2493. duration_prototype__proto.asMilliseconds = asMilliseconds;
  2494. duration_prototype__proto.asSeconds = asSeconds;
  2495. duration_prototype__proto.asMinutes = asMinutes;
  2496. duration_prototype__proto.asHours = asHours;
  2497. duration_prototype__proto.asDays = asDays;
  2498. duration_prototype__proto.asWeeks = asWeeks;
  2499. duration_prototype__proto.asMonths = asMonths;
  2500. duration_prototype__proto.asYears = asYears;
  2501. duration_prototype__proto.valueOf = duration_as__valueOf;
  2502. duration_prototype__proto._bubble = bubble;
  2503. duration_prototype__proto.get = duration_get__get;
  2504. duration_prototype__proto.milliseconds = duration_get__milliseconds;
  2505. duration_prototype__proto.seconds = seconds;
  2506. duration_prototype__proto.minutes = minutes;
  2507. duration_prototype__proto.hours = hours;
  2508. duration_prototype__proto.days = days;
  2509. duration_prototype__proto.weeks = weeks;
  2510. duration_prototype__proto.months = months;
  2511. duration_prototype__proto.years = years;
  2512. duration_prototype__proto.humanize = humanize;
  2513. duration_prototype__proto.toISOString = iso_string__toISOString;
  2514. duration_prototype__proto.toString = iso_string__toISOString;
  2515. duration_prototype__proto.toJSON = iso_string__toISOString;
  2516. duration_prototype__proto.locale = locale;
  2517. duration_prototype__proto.localeData = localeData;
  2518. // Deprecations
  2519. duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
  2520. duration_prototype__proto.lang = lang;
  2521. // Side effect imports
  2522. addFormatToken('X', 0, 0, 'unix');
  2523. addFormatToken('x', 0, 0, 'valueOf');
  2524. // PARSING
  2525. addRegexToken('x', matchSigned);
  2526. addRegexToken('X', matchTimestamp);
  2527. addParseToken('X', function (input, array, config) {
  2528. config._d = new Date(parseFloat(input, 10) * 1000);
  2529. });
  2530. addParseToken('x', function (input, array, config) {
  2531. config._d = new Date(toInt(input));
  2532. });
  2533. // Side effect imports
  2534. utils_hooks__hooks.version = '2.10.3';
  2535. setHookCallback(local__createLocal);
  2536. utils_hooks__hooks.fn = momentPrototype;
  2537. utils_hooks__hooks.min = min;
  2538. utils_hooks__hooks.max = max;
  2539. utils_hooks__hooks.utc = create_utc__createUTC;
  2540. utils_hooks__hooks.unix = moment__createUnix;
  2541. utils_hooks__hooks.months = lists__listMonths;
  2542. utils_hooks__hooks.isDate = isDate;
  2543. utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
  2544. utils_hooks__hooks.invalid = valid__createInvalid;
  2545. utils_hooks__hooks.duration = create__createDuration;
  2546. utils_hooks__hooks.isMoment = isMoment;
  2547. utils_hooks__hooks.weekdays = lists__listWeekdays;
  2548. utils_hooks__hooks.parseZone = moment__createInZone;
  2549. utils_hooks__hooks.localeData = locale_locales__getLocale;
  2550. utils_hooks__hooks.isDuration = isDuration;
  2551. utils_hooks__hooks.monthsShort = lists__listMonthsShort;
  2552. utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
  2553. utils_hooks__hooks.defineLocale = defineLocale;
  2554. utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
  2555. utils_hooks__hooks.normalizeUnits = normalizeUnits;
  2556. utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
  2557. var _moment = utils_hooks__hooks;
  2558. return _moment;
  2559. }));