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

2489 lines
79 KiB

  1. //! moment.js
  2. //! version : 2.6.0
  3. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  4. //! license : MIT
  5. //! momentjs.com
  6. (function (undefined) {
  7. /************************************
  8. Constants
  9. ************************************/
  10. var moment,
  11. VERSION = "2.6.0",
  12. // the global-scope this is NOT the global object in Node.js
  13. globalScope = typeof global !== 'undefined' ? global : this,
  14. oldGlobalMoment,
  15. round = Math.round,
  16. i,
  17. YEAR = 0,
  18. MONTH = 1,
  19. DATE = 2,
  20. HOUR = 3,
  21. MINUTE = 4,
  22. SECOND = 5,
  23. MILLISECOND = 6,
  24. // internal storage for language config files
  25. languages = {},
  26. // moment internal properties
  27. momentProperties = {
  28. _isAMomentObject: null,
  29. _i : null,
  30. _f : null,
  31. _l : null,
  32. _strict : null,
  33. _isUTC : null,
  34. _offset : null, // optional. Combine with _isUTC
  35. _pf : null,
  36. _lang : null // optional
  37. },
  38. // check for nodeJS
  39. hasModule = (typeof module !== 'undefined' && module.exports),
  40. // ASP.NET json date format regex
  41. aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
  42. aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
  43. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  44. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  45. isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
  46. // format tokens
  47. 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|zz?|ZZ?|.)/g,
  48. localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
  49. // parsing token regexes
  50. parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
  51. parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
  52. parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
  53. parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
  54. parseTokenDigits = /\d+/, // nonzero number of digits
  55. parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic.
  56. parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
  57. parseTokenT = /T/i, // T (ISO separator)
  58. parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
  59. parseTokenOrdinal = /\d{1,2}/,
  60. //strict parsing regexes
  61. parseTokenOneDigit = /\d/, // 0 - 9
  62. parseTokenTwoDigits = /\d\d/, // 00 - 99
  63. parseTokenThreeDigits = /\d{3}/, // 000 - 999
  64. parseTokenFourDigits = /\d{4}/, // 0000 - 9999
  65. parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
  66. parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
  67. // iso 8601 regex
  68. // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  69. 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)?)?$/,
  70. isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
  71. isoDates = [
  72. ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
  73. ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
  74. ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
  75. ['GGGG-[W]WW', /\d{4}-W\d{2}/],
  76. ['YYYY-DDD', /\d{4}-\d{3}/]
  77. ],
  78. // iso time formats and regexes
  79. isoTimes = [
  80. ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
  81. ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
  82. ['HH:mm', /(T| )\d\d:\d\d/],
  83. ['HH', /(T| )\d\d/]
  84. ],
  85. // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
  86. parseTimezoneChunker = /([\+\-]|\d\d)/gi,
  87. // getter and setter names
  88. proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
  89. unitMillisecondFactors = {
  90. 'Milliseconds' : 1,
  91. 'Seconds' : 1e3,
  92. 'Minutes' : 6e4,
  93. 'Hours' : 36e5,
  94. 'Days' : 864e5,
  95. 'Months' : 2592e6,
  96. 'Years' : 31536e6
  97. },
  98. unitAliases = {
  99. ms : 'millisecond',
  100. s : 'second',
  101. m : 'minute',
  102. h : 'hour',
  103. d : 'day',
  104. D : 'date',
  105. w : 'week',
  106. W : 'isoWeek',
  107. M : 'month',
  108. Q : 'quarter',
  109. y : 'year',
  110. DDD : 'dayOfYear',
  111. e : 'weekday',
  112. E : 'isoWeekday',
  113. gg: 'weekYear',
  114. GG: 'isoWeekYear'
  115. },
  116. camelFunctions = {
  117. dayofyear : 'dayOfYear',
  118. isoweekday : 'isoWeekday',
  119. isoweek : 'isoWeek',
  120. weekyear : 'weekYear',
  121. isoweekyear : 'isoWeekYear'
  122. },
  123. // format function strings
  124. formatFunctions = {},
  125. // tokens to ordinalize and pad
  126. ordinalizeTokens = 'DDD w W M D d'.split(' '),
  127. paddedTokens = 'M D H h m s w W'.split(' '),
  128. formatTokenFunctions = {
  129. M : function () {
  130. return this.month() + 1;
  131. },
  132. MMM : function (format) {
  133. return this.lang().monthsShort(this, format);
  134. },
  135. MMMM : function (format) {
  136. return this.lang().months(this, format);
  137. },
  138. D : function () {
  139. return this.date();
  140. },
  141. DDD : function () {
  142. return this.dayOfYear();
  143. },
  144. d : function () {
  145. return this.day();
  146. },
  147. dd : function (format) {
  148. return this.lang().weekdaysMin(this, format);
  149. },
  150. ddd : function (format) {
  151. return this.lang().weekdaysShort(this, format);
  152. },
  153. dddd : function (format) {
  154. return this.lang().weekdays(this, format);
  155. },
  156. w : function () {
  157. return this.week();
  158. },
  159. W : function () {
  160. return this.isoWeek();
  161. },
  162. YY : function () {
  163. return leftZeroFill(this.year() % 100, 2);
  164. },
  165. YYYY : function () {
  166. return leftZeroFill(this.year(), 4);
  167. },
  168. YYYYY : function () {
  169. return leftZeroFill(this.year(), 5);
  170. },
  171. YYYYYY : function () {
  172. var y = this.year(), sign = y >= 0 ? '+' : '-';
  173. return sign + leftZeroFill(Math.abs(y), 6);
  174. },
  175. gg : function () {
  176. return leftZeroFill(this.weekYear() % 100, 2);
  177. },
  178. gggg : function () {
  179. return leftZeroFill(this.weekYear(), 4);
  180. },
  181. ggggg : function () {
  182. return leftZeroFill(this.weekYear(), 5);
  183. },
  184. GG : function () {
  185. return leftZeroFill(this.isoWeekYear() % 100, 2);
  186. },
  187. GGGG : function () {
  188. return leftZeroFill(this.isoWeekYear(), 4);
  189. },
  190. GGGGG : function () {
  191. return leftZeroFill(this.isoWeekYear(), 5);
  192. },
  193. e : function () {
  194. return this.weekday();
  195. },
  196. E : function () {
  197. return this.isoWeekday();
  198. },
  199. a : function () {
  200. return this.lang().meridiem(this.hours(), this.minutes(), true);
  201. },
  202. A : function () {
  203. return this.lang().meridiem(this.hours(), this.minutes(), false);
  204. },
  205. H : function () {
  206. return this.hours();
  207. },
  208. h : function () {
  209. return this.hours() % 12 || 12;
  210. },
  211. m : function () {
  212. return this.minutes();
  213. },
  214. s : function () {
  215. return this.seconds();
  216. },
  217. S : function () {
  218. return toInt(this.milliseconds() / 100);
  219. },
  220. SS : function () {
  221. return leftZeroFill(toInt(this.milliseconds() / 10), 2);
  222. },
  223. SSS : function () {
  224. return leftZeroFill(this.milliseconds(), 3);
  225. },
  226. SSSS : function () {
  227. return leftZeroFill(this.milliseconds(), 3);
  228. },
  229. Z : function () {
  230. var a = -this.zone(),
  231. b = "+";
  232. if (a < 0) {
  233. a = -a;
  234. b = "-";
  235. }
  236. return b + leftZeroFill(toInt(a / 60), 2) + ":" + leftZeroFill(toInt(a) % 60, 2);
  237. },
  238. ZZ : function () {
  239. var a = -this.zone(),
  240. b = "+";
  241. if (a < 0) {
  242. a = -a;
  243. b = "-";
  244. }
  245. return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
  246. },
  247. z : function () {
  248. return this.zoneAbbr();
  249. },
  250. zz : function () {
  251. return this.zoneName();
  252. },
  253. X : function () {
  254. return this.unix();
  255. },
  256. Q : function () {
  257. return this.quarter();
  258. }
  259. },
  260. lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
  261. function defaultParsingFlags() {
  262. // We need to deep clone this object, and es5 standard is not very
  263. // helpful.
  264. return {
  265. empty : false,
  266. unusedTokens : [],
  267. unusedInput : [],
  268. overflow : -2,
  269. charsLeftOver : 0,
  270. nullInput : false,
  271. invalidMonth : null,
  272. invalidFormat : false,
  273. userInvalidated : false,
  274. iso: false
  275. };
  276. }
  277. function deprecate(msg, fn) {
  278. var firstTime = true;
  279. function printMsg() {
  280. if (moment.suppressDeprecationWarnings === false &&
  281. typeof console !== 'undefined' && console.warn) {
  282. console.warn("Deprecation warning: " + msg);
  283. }
  284. }
  285. return extend(function () {
  286. if (firstTime) {
  287. printMsg();
  288. firstTime = false;
  289. }
  290. return fn.apply(this, arguments);
  291. }, fn);
  292. }
  293. function padToken(func, count) {
  294. return function (a) {
  295. return leftZeroFill(func.call(this, a), count);
  296. };
  297. }
  298. function ordinalizeToken(func, period) {
  299. return function (a) {
  300. return this.lang().ordinal(func.call(this, a), period);
  301. };
  302. }
  303. while (ordinalizeTokens.length) {
  304. i = ordinalizeTokens.pop();
  305. formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
  306. }
  307. while (paddedTokens.length) {
  308. i = paddedTokens.pop();
  309. formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
  310. }
  311. formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
  312. /************************************
  313. Constructors
  314. ************************************/
  315. function Language() {
  316. }
  317. // Moment prototype object
  318. function Moment(config) {
  319. checkOverflow(config);
  320. extend(this, config);
  321. }
  322. // Duration Constructor
  323. function Duration(duration) {
  324. var normalizedInput = normalizeObjectUnits(duration),
  325. years = normalizedInput.year || 0,
  326. quarters = normalizedInput.quarter || 0,
  327. months = normalizedInput.month || 0,
  328. weeks = normalizedInput.week || 0,
  329. days = normalizedInput.day || 0,
  330. hours = normalizedInput.hour || 0,
  331. minutes = normalizedInput.minute || 0,
  332. seconds = normalizedInput.second || 0,
  333. milliseconds = normalizedInput.millisecond || 0;
  334. // representation for dateAddRemove
  335. this._milliseconds = +milliseconds +
  336. seconds * 1e3 + // 1000
  337. minutes * 6e4 + // 1000 * 60
  338. hours * 36e5; // 1000 * 60 * 60
  339. // Because of dateAddRemove treats 24 hours as different from a
  340. // day when working around DST, we need to store them separately
  341. this._days = +days +
  342. weeks * 7;
  343. // It is impossible translate months into days without knowing
  344. // which months you are are talking about, so we have to store
  345. // it separately.
  346. this._months = +months +
  347. quarters * 3 +
  348. years * 12;
  349. this._data = {};
  350. this._bubble();
  351. }
  352. /************************************
  353. Helpers
  354. ************************************/
  355. function extend(a, b) {
  356. for (var i in b) {
  357. if (b.hasOwnProperty(i)) {
  358. a[i] = b[i];
  359. }
  360. }
  361. if (b.hasOwnProperty("toString")) {
  362. a.toString = b.toString;
  363. }
  364. if (b.hasOwnProperty("valueOf")) {
  365. a.valueOf = b.valueOf;
  366. }
  367. return a;
  368. }
  369. function cloneMoment(m) {
  370. var result = {}, i;
  371. for (i in m) {
  372. if (m.hasOwnProperty(i) && momentProperties.hasOwnProperty(i)) {
  373. result[i] = m[i];
  374. }
  375. }
  376. return result;
  377. }
  378. function absRound(number) {
  379. if (number < 0) {
  380. return Math.ceil(number);
  381. } else {
  382. return Math.floor(number);
  383. }
  384. }
  385. // left zero fill a number
  386. // see http://jsperf.com/left-zero-filling for performance comparison
  387. function leftZeroFill(number, targetLength, forceSign) {
  388. var output = '' + Math.abs(number),
  389. sign = number >= 0;
  390. while (output.length < targetLength) {
  391. output = '0' + output;
  392. }
  393. return (sign ? (forceSign ? '+' : '') : '-') + output;
  394. }
  395. // helper function for _.addTime and _.subtractTime
  396. function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {
  397. var milliseconds = duration._milliseconds,
  398. days = duration._days,
  399. months = duration._months;
  400. updateOffset = updateOffset == null ? true : updateOffset;
  401. if (milliseconds) {
  402. mom._d.setTime(+mom._d + milliseconds * isAdding);
  403. }
  404. if (days) {
  405. rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);
  406. }
  407. if (months) {
  408. rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);
  409. }
  410. if (updateOffset) {
  411. moment.updateOffset(mom, days || months);
  412. }
  413. }
  414. // check if is an array
  415. function isArray(input) {
  416. return Object.prototype.toString.call(input) === '[object Array]';
  417. }
  418. function isDate(input) {
  419. return Object.prototype.toString.call(input) === '[object Date]' ||
  420. input instanceof Date;
  421. }
  422. // compare two arrays, return the number of differences
  423. function compareArrays(array1, array2, dontConvert) {
  424. var len = Math.min(array1.length, array2.length),
  425. lengthDiff = Math.abs(array1.length - array2.length),
  426. diffs = 0,
  427. i;
  428. for (i = 0; i < len; i++) {
  429. if ((dontConvert && array1[i] !== array2[i]) ||
  430. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  431. diffs++;
  432. }
  433. }
  434. return diffs + lengthDiff;
  435. }
  436. function normalizeUnits(units) {
  437. if (units) {
  438. var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
  439. units = unitAliases[units] || camelFunctions[lowered] || lowered;
  440. }
  441. return units;
  442. }
  443. function normalizeObjectUnits(inputObject) {
  444. var normalizedInput = {},
  445. normalizedProp,
  446. prop;
  447. for (prop in inputObject) {
  448. if (inputObject.hasOwnProperty(prop)) {
  449. normalizedProp = normalizeUnits(prop);
  450. if (normalizedProp) {
  451. normalizedInput[normalizedProp] = inputObject[prop];
  452. }
  453. }
  454. }
  455. return normalizedInput;
  456. }
  457. function makeList(field) {
  458. var count, setter;
  459. if (field.indexOf('week') === 0) {
  460. count = 7;
  461. setter = 'day';
  462. }
  463. else if (field.indexOf('month') === 0) {
  464. count = 12;
  465. setter = 'month';
  466. }
  467. else {
  468. return;
  469. }
  470. moment[field] = function (format, index) {
  471. var i, getter,
  472. method = moment.fn._lang[field],
  473. results = [];
  474. if (typeof format === 'number') {
  475. index = format;
  476. format = undefined;
  477. }
  478. getter = function (i) {
  479. var m = moment().utc().set(setter, i);
  480. return method.call(moment.fn._lang, m, format || '');
  481. };
  482. if (index != null) {
  483. return getter(index);
  484. }
  485. else {
  486. for (i = 0; i < count; i++) {
  487. results.push(getter(i));
  488. }
  489. return results;
  490. }
  491. };
  492. }
  493. function toInt(argumentForCoercion) {
  494. var coercedNumber = +argumentForCoercion,
  495. value = 0;
  496. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  497. if (coercedNumber >= 0) {
  498. value = Math.floor(coercedNumber);
  499. } else {
  500. value = Math.ceil(coercedNumber);
  501. }
  502. }
  503. return value;
  504. }
  505. function daysInMonth(year, month) {
  506. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  507. }
  508. function weeksInYear(year, dow, doy) {
  509. return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;
  510. }
  511. function daysInYear(year) {
  512. return isLeapYear(year) ? 366 : 365;
  513. }
  514. function isLeapYear(year) {
  515. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  516. }
  517. function checkOverflow(m) {
  518. var overflow;
  519. if (m._a && m._pf.overflow === -2) {
  520. overflow =
  521. m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
  522. m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
  523. m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
  524. m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
  525. m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
  526. m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
  527. -1;
  528. if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  529. overflow = DATE;
  530. }
  531. m._pf.overflow = overflow;
  532. }
  533. }
  534. function isValid(m) {
  535. if (m._isValid == null) {
  536. m._isValid = !isNaN(m._d.getTime()) &&
  537. m._pf.overflow < 0 &&
  538. !m._pf.empty &&
  539. !m._pf.invalidMonth &&
  540. !m._pf.nullInput &&
  541. !m._pf.invalidFormat &&
  542. !m._pf.userInvalidated;
  543. if (m._strict) {
  544. m._isValid = m._isValid &&
  545. m._pf.charsLeftOver === 0 &&
  546. m._pf.unusedTokens.length === 0;
  547. }
  548. }
  549. return m._isValid;
  550. }
  551. function normalizeLanguage(key) {
  552. return key ? key.toLowerCase().replace('_', '-') : key;
  553. }
  554. // Return a moment from input, that is local/utc/zone equivalent to model.
  555. function makeAs(input, model) {
  556. return model._isUTC ? moment(input).zone(model._offset || 0) :
  557. moment(input).local();
  558. }
  559. /************************************
  560. Languages
  561. ************************************/
  562. extend(Language.prototype, {
  563. set : function (config) {
  564. var prop, i;
  565. for (i in config) {
  566. prop = config[i];
  567. if (typeof prop === 'function') {
  568. this[i] = prop;
  569. } else {
  570. this['_' + i] = prop;
  571. }
  572. }
  573. },
  574. _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
  575. months : function (m) {
  576. return this._months[m.month()];
  577. },
  578. _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
  579. monthsShort : function (m) {
  580. return this._monthsShort[m.month()];
  581. },
  582. monthsParse : function (monthName) {
  583. var i, mom, regex;
  584. if (!this._monthsParse) {
  585. this._monthsParse = [];
  586. }
  587. for (i = 0; i < 12; i++) {
  588. // make the regex if we don't have it already
  589. if (!this._monthsParse[i]) {
  590. mom = moment.utc([2000, i]);
  591. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  592. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  593. }
  594. // test the regex
  595. if (this._monthsParse[i].test(monthName)) {
  596. return i;
  597. }
  598. }
  599. },
  600. _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  601. weekdays : function (m) {
  602. return this._weekdays[m.day()];
  603. },
  604. _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
  605. weekdaysShort : function (m) {
  606. return this._weekdaysShort[m.day()];
  607. },
  608. _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
  609. weekdaysMin : function (m) {
  610. return this._weekdaysMin[m.day()];
  611. },
  612. weekdaysParse : function (weekdayName) {
  613. var i, mom, regex;
  614. if (!this._weekdaysParse) {
  615. this._weekdaysParse = [];
  616. }
  617. for (i = 0; i < 7; i++) {
  618. // make the regex if we don't have it already
  619. if (!this._weekdaysParse[i]) {
  620. mom = moment([2000, 1]).day(i);
  621. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  622. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  623. }
  624. // test the regex
  625. if (this._weekdaysParse[i].test(weekdayName)) {
  626. return i;
  627. }
  628. }
  629. },
  630. _longDateFormat : {
  631. LT : "h:mm A",
  632. L : "MM/DD/YYYY",
  633. LL : "MMMM D YYYY",
  634. LLL : "MMMM D YYYY LT",
  635. LLLL : "dddd, MMMM D YYYY LT"
  636. },
  637. longDateFormat : function (key) {
  638. var output = this._longDateFormat[key];
  639. if (!output && this._longDateFormat[key.toUpperCase()]) {
  640. output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
  641. return val.slice(1);
  642. });
  643. this._longDateFormat[key] = output;
  644. }
  645. return output;
  646. },
  647. isPM : function (input) {
  648. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  649. // Using charAt should be more compatible.
  650. return ((input + '').toLowerCase().charAt(0) === 'p');
  651. },
  652. _meridiemParse : /[ap]\.?m?\.?/i,
  653. meridiem : function (hours, minutes, isLower) {
  654. if (hours > 11) {
  655. return isLower ? 'pm' : 'PM';
  656. } else {
  657. return isLower ? 'am' : 'AM';
  658. }
  659. },
  660. _calendar : {
  661. sameDay : '[Today at] LT',
  662. nextDay : '[Tomorrow at] LT',
  663. nextWeek : 'dddd [at] LT',
  664. lastDay : '[Yesterday at] LT',
  665. lastWeek : '[Last] dddd [at] LT',
  666. sameElse : 'L'
  667. },
  668. calendar : function (key, mom) {
  669. var output = this._calendar[key];
  670. return typeof output === 'function' ? output.apply(mom) : output;
  671. },
  672. _relativeTime : {
  673. future : "in %s",
  674. past : "%s ago",
  675. s : "a few seconds",
  676. m : "a minute",
  677. mm : "%d minutes",
  678. h : "an hour",
  679. hh : "%d hours",
  680. d : "a day",
  681. dd : "%d days",
  682. M : "a month",
  683. MM : "%d months",
  684. y : "a year",
  685. yy : "%d years"
  686. },
  687. relativeTime : function (number, withoutSuffix, string, isFuture) {
  688. var output = this._relativeTime[string];
  689. return (typeof output === 'function') ?
  690. output(number, withoutSuffix, string, isFuture) :
  691. output.replace(/%d/i, number);
  692. },
  693. pastFuture : function (diff, output) {
  694. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  695. return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
  696. },
  697. ordinal : function (number) {
  698. return this._ordinal.replace("%d", number);
  699. },
  700. _ordinal : "%d",
  701. preparse : function (string) {
  702. return string;
  703. },
  704. postformat : function (string) {
  705. return string;
  706. },
  707. week : function (mom) {
  708. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  709. },
  710. _week : {
  711. dow : 0, // Sunday is the first day of the week.
  712. doy : 6 // The week that contains Jan 1st is the first week of the year.
  713. },
  714. _invalidDate: 'Invalid date',
  715. invalidDate: function () {
  716. return this._invalidDate;
  717. }
  718. });
  719. // Loads a language definition into the `languages` cache. The function
  720. // takes a key and optionally values. If not in the browser and no values
  721. // are provided, it will load the language file module. As a convenience,
  722. // this function also returns the language values.
  723. function loadLang(key, values) {
  724. values.abbr = key;
  725. if (!languages[key]) {
  726. languages[key] = new Language();
  727. }
  728. languages[key].set(values);
  729. return languages[key];
  730. }
  731. // Remove a language from the `languages` cache. Mostly useful in tests.
  732. function unloadLang(key) {
  733. delete languages[key];
  734. }
  735. // Determines which language definition to use and returns it.
  736. //
  737. // With no parameters, it will return the global language. If you
  738. // pass in a language key, such as 'en', it will return the
  739. // definition for 'en', so long as 'en' has already been loaded using
  740. // moment.lang.
  741. function getLangDefinition(key) {
  742. var i = 0, j, lang, next, split,
  743. get = function (k) {
  744. if (!languages[k] && hasModule) {
  745. try {
  746. require('./lang/' + k);
  747. } catch (e) { }
  748. }
  749. return languages[k];
  750. };
  751. if (!key) {
  752. return moment.fn._lang;
  753. }
  754. if (!isArray(key)) {
  755. //short-circuit everything else
  756. lang = get(key);
  757. if (lang) {
  758. return lang;
  759. }
  760. key = [key];
  761. }
  762. //pick the language from the array
  763. //try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  764. //substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  765. while (i < key.length) {
  766. split = normalizeLanguage(key[i]).split('-');
  767. j = split.length;
  768. next = normalizeLanguage(key[i + 1]);
  769. next = next ? next.split('-') : null;
  770. while (j > 0) {
  771. lang = get(split.slice(0, j).join('-'));
  772. if (lang) {
  773. return lang;
  774. }
  775. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  776. //the next array item is better than a shallower substring of this one
  777. break;
  778. }
  779. j--;
  780. }
  781. i++;
  782. }
  783. return moment.fn._lang;
  784. }
  785. /************************************
  786. Formatting
  787. ************************************/
  788. function removeFormattingTokens(input) {
  789. if (input.match(/\[[\s\S]/)) {
  790. return input.replace(/^\[|\]$/g, "");
  791. }
  792. return input.replace(/\\/g, "");
  793. }
  794. function makeFormatFunction(format) {
  795. var array = format.match(formattingTokens), i, length;
  796. for (i = 0, length = array.length; i < length; i++) {
  797. if (formatTokenFunctions[array[i]]) {
  798. array[i] = formatTokenFunctions[array[i]];
  799. } else {
  800. array[i] = removeFormattingTokens(array[i]);
  801. }
  802. }
  803. return function (mom) {
  804. var output = "";
  805. for (i = 0; i < length; i++) {
  806. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  807. }
  808. return output;
  809. };
  810. }
  811. // format date using native date object
  812. function formatMoment(m, format) {
  813. if (!m.isValid()) {
  814. return m.lang().invalidDate();
  815. }
  816. format = expandFormat(format, m.lang());
  817. if (!formatFunctions[format]) {
  818. formatFunctions[format] = makeFormatFunction(format);
  819. }
  820. return formatFunctions[format](m);
  821. }
  822. function expandFormat(format, lang) {
  823. var i = 5;
  824. function replaceLongDateFormatTokens(input) {
  825. return lang.longDateFormat(input) || input;
  826. }
  827. localFormattingTokens.lastIndex = 0;
  828. while (i >= 0 && localFormattingTokens.test(format)) {
  829. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  830. localFormattingTokens.lastIndex = 0;
  831. i -= 1;
  832. }
  833. return format;
  834. }
  835. /************************************
  836. Parsing
  837. ************************************/
  838. // get the regex to find the next token
  839. function getParseRegexForToken(token, config) {
  840. var a, strict = config._strict;
  841. switch (token) {
  842. case 'Q':
  843. return parseTokenOneDigit;
  844. case 'DDDD':
  845. return parseTokenThreeDigits;
  846. case 'YYYY':
  847. case 'GGGG':
  848. case 'gggg':
  849. return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
  850. case 'Y':
  851. case 'G':
  852. case 'g':
  853. return parseTokenSignedNumber;
  854. case 'YYYYYY':
  855. case 'YYYYY':
  856. case 'GGGGG':
  857. case 'ggggg':
  858. return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
  859. case 'S':
  860. if (strict) { return parseTokenOneDigit; }
  861. /* falls through */
  862. case 'SS':
  863. if (strict) { return parseTokenTwoDigits; }
  864. /* falls through */
  865. case 'SSS':
  866. if (strict) { return parseTokenThreeDigits; }
  867. /* falls through */
  868. case 'DDD':
  869. return parseTokenOneToThreeDigits;
  870. case 'MMM':
  871. case 'MMMM':
  872. case 'dd':
  873. case 'ddd':
  874. case 'dddd':
  875. return parseTokenWord;
  876. case 'a':
  877. case 'A':
  878. return getLangDefinition(config._l)._meridiemParse;
  879. case 'X':
  880. return parseTokenTimestampMs;
  881. case 'Z':
  882. case 'ZZ':
  883. return parseTokenTimezone;
  884. case 'T':
  885. return parseTokenT;
  886. case 'SSSS':
  887. return parseTokenDigits;
  888. case 'MM':
  889. case 'DD':
  890. case 'YY':
  891. case 'GG':
  892. case 'gg':
  893. case 'HH':
  894. case 'hh':
  895. case 'mm':
  896. case 'ss':
  897. case 'ww':
  898. case 'WW':
  899. return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
  900. case 'M':
  901. case 'D':
  902. case 'd':
  903. case 'H':
  904. case 'h':
  905. case 'm':
  906. case 's':
  907. case 'w':
  908. case 'W':
  909. case 'e':
  910. case 'E':
  911. return parseTokenOneOrTwoDigits;
  912. case 'Do':
  913. return parseTokenOrdinal;
  914. default :
  915. a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
  916. return a;
  917. }
  918. }
  919. function timezoneMinutesFromString(string) {
  920. string = string || "";
  921. var possibleTzMatches = (string.match(parseTokenTimezone) || []),
  922. tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
  923. parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
  924. minutes = +(parts[1] * 60) + toInt(parts[2]);
  925. return parts[0] === '+' ? -minutes : minutes;
  926. }
  927. // function to convert string input to date
  928. function addTimeToArrayFromToken(token, input, config) {
  929. var a, datePartArray = config._a;
  930. switch (token) {
  931. // QUARTER
  932. case 'Q':
  933. if (input != null) {
  934. datePartArray[MONTH] = (toInt(input) - 1) * 3;
  935. }
  936. break;
  937. // MONTH
  938. case 'M' : // fall through to MM
  939. case 'MM' :
  940. if (input != null) {
  941. datePartArray[MONTH] = toInt(input) - 1;
  942. }
  943. break;
  944. case 'MMM' : // fall through to MMMM
  945. case 'MMMM' :
  946. a = getLangDefinition(config._l).monthsParse(input);
  947. // if we didn't find a month name, mark the date as invalid.
  948. if (a != null) {
  949. datePartArray[MONTH] = a;
  950. } else {
  951. config._pf.invalidMonth = input;
  952. }
  953. break;
  954. // DAY OF MONTH
  955. case 'D' : // fall through to DD
  956. case 'DD' :
  957. if (input != null) {
  958. datePartArray[DATE] = toInt(input);
  959. }
  960. break;
  961. case 'Do' :
  962. if (input != null) {
  963. datePartArray[DATE] = toInt(parseInt(input, 10));
  964. }
  965. break;
  966. // DAY OF YEAR
  967. case 'DDD' : // fall through to DDDD
  968. case 'DDDD' :
  969. if (input != null) {
  970. config._dayOfYear = toInt(input);
  971. }
  972. break;
  973. // YEAR
  974. case 'YY' :
  975. datePartArray[YEAR] = moment.parseTwoDigitYear(input);
  976. break;
  977. case 'YYYY' :
  978. case 'YYYYY' :
  979. case 'YYYYYY' :
  980. datePartArray[YEAR] = toInt(input);
  981. break;
  982. // AM / PM
  983. case 'a' : // fall through to A
  984. case 'A' :
  985. config._isPm = getLangDefinition(config._l).isPM(input);
  986. break;
  987. // 24 HOUR
  988. case 'H' : // fall through to hh
  989. case 'HH' : // fall through to hh
  990. case 'h' : // fall through to hh
  991. case 'hh' :
  992. datePartArray[HOUR] = toInt(input);
  993. break;
  994. // MINUTE
  995. case 'm' : // fall through to mm
  996. case 'mm' :
  997. datePartArray[MINUTE] = toInt(input);
  998. break;
  999. // SECOND
  1000. case 's' : // fall through to ss
  1001. case 'ss' :
  1002. datePartArray[SECOND] = toInt(input);
  1003. break;
  1004. // MILLISECOND
  1005. case 'S' :
  1006. case 'SS' :
  1007. case 'SSS' :
  1008. case 'SSSS' :
  1009. datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
  1010. break;
  1011. // UNIX TIMESTAMP WITH MS
  1012. case 'X':
  1013. config._d = new Date(parseFloat(input) * 1000);
  1014. break;
  1015. // TIMEZONE
  1016. case 'Z' : // fall through to ZZ
  1017. case 'ZZ' :
  1018. config._useUTC = true;
  1019. config._tzm = timezoneMinutesFromString(input);
  1020. break;
  1021. case 'w':
  1022. case 'ww':
  1023. case 'W':
  1024. case 'WW':
  1025. case 'd':
  1026. case 'dd':
  1027. case 'ddd':
  1028. case 'dddd':
  1029. case 'e':
  1030. case 'E':
  1031. token = token.substr(0, 1);
  1032. /* falls through */
  1033. case 'gg':
  1034. case 'gggg':
  1035. case 'GG':
  1036. case 'GGGG':
  1037. case 'GGGGG':
  1038. token = token.substr(0, 2);
  1039. if (input) {
  1040. config._w = config._w || {};
  1041. config._w[token] = input;
  1042. }
  1043. break;
  1044. }
  1045. }
  1046. // convert an array to a date.
  1047. // the array should mirror the parameters below
  1048. // note: all values past the year are optional and will default to the lowest possible value.
  1049. // [year, month, day , hour, minute, second, millisecond]
  1050. function dateFromConfig(config) {
  1051. var i, date, input = [], currentDate,
  1052. yearToUse, fixYear, w, temp, lang, weekday, week;
  1053. if (config._d) {
  1054. return;
  1055. }
  1056. currentDate = currentDateArray(config);
  1057. //compute day of the year from weeks and weekdays
  1058. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  1059. fixYear = function (val) {
  1060. var intVal = parseInt(val, 10);
  1061. return val ?
  1062. (val.length < 3 ? (intVal > 68 ? 1900 + intVal : 2000 + intVal) : intVal) :
  1063. (config._a[YEAR] == null ? moment().weekYear() : config._a[YEAR]);
  1064. };
  1065. w = config._w;
  1066. if (w.GG != null || w.W != null || w.E != null) {
  1067. temp = dayOfYearFromWeeks(fixYear(w.GG), w.W || 1, w.E, 4, 1);
  1068. }
  1069. else {
  1070. lang = getLangDefinition(config._l);
  1071. weekday = w.d != null ? parseWeekday(w.d, lang) :
  1072. (w.e != null ? parseInt(w.e, 10) + lang._week.dow : 0);
  1073. week = parseInt(w.w, 10) || 1;
  1074. //if we're parsing 'd', then the low day numbers may be next week
  1075. if (w.d != null && weekday < lang._week.dow) {
  1076. week++;
  1077. }
  1078. temp = dayOfYearFromWeeks(fixYear(w.gg), week, weekday, lang._week.doy, lang._week.dow);
  1079. }
  1080. config._a[YEAR] = temp.year;
  1081. config._dayOfYear = temp.dayOfYear;
  1082. }
  1083. //if the day of the year is set, figure out what it is
  1084. if (config._dayOfYear) {
  1085. yearToUse = config._a[YEAR] == null ? currentDate[YEAR] : config._a[YEAR];
  1086. if (config._dayOfYear > daysInYear(yearToUse)) {
  1087. config._pf._overflowDayOfYear = true;
  1088. }
  1089. date = makeUTCDate(yearToUse, 0, config._dayOfYear);
  1090. config._a[MONTH] = date.getUTCMonth();
  1091. config._a[DATE] = date.getUTCDate();
  1092. }
  1093. // Default to current date.
  1094. // * if no year, month, day of month are given, default to today
  1095. // * if day of month is given, default month and year
  1096. // * if month is given, default only year
  1097. // * if year is given, don't default anything
  1098. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  1099. config._a[i] = input[i] = currentDate[i];
  1100. }
  1101. // Zero out whatever was not defaulted, including time
  1102. for (; i < 7; i++) {
  1103. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  1104. }
  1105. // add the offsets to the time to be parsed so that we can have a clean array for checking isValid
  1106. input[HOUR] += toInt((config._tzm || 0) / 60);
  1107. input[MINUTE] += toInt((config._tzm || 0) % 60);
  1108. config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
  1109. }
  1110. function dateFromObject(config) {
  1111. var normalizedInput;
  1112. if (config._d) {
  1113. return;
  1114. }
  1115. normalizedInput = normalizeObjectUnits(config._i);
  1116. config._a = [
  1117. normalizedInput.year,
  1118. normalizedInput.month,
  1119. normalizedInput.day,
  1120. normalizedInput.hour,
  1121. normalizedInput.minute,
  1122. normalizedInput.second,
  1123. normalizedInput.millisecond
  1124. ];
  1125. dateFromConfig(config);
  1126. }
  1127. function currentDateArray(config) {
  1128. var now = new Date();
  1129. if (config._useUTC) {
  1130. return [
  1131. now.getUTCFullYear(),
  1132. now.getUTCMonth(),
  1133. now.getUTCDate()
  1134. ];
  1135. } else {
  1136. return [now.getFullYear(), now.getMonth(), now.getDate()];
  1137. }
  1138. }
  1139. // date from string and format string
  1140. function makeDateFromStringAndFormat(config) {
  1141. config._a = [];
  1142. config._pf.empty = true;
  1143. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  1144. var lang = getLangDefinition(config._l),
  1145. string = '' + config._i,
  1146. i, parsedInput, tokens, token, skipped,
  1147. stringLength = string.length,
  1148. totalParsedInputLength = 0;
  1149. tokens = expandFormat(config._f, lang).match(formattingTokens) || [];
  1150. for (i = 0; i < tokens.length; i++) {
  1151. token = tokens[i];
  1152. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  1153. if (parsedInput) {
  1154. skipped = string.substr(0, string.indexOf(parsedInput));
  1155. if (skipped.length > 0) {
  1156. config._pf.unusedInput.push(skipped);
  1157. }
  1158. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  1159. totalParsedInputLength += parsedInput.length;
  1160. }
  1161. // don't parse if it's not a known token
  1162. if (formatTokenFunctions[token]) {
  1163. if (parsedInput) {
  1164. config._pf.empty = false;
  1165. }
  1166. else {
  1167. config._pf.unusedTokens.push(token);
  1168. }
  1169. addTimeToArrayFromToken(token, parsedInput, config);
  1170. }
  1171. else if (config._strict && !parsedInput) {
  1172. config._pf.unusedTokens.push(token);
  1173. }
  1174. }
  1175. // add remaining unparsed input length to the string
  1176. config._pf.charsLeftOver = stringLength - totalParsedInputLength;
  1177. if (string.length > 0) {
  1178. config._pf.unusedInput.push(string);
  1179. }
  1180. // handle am pm
  1181. if (config._isPm && config._a[HOUR] < 12) {
  1182. config._a[HOUR] += 12;
  1183. }
  1184. // if is 12 am, change hours to 0
  1185. if (config._isPm === false && config._a[HOUR] === 12) {
  1186. config._a[HOUR] = 0;
  1187. }
  1188. dateFromConfig(config);
  1189. checkOverflow(config);
  1190. }
  1191. function unescapeFormat(s) {
  1192. return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  1193. return p1 || p2 || p3 || p4;
  1194. });
  1195. }
  1196. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  1197. function regexpEscape(s) {
  1198. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  1199. }
  1200. // date from string and array of format strings
  1201. function makeDateFromStringAndArray(config) {
  1202. var tempConfig,
  1203. bestMoment,
  1204. scoreToBeat,
  1205. i,
  1206. currentScore;
  1207. if (config._f.length === 0) {
  1208. config._pf.invalidFormat = true;
  1209. config._d = new Date(NaN);
  1210. return;
  1211. }
  1212. for (i = 0; i < config._f.length; i++) {
  1213. currentScore = 0;
  1214. tempConfig = extend({}, config);
  1215. tempConfig._pf = defaultParsingFlags();
  1216. tempConfig._f = config._f[i];
  1217. makeDateFromStringAndFormat(tempConfig);
  1218. if (!isValid(tempConfig)) {
  1219. continue;
  1220. }
  1221. // if there is any input that was not parsed add a penalty for that format
  1222. currentScore += tempConfig._pf.charsLeftOver;
  1223. //or tokens
  1224. currentScore += tempConfig._pf.unusedTokens.length * 10;
  1225. tempConfig._pf.score = currentScore;
  1226. if (scoreToBeat == null || currentScore < scoreToBeat) {
  1227. scoreToBeat = currentScore;
  1228. bestMoment = tempConfig;
  1229. }
  1230. }
  1231. extend(config, bestMoment || tempConfig);
  1232. }
  1233. // date from iso format
  1234. function makeDateFromString(config) {
  1235. var i, l,
  1236. string = config._i,
  1237. match = isoRegex.exec(string);
  1238. if (match) {
  1239. config._pf.iso = true;
  1240. for (i = 0, l = isoDates.length; i < l; i++) {
  1241. if (isoDates[i][1].exec(string)) {
  1242. // match[5] should be "T" or undefined
  1243. config._f = isoDates[i][0] + (match[6] || " ");
  1244. break;
  1245. }
  1246. }
  1247. for (i = 0, l = isoTimes.length; i < l; i++) {
  1248. if (isoTimes[i][1].exec(string)) {
  1249. config._f += isoTimes[i][0];
  1250. break;
  1251. }
  1252. }
  1253. if (string.match(parseTokenTimezone)) {
  1254. config._f += "Z";
  1255. }
  1256. makeDateFromStringAndFormat(config);
  1257. }
  1258. else {
  1259. moment.createFromInputFallback(config);
  1260. }
  1261. }
  1262. function makeDateFromInput(config) {
  1263. var input = config._i,
  1264. matched = aspNetJsonRegex.exec(input);
  1265. if (input === undefined) {
  1266. config._d = new Date();
  1267. } else if (matched) {
  1268. config._d = new Date(+matched[1]);
  1269. } else if (typeof input === 'string') {
  1270. makeDateFromString(config);
  1271. } else if (isArray(input)) {
  1272. config._a = input.slice(0);
  1273. dateFromConfig(config);
  1274. } else if (isDate(input)) {
  1275. config._d = new Date(+input);
  1276. } else if (typeof(input) === 'object') {
  1277. dateFromObject(config);
  1278. } else if (typeof(input) === 'number') {
  1279. // from milliseconds
  1280. config._d = new Date(input);
  1281. } else {
  1282. moment.createFromInputFallback(config);
  1283. }
  1284. }
  1285. function makeDate(y, m, d, h, M, s, ms) {
  1286. //can't just apply() to create a date:
  1287. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  1288. var date = new Date(y, m, d, h, M, s, ms);
  1289. //the date constructor doesn't accept years < 1970
  1290. if (y < 1970) {
  1291. date.setFullYear(y);
  1292. }
  1293. return date;
  1294. }
  1295. function makeUTCDate(y) {
  1296. var date = new Date(Date.UTC.apply(null, arguments));
  1297. if (y < 1970) {
  1298. date.setUTCFullYear(y);
  1299. }
  1300. return date;
  1301. }
  1302. function parseWeekday(input, language) {
  1303. if (typeof input === 'string') {
  1304. if (!isNaN(input)) {
  1305. input = parseInt(input, 10);
  1306. }
  1307. else {
  1308. input = language.weekdaysParse(input);
  1309. if (typeof input !== 'number') {
  1310. return null;
  1311. }
  1312. }
  1313. }
  1314. return input;
  1315. }
  1316. /************************************
  1317. Relative Time
  1318. ************************************/
  1319. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  1320. function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) {
  1321. return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  1322. }
  1323. function relativeTime(milliseconds, withoutSuffix, lang) {
  1324. var seconds = round(Math.abs(milliseconds) / 1000),
  1325. minutes = round(seconds / 60),
  1326. hours = round(minutes / 60),
  1327. days = round(hours / 24),
  1328. years = round(days / 365),
  1329. args = seconds < 45 && ['s', seconds] ||
  1330. minutes === 1 && ['m'] ||
  1331. minutes < 45 && ['mm', minutes] ||
  1332. hours === 1 && ['h'] ||
  1333. hours < 22 && ['hh', hours] ||
  1334. days === 1 && ['d'] ||
  1335. days <= 25 && ['dd', days] ||
  1336. days <= 45 && ['M'] ||
  1337. days < 345 && ['MM', round(days / 30)] ||
  1338. years === 1 && ['y'] || ['yy', years];
  1339. args[2] = withoutSuffix;
  1340. args[3] = milliseconds > 0;
  1341. args[4] = lang;
  1342. return substituteTimeAgo.apply({}, args);
  1343. }
  1344. /************************************
  1345. Week of Year
  1346. ************************************/
  1347. // firstDayOfWeek 0 = sun, 6 = sat
  1348. // the day of the week that starts the week
  1349. // (usually sunday or monday)
  1350. // firstDayOfWeekOfYear 0 = sun, 6 = sat
  1351. // the first week is the week that contains the first
  1352. // of this day of the week
  1353. // (eg. ISO weeks use thursday (4))
  1354. function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
  1355. var end = firstDayOfWeekOfYear - firstDayOfWeek,
  1356. daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
  1357. adjustedMoment;
  1358. if (daysToDayOfWeek > end) {
  1359. daysToDayOfWeek -= 7;
  1360. }
  1361. if (daysToDayOfWeek < end - 7) {
  1362. daysToDayOfWeek += 7;
  1363. }
  1364. adjustedMoment = moment(mom).add('d', daysToDayOfWeek);
  1365. return {
  1366. week: Math.ceil(adjustedMoment.dayOfYear() / 7),
  1367. year: adjustedMoment.year()
  1368. };
  1369. }
  1370. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1371. function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
  1372. var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
  1373. weekday = weekday != null ? weekday : firstDayOfWeek;
  1374. daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
  1375. dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
  1376. return {
  1377. year: dayOfYear > 0 ? year : year - 1,
  1378. dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
  1379. };
  1380. }
  1381. /************************************
  1382. Top Level Functions
  1383. ************************************/
  1384. function makeMoment(config) {
  1385. var input = config._i,
  1386. format = config._f;
  1387. if (input === null || (format === undefined && input === '')) {
  1388. return moment.invalid({nullInput: true});
  1389. }
  1390. if (typeof input === 'string') {
  1391. config._i = input = getLangDefinition().preparse(input);
  1392. }
  1393. if (moment.isMoment(input)) {
  1394. config = cloneMoment(input);
  1395. config._d = new Date(+input._d);
  1396. } else if (format) {
  1397. if (isArray(format)) {
  1398. makeDateFromStringAndArray(config);
  1399. } else {
  1400. makeDateFromStringAndFormat(config);
  1401. }
  1402. } else {
  1403. makeDateFromInput(config);
  1404. }
  1405. return new Moment(config);
  1406. }
  1407. moment = function (input, format, lang, strict) {
  1408. var c;
  1409. if (typeof(lang) === "boolean") {
  1410. strict = lang;
  1411. lang = undefined;
  1412. }
  1413. // object construction must be done this way.
  1414. // https://github.com/moment/moment/issues/1423
  1415. c = {};
  1416. c._isAMomentObject = true;
  1417. c._i = input;
  1418. c._f = format;
  1419. c._l = lang;
  1420. c._strict = strict;
  1421. c._isUTC = false;
  1422. c._pf = defaultParsingFlags();
  1423. return makeMoment(c);
  1424. };
  1425. moment.suppressDeprecationWarnings = false;
  1426. moment.createFromInputFallback = deprecate(
  1427. "moment construction falls back to js Date. This is " +
  1428. "discouraged and will be removed in upcoming major " +
  1429. "release. Please refer to " +
  1430. "https://github.com/moment/moment/issues/1407 for more info.",
  1431. function (config) {
  1432. config._d = new Date(config._i);
  1433. });
  1434. // creating with utc
  1435. moment.utc = function (input, format, lang, strict) {
  1436. var c;
  1437. if (typeof(lang) === "boolean") {
  1438. strict = lang;
  1439. lang = undefined;
  1440. }
  1441. // object construction must be done this way.
  1442. // https://github.com/moment/moment/issues/1423
  1443. c = {};
  1444. c._isAMomentObject = true;
  1445. c._useUTC = true;
  1446. c._isUTC = true;
  1447. c._l = lang;
  1448. c._i = input;
  1449. c._f = format;
  1450. c._strict = strict;
  1451. c._pf = defaultParsingFlags();
  1452. return makeMoment(c).utc();
  1453. };
  1454. // creating with unix timestamp (in seconds)
  1455. moment.unix = function (input) {
  1456. return moment(input * 1000);
  1457. };
  1458. // duration
  1459. moment.duration = function (input, key) {
  1460. var duration = input,
  1461. // matching against regexp is expensive, do it on demand
  1462. match = null,
  1463. sign,
  1464. ret,
  1465. parseIso;
  1466. if (moment.isDuration(input)) {
  1467. duration = {
  1468. ms: input._milliseconds,
  1469. d: input._days,
  1470. M: input._months
  1471. };
  1472. } else if (typeof input === 'number') {
  1473. duration = {};
  1474. if (key) {
  1475. duration[key] = input;
  1476. } else {
  1477. duration.milliseconds = input;
  1478. }
  1479. } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
  1480. sign = (match[1] === "-") ? -1 : 1;
  1481. duration = {
  1482. y: 0,
  1483. d: toInt(match[DATE]) * sign,
  1484. h: toInt(match[HOUR]) * sign,
  1485. m: toInt(match[MINUTE]) * sign,
  1486. s: toInt(match[SECOND]) * sign,
  1487. ms: toInt(match[MILLISECOND]) * sign
  1488. };
  1489. } else if (!!(match = isoDurationRegex.exec(input))) {
  1490. sign = (match[1] === "-") ? -1 : 1;
  1491. parseIso = function (inp) {
  1492. // We'd normally use ~~inp for this, but unfortunately it also
  1493. // converts floats to ints.
  1494. // inp may be undefined, so careful calling replace on it.
  1495. var res = inp && parseFloat(inp.replace(',', '.'));
  1496. // apply sign while we're at it
  1497. return (isNaN(res) ? 0 : res) * sign;
  1498. };
  1499. duration = {
  1500. y: parseIso(match[2]),
  1501. M: parseIso(match[3]),
  1502. d: parseIso(match[4]),
  1503. h: parseIso(match[5]),
  1504. m: parseIso(match[6]),
  1505. s: parseIso(match[7]),
  1506. w: parseIso(match[8])
  1507. };
  1508. }
  1509. ret = new Duration(duration);
  1510. if (moment.isDuration(input) && input.hasOwnProperty('_lang')) {
  1511. ret._lang = input._lang;
  1512. }
  1513. return ret;
  1514. };
  1515. // version number
  1516. moment.version = VERSION;
  1517. // default format
  1518. moment.defaultFormat = isoFormat;
  1519. // Plugins that add properties should also add the key here (null value),
  1520. // so we can properly clone ourselves.
  1521. moment.momentProperties = momentProperties;
  1522. // This function will be called whenever a moment is mutated.
  1523. // It is intended to keep the offset in sync with the timezone.
  1524. moment.updateOffset = function () {};
  1525. // This function will load languages and then set the global language. If
  1526. // no arguments are passed in, it will simply return the current global
  1527. // language key.
  1528. moment.lang = function (key, values) {
  1529. var r;
  1530. if (!key) {
  1531. return moment.fn._lang._abbr;
  1532. }
  1533. if (values) {
  1534. loadLang(normalizeLanguage(key), values);
  1535. } else if (values === null) {
  1536. unloadLang(key);
  1537. key = 'en';
  1538. } else if (!languages[key]) {
  1539. getLangDefinition(key);
  1540. }
  1541. r = moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key);
  1542. return r._abbr;
  1543. };
  1544. // returns language data
  1545. moment.langData = function (key) {
  1546. if (key && key._lang && key._lang._abbr) {
  1547. key = key._lang._abbr;
  1548. }
  1549. return getLangDefinition(key);
  1550. };
  1551. // compare moment object
  1552. moment.isMoment = function (obj) {
  1553. return obj instanceof Moment ||
  1554. (obj != null && obj.hasOwnProperty('_isAMomentObject'));
  1555. };
  1556. // for typechecking Duration objects
  1557. moment.isDuration = function (obj) {
  1558. return obj instanceof Duration;
  1559. };
  1560. for (i = lists.length - 1; i >= 0; --i) {
  1561. makeList(lists[i]);
  1562. }
  1563. moment.normalizeUnits = function (units) {
  1564. return normalizeUnits(units);
  1565. };
  1566. moment.invalid = function (flags) {
  1567. var m = moment.utc(NaN);
  1568. if (flags != null) {
  1569. extend(m._pf, flags);
  1570. }
  1571. else {
  1572. m._pf.userInvalidated = true;
  1573. }
  1574. return m;
  1575. };
  1576. moment.parseZone = function () {
  1577. return moment.apply(null, arguments).parseZone();
  1578. };
  1579. moment.parseTwoDigitYear = function (input) {
  1580. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  1581. };
  1582. /************************************
  1583. Moment Prototype
  1584. ************************************/
  1585. extend(moment.fn = Moment.prototype, {
  1586. clone : function () {
  1587. return moment(this);
  1588. },
  1589. valueOf : function () {
  1590. return +this._d + ((this._offset || 0) * 60000);
  1591. },
  1592. unix : function () {
  1593. return Math.floor(+this / 1000);
  1594. },
  1595. toString : function () {
  1596. return this.clone().lang('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
  1597. },
  1598. toDate : function () {
  1599. return this._offset ? new Date(+this) : this._d;
  1600. },
  1601. toISOString : function () {
  1602. var m = moment(this).utc();
  1603. if (0 < m.year() && m.year() <= 9999) {
  1604. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1605. } else {
  1606. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1607. }
  1608. },
  1609. toArray : function () {
  1610. var m = this;
  1611. return [
  1612. m.year(),
  1613. m.month(),
  1614. m.date(),
  1615. m.hours(),
  1616. m.minutes(),
  1617. m.seconds(),
  1618. m.milliseconds()
  1619. ];
  1620. },
  1621. isValid : function () {
  1622. return isValid(this);
  1623. },
  1624. isDSTShifted : function () {
  1625. if (this._a) {
  1626. return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
  1627. }
  1628. return false;
  1629. },
  1630. parsingFlags : function () {
  1631. return extend({}, this._pf);
  1632. },
  1633. invalidAt: function () {
  1634. return this._pf.overflow;
  1635. },
  1636. utc : function () {
  1637. return this.zone(0);
  1638. },
  1639. local : function () {
  1640. this.zone(0);
  1641. this._isUTC = false;
  1642. return this;
  1643. },
  1644. format : function (inputString) {
  1645. var output = formatMoment(this, inputString || moment.defaultFormat);
  1646. return this.lang().postformat(output);
  1647. },
  1648. add : function (input, val) {
  1649. var dur;
  1650. // switch args to support add('s', 1) and add(1, 's')
  1651. if (typeof input === 'string') {
  1652. dur = moment.duration(+val, input);
  1653. } else {
  1654. dur = moment.duration(input, val);
  1655. }
  1656. addOrSubtractDurationFromMoment(this, dur, 1);
  1657. return this;
  1658. },
  1659. subtract : function (input, val) {
  1660. var dur;
  1661. // switch args to support subtract('s', 1) and subtract(1, 's')
  1662. if (typeof input === 'string') {
  1663. dur = moment.duration(+val, input);
  1664. } else {
  1665. dur = moment.duration(input, val);
  1666. }
  1667. addOrSubtractDurationFromMoment(this, dur, -1);
  1668. return this;
  1669. },
  1670. diff : function (input, units, asFloat) {
  1671. var that = makeAs(input, this),
  1672. zoneDiff = (this.zone() - that.zone()) * 6e4,
  1673. diff, output;
  1674. units = normalizeUnits(units);
  1675. if (units === 'year' || units === 'month') {
  1676. // average number of days in the months in the given dates
  1677. diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
  1678. // difference in months
  1679. output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
  1680. // adjust by taking difference in days, average number of days
  1681. // and dst in the given months.
  1682. output += ((this - moment(this).startOf('month')) -
  1683. (that - moment(that).startOf('month'))) / diff;
  1684. // same as above but with zones, to negate all dst
  1685. output -= ((this.zone() - moment(this).startOf('month').zone()) -
  1686. (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff;
  1687. if (units === 'year') {
  1688. output = output / 12;
  1689. }
  1690. } else {
  1691. diff = (this - that);
  1692. output = units === 'second' ? diff / 1e3 : // 1000
  1693. units === 'minute' ? diff / 6e4 : // 1000 * 60
  1694. units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
  1695. units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  1696. units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  1697. diff;
  1698. }
  1699. return asFloat ? output : absRound(output);
  1700. },
  1701. from : function (time, withoutSuffix) {
  1702. return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix);
  1703. },
  1704. fromNow : function (withoutSuffix) {
  1705. return this.from(moment(), withoutSuffix);
  1706. },
  1707. calendar : function () {
  1708. // We want to compare the start of today, vs this.
  1709. // Getting start-of-today depends on whether we're zone'd or not.
  1710. var sod = makeAs(moment(), this).startOf('day'),
  1711. diff = this.diff(sod, 'days', true),
  1712. format = diff < -6 ? 'sameElse' :
  1713. diff < -1 ? 'lastWeek' :
  1714. diff < 0 ? 'lastDay' :
  1715. diff < 1 ? 'sameDay' :
  1716. diff < 2 ? 'nextDay' :
  1717. diff < 7 ? 'nextWeek' : 'sameElse';
  1718. return this.format(this.lang().calendar(format, this));
  1719. },
  1720. isLeapYear : function () {
  1721. return isLeapYear(this.year());
  1722. },
  1723. isDST : function () {
  1724. return (this.zone() < this.clone().month(0).zone() ||
  1725. this.zone() < this.clone().month(5).zone());
  1726. },
  1727. day : function (input) {
  1728. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1729. if (input != null) {
  1730. input = parseWeekday(input, this.lang());
  1731. return this.add({ d : input - day });
  1732. } else {
  1733. return day;
  1734. }
  1735. },
  1736. month : makeAccessor('Month', true),
  1737. startOf: function (units) {
  1738. units = normalizeUnits(units);
  1739. // the following switch intentionally omits break keywords
  1740. // to utilize falling through the cases.
  1741. switch (units) {
  1742. case 'year':
  1743. this.month(0);
  1744. /* falls through */
  1745. case 'quarter':
  1746. case 'month':
  1747. this.date(1);
  1748. /* falls through */
  1749. case 'week':
  1750. case 'isoWeek':
  1751. case 'day':
  1752. this.hours(0);
  1753. /* falls through */
  1754. case 'hour':
  1755. this.minutes(0);
  1756. /* falls through */
  1757. case 'minute':
  1758. this.seconds(0);
  1759. /* falls through */
  1760. case 'second':
  1761. this.milliseconds(0);
  1762. /* falls through */
  1763. }
  1764. // weeks are a special case
  1765. if (units === 'week') {
  1766. this.weekday(0);
  1767. } else if (units === 'isoWeek') {
  1768. this.isoWeekday(1);
  1769. }
  1770. // quarters are also special
  1771. if (units === 'quarter') {
  1772. this.month(Math.floor(this.month() / 3) * 3);
  1773. }
  1774. return this;
  1775. },
  1776. endOf: function (units) {
  1777. units = normalizeUnits(units);
  1778. return this.startOf(units).add((units === 'isoWeek' ? 'week' : units), 1).subtract('ms', 1);
  1779. },
  1780. isAfter: function (input, units) {
  1781. units = typeof units !== 'undefined' ? units : 'millisecond';
  1782. return +this.clone().startOf(units) > +moment(input).startOf(units);
  1783. },
  1784. isBefore: function (input, units) {
  1785. units = typeof units !== 'undefined' ? units : 'millisecond';
  1786. return +this.clone().startOf(units) < +moment(input).startOf(units);
  1787. },
  1788. isSame: function (input, units) {
  1789. units = units || 'ms';
  1790. return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
  1791. },
  1792. min: function (other) {
  1793. other = moment.apply(null, arguments);
  1794. return other < this ? this : other;
  1795. },
  1796. max: function (other) {
  1797. other = moment.apply(null, arguments);
  1798. return other > this ? this : other;
  1799. },
  1800. // keepTime = true means only change the timezone, without affecting
  1801. // the local hour. So 5:31:26 +0300 --[zone(2, true)]--> 5:31:26 +0200
  1802. // It is possible that 5:31:26 doesn't exist int zone +0200, so we
  1803. // adjust the time as needed, to be valid.
  1804. //
  1805. // Keeping the time actually adds/subtracts (one hour)
  1806. // from the actual represented time. That is why we call updateOffset
  1807. // a second time. In case it wants us to change the offset again
  1808. // _changeInProgress == true case, then we have to adjust, because
  1809. // there is no such time in the given timezone.
  1810. zone : function (input, keepTime) {
  1811. var offset = this._offset || 0;
  1812. if (input != null) {
  1813. if (typeof input === "string") {
  1814. input = timezoneMinutesFromString(input);
  1815. }
  1816. if (Math.abs(input) < 16) {
  1817. input = input * 60;
  1818. }
  1819. this._offset = input;
  1820. this._isUTC = true;
  1821. if (offset !== input) {
  1822. if (!keepTime || this._changeInProgress) {
  1823. addOrSubtractDurationFromMoment(this,
  1824. moment.duration(offset - input, 'm'), 1, false);
  1825. } else if (!this._changeInProgress) {
  1826. this._changeInProgress = true;
  1827. moment.updateOffset(this, true);
  1828. this._changeInProgress = null;
  1829. }
  1830. }
  1831. } else {
  1832. return this._isUTC ? offset : this._d.getTimezoneOffset();
  1833. }
  1834. return this;
  1835. },
  1836. zoneAbbr : function () {
  1837. return this._isUTC ? "UTC" : "";
  1838. },
  1839. zoneName : function () {
  1840. return this._isUTC ? "Coordinated Universal Time" : "";
  1841. },
  1842. parseZone : function () {
  1843. if (this._tzm) {
  1844. this.zone(this._tzm);
  1845. } else if (typeof this._i === 'string') {
  1846. this.zone(this._i);
  1847. }
  1848. return this;
  1849. },
  1850. hasAlignedHourOffset : function (input) {
  1851. if (!input) {
  1852. input = 0;
  1853. }
  1854. else {
  1855. input = moment(input).zone();
  1856. }
  1857. return (this.zone() - input) % 60 === 0;
  1858. },
  1859. daysInMonth : function () {
  1860. return daysInMonth(this.year(), this.month());
  1861. },
  1862. dayOfYear : function (input) {
  1863. var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
  1864. return input == null ? dayOfYear : this.add("d", (input - dayOfYear));
  1865. },
  1866. quarter : function (input) {
  1867. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  1868. },
  1869. weekYear : function (input) {
  1870. var year = weekOfYear(this, this.lang()._week.dow, this.lang()._week.doy).year;
  1871. return input == null ? year : this.add("y", (input - year));
  1872. },
  1873. isoWeekYear : function (input) {
  1874. var year = weekOfYear(this, 1, 4).year;
  1875. return input == null ? year : this.add("y", (input - year));
  1876. },
  1877. week : function (input) {
  1878. var week = this.lang().week(this);
  1879. return input == null ? week : this.add("d", (input - week) * 7);
  1880. },
  1881. isoWeek : function (input) {
  1882. var week = weekOfYear(this, 1, 4).week;
  1883. return input == null ? week : this.add("d", (input - week) * 7);
  1884. },
  1885. weekday : function (input) {
  1886. var weekday = (this.day() + 7 - this.lang()._week.dow) % 7;
  1887. return input == null ? weekday : this.add("d", input - weekday);
  1888. },
  1889. isoWeekday : function (input) {
  1890. // behaves the same as moment#day except
  1891. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  1892. // as a setter, sunday should belong to the previous week.
  1893. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  1894. },
  1895. isoWeeksInYear : function () {
  1896. return weeksInYear(this.year(), 1, 4);
  1897. },
  1898. weeksInYear : function () {
  1899. var weekInfo = this._lang._week;
  1900. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  1901. },
  1902. get : function (units) {
  1903. units = normalizeUnits(units);
  1904. return this[units]();
  1905. },
  1906. set : function (units, value) {
  1907. units = normalizeUnits(units);
  1908. if (typeof this[units] === 'function') {
  1909. this[units](value);
  1910. }
  1911. return this;
  1912. },
  1913. // If passed a language key, it will set the language for this
  1914. // instance. Otherwise, it will return the language configuration
  1915. // variables for this instance.
  1916. lang : function (key) {
  1917. if (key === undefined) {
  1918. return this._lang;
  1919. } else {
  1920. this._lang = getLangDefinition(key);
  1921. return this;
  1922. }
  1923. }
  1924. });
  1925. function rawMonthSetter(mom, value) {
  1926. var dayOfMonth;
  1927. // TODO: Move this out of here!
  1928. if (typeof value === 'string') {
  1929. value = mom.lang().monthsParse(value);
  1930. // TODO: Another silent failure?
  1931. if (typeof value !== 'number') {
  1932. return mom;
  1933. }
  1934. }
  1935. dayOfMonth = Math.min(mom.date(),
  1936. daysInMonth(mom.year(), value));
  1937. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  1938. return mom;
  1939. }
  1940. function rawGetter(mom, unit) {
  1941. return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
  1942. }
  1943. function rawSetter(mom, unit, value) {
  1944. if (unit === 'Month') {
  1945. return rawMonthSetter(mom, value);
  1946. } else {
  1947. return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  1948. }
  1949. }
  1950. function makeAccessor(unit, keepTime) {
  1951. return function (value) {
  1952. if (value != null) {
  1953. rawSetter(this, unit, value);
  1954. moment.updateOffset(this, keepTime);
  1955. return this;
  1956. } else {
  1957. return rawGetter(this, unit);
  1958. }
  1959. };
  1960. }
  1961. moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);
  1962. moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);
  1963. moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);
  1964. // Setting the hour should keep the time, because the user explicitly
  1965. // specified which hour he wants. So trying to maintain the same hour (in
  1966. // a new timezone) makes sense. Adding/subtracting hours does not follow
  1967. // this rule.
  1968. moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);
  1969. // moment.fn.month is defined separately
  1970. moment.fn.date = makeAccessor('Date', true);
  1971. moment.fn.dates = deprecate("dates accessor is deprecated. Use date instead.", makeAccessor('Date', true));
  1972. moment.fn.year = makeAccessor('FullYear', true);
  1973. moment.fn.years = deprecate("years accessor is deprecated. Use year instead.", makeAccessor('FullYear', true));
  1974. // add plural methods
  1975. moment.fn.days = moment.fn.day;
  1976. moment.fn.months = moment.fn.month;
  1977. moment.fn.weeks = moment.fn.week;
  1978. moment.fn.isoWeeks = moment.fn.isoWeek;
  1979. moment.fn.quarters = moment.fn.quarter;
  1980. // add aliased format methods
  1981. moment.fn.toJSON = moment.fn.toISOString;
  1982. /************************************
  1983. Duration Prototype
  1984. ************************************/
  1985. extend(moment.duration.fn = Duration.prototype, {
  1986. _bubble : function () {
  1987. var milliseconds = this._milliseconds,
  1988. days = this._days,
  1989. months = this._months,
  1990. data = this._data,
  1991. seconds, minutes, hours, years;
  1992. // The following code bubbles up values, see the tests for
  1993. // examples of what that means.
  1994. data.milliseconds = milliseconds % 1000;
  1995. seconds = absRound(milliseconds / 1000);
  1996. data.seconds = seconds % 60;
  1997. minutes = absRound(seconds / 60);
  1998. data.minutes = minutes % 60;
  1999. hours = absRound(minutes / 60);
  2000. data.hours = hours % 24;
  2001. days += absRound(hours / 24);
  2002. data.days = days % 30;
  2003. months += absRound(days / 30);
  2004. data.months = months % 12;
  2005. years = absRound(months / 12);
  2006. data.years = years;
  2007. },
  2008. weeks : function () {
  2009. return absRound(this.days() / 7);
  2010. },
  2011. valueOf : function () {
  2012. return this._milliseconds +
  2013. this._days * 864e5 +
  2014. (this._months % 12) * 2592e6 +
  2015. toInt(this._months / 12) * 31536e6;
  2016. },
  2017. humanize : function (withSuffix) {
  2018. var difference = +this,
  2019. output = relativeTime(difference, !withSuffix, this.lang());
  2020. if (withSuffix) {
  2021. output = this.lang().pastFuture(difference, output);
  2022. }
  2023. return this.lang().postformat(output);
  2024. },
  2025. add : function (input, val) {
  2026. // supports only 2.0-style add(1, 's') or add(moment)
  2027. var dur = moment.duration(input, val);
  2028. this._milliseconds += dur._milliseconds;
  2029. this._days += dur._days;
  2030. this._months += dur._months;
  2031. this._bubble();
  2032. return this;
  2033. },
  2034. subtract : function (input, val) {
  2035. var dur = moment.duration(input, val);
  2036. this._milliseconds -= dur._milliseconds;
  2037. this._days -= dur._days;
  2038. this._months -= dur._months;
  2039. this._bubble();
  2040. return this;
  2041. },
  2042. get : function (units) {
  2043. units = normalizeUnits(units);
  2044. return this[units.toLowerCase() + 's']();
  2045. },
  2046. as : function (units) {
  2047. units = normalizeUnits(units);
  2048. return this['as' + units.charAt(0).toUpperCase() + units.slice(1) + 's']();
  2049. },
  2050. lang : moment.fn.lang,
  2051. toIsoString : function () {
  2052. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  2053. var years = Math.abs(this.years()),
  2054. months = Math.abs(this.months()),
  2055. days = Math.abs(this.days()),
  2056. hours = Math.abs(this.hours()),
  2057. minutes = Math.abs(this.minutes()),
  2058. seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
  2059. if (!this.asSeconds()) {
  2060. // this is the same as C#'s (Noda) and python (isodate)...
  2061. // but not other JS (goog.date)
  2062. return 'P0D';
  2063. }
  2064. return (this.asSeconds() < 0 ? '-' : '') +
  2065. 'P' +
  2066. (years ? years + 'Y' : '') +
  2067. (months ? months + 'M' : '') +
  2068. (days ? days + 'D' : '') +
  2069. ((hours || minutes || seconds) ? 'T' : '') +
  2070. (hours ? hours + 'H' : '') +
  2071. (minutes ? minutes + 'M' : '') +
  2072. (seconds ? seconds + 'S' : '');
  2073. }
  2074. });
  2075. function makeDurationGetter(name) {
  2076. moment.duration.fn[name] = function () {
  2077. return this._data[name];
  2078. };
  2079. }
  2080. function makeDurationAsGetter(name, factor) {
  2081. moment.duration.fn['as' + name] = function () {
  2082. return +this / factor;
  2083. };
  2084. }
  2085. for (i in unitMillisecondFactors) {
  2086. if (unitMillisecondFactors.hasOwnProperty(i)) {
  2087. makeDurationAsGetter(i, unitMillisecondFactors[i]);
  2088. makeDurationGetter(i.toLowerCase());
  2089. }
  2090. }
  2091. makeDurationAsGetter('Weeks', 6048e5);
  2092. moment.duration.fn.asMonths = function () {
  2093. return (+this - this.years() * 31536e6) / 2592e6 + this.years() * 12;
  2094. };
  2095. /************************************
  2096. Default Lang
  2097. ************************************/
  2098. // Set default language, other languages will inherit from English.
  2099. moment.lang('en', {
  2100. ordinal : function (number) {
  2101. var b = number % 10,
  2102. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  2103. (b === 1) ? 'st' :
  2104. (b === 2) ? 'nd' :
  2105. (b === 3) ? 'rd' : 'th';
  2106. return number + output;
  2107. }
  2108. });
  2109. /* EMBED_LANGUAGES */
  2110. /************************************
  2111. Exposing Moment
  2112. ************************************/
  2113. function makeGlobal(shouldDeprecate) {
  2114. /*global ender:false */
  2115. if (typeof ender !== 'undefined') {
  2116. return;
  2117. }
  2118. oldGlobalMoment = globalScope.moment;
  2119. if (shouldDeprecate) {
  2120. globalScope.moment = deprecate(
  2121. "Accessing Moment through the global scope is " +
  2122. "deprecated, and will be removed in an upcoming " +
  2123. "release.",
  2124. moment);
  2125. } else {
  2126. globalScope.moment = moment;
  2127. }
  2128. }
  2129. // CommonJS module is defined
  2130. if (hasModule) {
  2131. module.exports = moment;
  2132. } else if (typeof define === "function" && define.amd) {
  2133. define("moment", function (require, exports, module) {
  2134. if (module.config && module.config() && module.config().noGlobal === true) {
  2135. // release the global variable
  2136. globalScope.moment = oldGlobalMoment;
  2137. }
  2138. return moment;
  2139. });
  2140. makeGlobal(true);
  2141. } else {
  2142. makeGlobal();
  2143. }
  2144. }).call(this);