PageRenderTime 58ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full file

  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 t

Large files files are truncated, but you can click here to view the full file