PageRenderTime 72ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/plugins/daterangepicker/moment.js

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