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.

3082 lines
101 KiB

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