| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 //! moment.js 2 //! version : 2.31.0 3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors 4 //! license : MIT 5 //! momentjs.com 6 7 ;(function (global, factory) { 8 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 9 typeof define === 'function' && define.amd ? define(factory) : 10 global.moment = factory() 11 }(this, (function () { 'use strict'; 12 13 var hookCallback; 14 15 function hooks() { 16 return hookCallback.apply(null, arguments); 17 } 18 19 // This is done to register the method called with moment() 20 // without creating circular dependencies. 21 function setHookCallback(callback) { 22 hookCallback = callback; 23 } 24 25 function isArray(input) { 26 return ( 27 input instanceof Array || 28 Object.prototype.toString.call(input) === '[object Array]' 29 ); 30 } 31 32 function isObject(input) { 33 // IE8 will treat undefined and null as object if it wasn't for 34 // input != null 35 return ( 36 input != null && 37 Object.prototype.toString.call(input) === '[object Object]' 38 ); 39 } 40 41 function hasOwnProp(a, b) { 42 return Object.prototype.hasOwnProperty.call(a, b); 43 } 44 45 function isObjectEmpty(obj) { 46 if (Object.getOwnPropertyNames) { 47 return Object.getOwnPropertyNames(obj).length === 0; 48 } else { 49 var k; 50 for (k in obj) { 51 if (hasOwnProp(obj, k)) { 52 return false; 53 } 54 } 55 return true; 56 } 57 } 58 59 function isUndefined(input) { 60 return input === void 0; 61 } 62 63 function isNumber(input) { 64 return ( 65 typeof input === 'number' || 66 Object.prototype.toString.call(input) === '[object Number]' 67 ); 68 } 69 70 function isDate(input) { 71 return ( 72 input instanceof Date || 73 Object.prototype.toString.call(input) === '[object Date]' 74 ); 75 } 76 77 function map(arr, fn) { 78 var res = [], 79 i, 80 arrLen = arr.length; 81 for (i = 0; i < arrLen; ++i) { 82 res.push(fn(arr[i], i)); 83 } 84 return res; 85 } 86 87 function extend(a, b) { 88 for (var i in b) { 89 if (hasOwnProp(b, i)) { 90 a[i] = b[i]; 91 } 92 } 93 94 if (hasOwnProp(b, 'toString')) { 95 a.toString = b.toString; 96 } 97 98 if (hasOwnProp(b, 'valueOf')) { 99 a.valueOf = b.valueOf; 100 } 101 102 return a; 103 } 104 105 function createUTC(input, format, locale, strict) { 106 return createLocalOrUTC(input, format, locale, strict, true).utc(); 107 } 108 109 function defaultParsingFlags() { 110 // We need to deep clone this object. 111 return { 112 empty: false, 113 unusedTokens: [], 114 unusedInput: [], 115 overflow: -2, 116 charsLeftOver: 0, 117 nullInput: false, 118 invalidEra: null, 119 invalidMonth: null, 120 invalidOffset: null, 121 invalidFormat: false, 122 userInvalidated: false, 123 iso: false, 124 parsedDateParts: [], 125 era: null, 126 meridiem: null, 127 rfc2822: false, 128 weekdayMismatch: false, 129 }; 130 } 131 132 function getParsingFlags(m) { 133 if (m._pf == null) { 134 m._pf = defaultParsingFlags(); 135 } 136 return m._pf; 137 } 138 139 var some; 140 if (Array.prototype.some) { 141 some = Array.prototype.some; 142 } else { 143 some = function (fun) { 144 var t = Object(this), 145 len = t.length >>> 0, 146 i; 147 148 for (i = 0; i < len; i++) { 149 if (i in t && fun.call(this, t[i], i, t)) { 150 return true; 151 } 152 } 153 154 return false; 155 }; 156 } 157 158 function isValid$2(m) { 159 var flags = null, 160 parsedParts = false, 161 isNowValid = m._d && !isNaN(m._d.getTime()); 162 if (isNowValid) { 163 flags = getParsingFlags(m); 164 parsedParts = some.call(flags.parsedDateParts, function (i) { 165 return i != null; 166 }); 167 isNowValid = 168 flags.overflow < 0 && 169 !flags.empty && 170 !flags.invalidEra && 171 !flags.invalidMonth && 172 !flags.invalidOffset && 173 !flags.invalidWeekday && 174 !flags.weekdayMismatch && 175 !flags.nullInput && 176 !flags.invalidFormat && 177 !flags.userInvalidated && 178 (!flags.meridiem || (flags.meridiem && parsedParts)); 179 if (m._strict) { 180 isNowValid = 181 isNowValid && 182 flags.charsLeftOver === 0 && 183 flags.unusedTokens.length === 0 && 184 flags.bigHour === undefined; 185 } 186 } 187 if (Object.isFrozen == null || !Object.isFrozen(m)) { 188 m._isValid = isNowValid; 189 } else { 190 return isNowValid; 191 } 192 return m._isValid; 193 } 194 195 function createInvalid$1(flags) { 196 var m = createUTC(NaN); 197 if (flags != null) { 198 extend(getParsingFlags(m), flags); 199 } else { 200 getParsingFlags(m).userInvalidated = true; 201 } 202 203 return m; 204 } 205 206 // Plugins that add properties should also add the key here (null value), 207 // so we can properly clone ourselves. 208 var momentProperties = (hooks.momentProperties = []), 209 updateInProgress = false; 210 211 function copyConfig(to, from) { 212 var i, 213 prop, 214 val, 215 momentPropertiesLen = momentProperties.length; 216 217 if (!isUndefined(from._isAMomentObject)) { 218 to._isAMomentObject = from._isAMomentObject; 219 } 220 if (!isUndefined(from._i)) { 221 to._i = from._i; 222 } 223 if (!isUndefined(from._f)) { 224 to._f = from._f; 225 } 226 if (!isUndefined(from._l)) { 227 to._l = from._l; 228 } 229 if (!isUndefined(from._strict)) { 230 to._strict = from._strict; 231 } 232 if (!isUndefined(from._tzm)) { 233 to._tzm = from._tzm; 234 } 235 if (!isUndefined(from._isUTC)) { 236 to._isUTC = from._isUTC; 237 } 238 if (!isUndefined(from._offset)) { 239 to._offset = from._offset; 240 } 241 if (!isUndefined(from._pf)) { 242 to._pf = getParsingFlags(from); 243 } 244 if (!isUndefined(from._locale)) { 245 to._locale = from._locale; 246 } 247 248 if (momentPropertiesLen > 0) { 249 for (i = 0; i < momentPropertiesLen; i++) { 250 prop = momentProperties[i]; 251 val = from[prop]; 252 if (!isUndefined(val)) { 253 to[prop] = val; 254 } 255 } 256 } 257 258 return to; 259 } 260 261 // Moment prototype object 262 function Moment(config) { 263 copyConfig(this, config); 264 this._d = new Date(config._d != null ? config._d.getTime() : NaN); 265 if (!this.isValid()) { 266 this._d = new Date(NaN); 267 } 268 // Prevent infinite loop in case updateOffset creates new moment 269 // objects. 270 if (updateInProgress === false) { 271 updateInProgress = true; 272 hooks.updateOffset(this); 273 updateInProgress = false; 274 } 275 } 276 277 function isMoment(obj) { 278 return ( 279 obj instanceof Moment || (obj != null && obj._isAMomentObject != null) 280 ); 281 } 282 283 function warn(msg) { 284 if ( 285 hooks.suppressDeprecationWarnings === false && 286 typeof console !== 'undefined' && 287 console.warn 288 ) { 289 console.warn('Deprecation warning: ' + msg); 290 } 291 } 292 293 function deprecate(msg, fn) { 294 var firstTime = true; 295 296 return extend(function () { 297 if (hooks.deprecationHandler != null) { 298 hooks.deprecationHandler(null, msg); 299 } 300 if (firstTime) { 301 var args = [], 302 arg, 303 i, 304 key, 305 argLen = arguments.length; 306 for (i = 0; i < argLen; i++) { 307 arg = ''; 308 if (typeof arguments[i] === 'object') { 309 arg += '\n[' + i + '] '; 310 for (key in arguments[0]) { 311 if (hasOwnProp(arguments[0], key)) { 312 arg += key + ': ' + arguments[0][key] + ', '; 313 } 314 } 315 arg = arg.slice(0, -2); // Remove trailing comma and space 316 } else { 317 arg = arguments[i]; 318 } 319 args.push(arg); 320 } 321 warn( 322 msg + 323 '\nArguments: ' + 324 Array.prototype.slice.call(args).join('') + 325 '\n' + 326 new Error().stack 327 ); 328 firstTime = false; 329 } 330 return fn.apply(this, arguments); 331 }, fn); 332 } 333 334 var deprecations = {}; 335 336 function deprecateSimple(name, msg) { 337 if (hooks.deprecationHandler != null) { 338 hooks.deprecationHandler(name, msg); 339 } 340 if (!deprecations[name]) { 341 warn(msg + '\n' + new Error().stack); 342 deprecations[name] = true; 343 } 344 } 345 346 hooks.suppressDeprecationWarnings = false; 347 hooks.deprecationHandler = null; 348 349 function isFunction(input) { 350 return ( 351 (typeof Function !== 'undefined' && input instanceof Function) || 352 Object.prototype.toString.call(input) === '[object Function]' 353 ); 354 } 355 356 var aliases = { 357 D: 'date', 358 dates: 'date', 359 date: 'date', 360 d: 'day', 361 days: 'day', 362 day: 'day', 363 e: 'weekday', 364 weekdays: 'weekday', 365 weekday: 'weekday', 366 E: 'isoWeekday', 367 isoweekdays: 'isoWeekday', 368 isoweekday: 'isoWeekday', 369 DDD: 'dayOfYear', 370 dayofyears: 'dayOfYear', 371 dayofyear: 'dayOfYear', 372 h: 'hour', 373 hours: 'hour', 374 hour: 'hour', 375 ms: 'millisecond', 376 milliseconds: 'millisecond', 377 millisecond: 'millisecond', 378 m: 'minute', 379 minutes: 'minute', 380 minute: 'minute', 381 M: 'month', 382 months: 'month', 383 month: 'month', 384 Q: 'quarter', 385 quarters: 'quarter', 386 quarter: 'quarter', 387 s: 'second', 388 seconds: 'second', 389 second: 'second', 390 gg: 'weekYear', 391 weekyears: 'weekYear', 392 weekyear: 'weekYear', 393 GG: 'isoWeekYear', 394 isoweekyears: 'isoWeekYear', 395 isoweekyear: 'isoWeekYear', 396 w: 'week', 397 weeks: 'week', 398 week: 'week', 399 W: 'isoWeek', 400 isoweeks: 'isoWeek', 401 isoweek: 'isoWeek', 402 y: 'year', 403 years: 'year', 404 year: 'year', 405 }; 406 407 function normalizeUnits(units) { 408 return typeof units === 'string' 409 ? aliases[units] || aliases[units.toLowerCase()] 410 : undefined; 411 } 412 413 function normalizeObjectUnits(inputObject) { 414 var normalizedInput = {}, 415 normalizedProp, 416 prop; 417 418 for (prop in inputObject) { 419 if (hasOwnProp(inputObject, prop)) { 420 normalizedProp = normalizeUnits(prop); 421 if (normalizedProp) { 422 normalizedInput[normalizedProp] = inputObject[prop]; 423 } 424 } 425 } 426 427 return normalizedInput; 428 } 429 430 var priorities = { 431 date: 9, 432 day: 11, 433 weekday: 11, 434 isoWeekday: 11, 435 dayOfYear: 4, 436 hour: 13, 437 millisecond: 16, 438 minute: 14, 439 month: 8, 440 quarter: 7, 441 second: 15, 442 weekYear: 1, 443 isoWeekYear: 1, 444 week: 5, 445 isoWeek: 5, 446 year: 1, 447 }; 448 449 function getPrioritizedUnits(unitsObj) { 450 var units = [], 451 u; 452 for (u in unitsObj) { 453 if (hasOwnProp(unitsObj, u)) { 454 units.push({ unit: u, priority: priorities[u] }); 455 } 456 } 457 units.sort(function (a, b) { 458 return a.priority - b.priority; 459 }); 460 return units; 461 } 462 463 function zeroFill(number, targetLength, forceSign) { 464 var absNumber = '' + Math.abs(number), 465 zerosToFill = targetLength - absNumber.length, 466 sign = number >= 0; 467 return ( 468 (sign ? (forceSign ? '+' : '') : '-') + 469 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + 470 absNumber 471 ); 472 } 473 474 var formattingTokens = 475 /(\[[^\[]*\])|(\\e)|(\\)?(eHHmm|[Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g, 476 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g, 477 formatFunctions = {}, 478 formatTokenFunctions = {}; 479 480 // token: 'M' 481 // padded: ['MM', 2] 482 // ordinal: 'Mo' 483 // callback: function () { this.month() + 1 } 484 function addFormatToken(token, padded, ordinal, callback) { 485 var func = callback; 486 if (typeof callback === 'string') { 487 func = function () { 488 return this[callback](); 489 }; 490 } 491 if (token) { 492 formatTokenFunctions[token] = func; 493 } 494 if (padded) { 495 formatTokenFunctions[padded[0]] = function () { 496 return zeroFill(func.apply(this, arguments), padded[1], padded[2]); 497 }; 498 } 499 if (ordinal) { 500 formatTokenFunctions[ordinal] = function () { 501 return this.localeData().ordinal( 502 func.apply(this, arguments), 503 token 504 ); 505 }; 506 } 507 } 508 509 function removeFormattingTokens(input) { 510 if (input.match(/\[[\s\S]/)) { 511 return input.replace(/^\[|\]$/g, ''); 512 } 513 return input.replace(/\\/g, ''); 514 } 515 516 function makeFormatFunction(format) { 517 var array = format.match(formattingTokens), 518 i, 519 length; 520 521 for (i = 0, length = array.length; i < length; i++) { 522 if (formatTokenFunctions[array[i]]) { 523 array[i] = formatTokenFunctions[array[i]]; 524 } else { 525 array[i] = removeFormattingTokens(array[i]); 526 } 527 } 528 529 return function (mom) { 530 var output = '', 531 i; 532 for (i = 0; i < length; i++) { 533 output += isFunction(array[i]) 534 ? array[i].call(mom, format) 535 : array[i]; 536 } 537 return output; 538 }; 539 } 540 541 // format date using native date object 542 function formatMoment(m, format) { 543 if (!m.isValid()) { 544 return m.localeData().invalidDate(); 545 } 546 547 format = expandFormat(format, m.localeData()); 548 var cacheKey = '$' + format; 549 if (!hasOwnProp(formatFunctions, cacheKey)) { 550 formatFunctions[cacheKey] = makeFormatFunction(format); 551 } 552 553 return formatFunctions[cacheKey](m); 554 } 555 556 function expandFormat(format, locale) { 557 var i = 5; 558 559 function replaceLongDateFormatTokens(input) { 560 return locale.longDateFormat(input) || input; 561 } 562 563 localFormattingTokens.lastIndex = 0; 564 while (i >= 0 && localFormattingTokens.test(format)) { 565 format = format.replace( 566 localFormattingTokens, 567 replaceLongDateFormatTokens 568 ); 569 localFormattingTokens.lastIndex = 0; 570 i -= 1; 571 } 572 573 return format; 574 } 575 576 var match1 = /\d/, // 0 - 9 577 match2 = /\d\d/, // 00 - 99 578 match3 = /\d{3}/, // 000 - 999 579 match4 = /\d{4}/, // 0000 - 9999 580 match6 = /[+-]?\d{6}/, // -999999 - 999999 581 match1to2 = /\d\d?/, // 0 - 99 582 match3to4 = /\d\d\d\d?/, // 999 - 9999 583 match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999 584 match1to3 = /\d{1,3}/, // 0 - 999 585 match1to4 = /\d{1,4}/, // 0 - 9999 586 match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999 587 matchUnsigned = /\d+/, // 0 - inf 588 matchSigned = /[+-]?\d+/, // -inf - inf 589 matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z 590 matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z 591 matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 592 // any word (or two) characters or numbers including two/three word month in arabic. 593 // includes scottish gaelic two word and hyphenated months 594 matchWord = 595 /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i, 596 match1to2NoLeadingZero = /^[1-9]\d?/, // 1-99 597 match1to2HasZero = /^([1-9]\d|\d)/, // 0-99 598 regexes; 599 600 regexes = {}; 601 602 function addRegexToken(token, regex, strictRegex) { 603 regexes[token] = isFunction(regex) 604 ? regex 605 : function (isStrict, localeData) { 606 return isStrict && strictRegex ? strictRegex : regex; 607 }; 608 } 609 610 function getParseRegexForToken(token, config) { 611 if (!hasOwnProp(regexes, token)) { 612 return new RegExp(unescapeFormat(token)); 613 } 614 615 return regexes[token](config._strict, config._locale); 616 } 617 618 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript 619 function unescapeFormat(s) { 620 return regexEscape( 621 s 622 .replace('\\', '') 623 .replace( 624 /\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, 625 function (matched, p1, p2, p3, p4) { 626 return p1 || p2 || p3 || p4; 627 } 628 ) 629 ); 630 } 631 632 function regexEscape(s) { 633 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); 634 } 635 636 function absFloor(number) { 637 if (number < 0) { 638 // -0 -> 0 639 return Math.ceil(number) || 0; 640 } else { 641 return Math.floor(number); 642 } 643 } 644 645 function toInt(argumentForCoercion) { 646 var coercedNumber = +argumentForCoercion, 647 value = 0; 648 649 if (coercedNumber !== 0 && isFinite(coercedNumber)) { 650 value = absFloor(coercedNumber); 651 } 652 653 return value; 654 } 655 656 var tokens = {}; 657 658 function addParseToken(token, callback) { 659 var i, 660 func = callback, 661 tokenLen; 662 if (typeof token === 'string') { 663 token = [token]; 664 } 665 if (isNumber(callback)) { 666 func = function (input, array) { 667 array[callback] = toInt(input); 668 }; 669 } 670 tokenLen = token.length; 671 for (i = 0; i < tokenLen; i++) { 672 tokens[token[i]] = func; 673 } 674 } 675 676 function addWeekParseToken(token, callback) { 677 addParseToken(token, function (input, array, config, token) { 678 config._w = config._w || {}; 679 callback(input, config._w, config, token); 680 }); 681 } 682 683 function addTimeToArrayFromToken(token, input, config) { 684 if (input != null && hasOwnProp(tokens, token)) { 685 tokens[token](input, config._a, config, token); 686 } 687 } 688 689 function isLeapYear(year) { 690 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 691 } 692 693 var YEAR = 0, 694 MONTH = 1, 695 DATE = 2, 696 HOUR = 3, 697 MINUTE = 4, 698 SECOND = 5, 699 MILLISECOND = 6, 700 WEEK = 7, 701 WEEKDAY = 8; 702 703 // FORMATTING 704 705 addFormatToken('Y', 0, 0, function () { 706 var y = this.year(); 707 return y <= 9999 ? zeroFill(y, 4) : '+' + y; 708 }); 709 710 addFormatToken(0, ['YY', 2], 0, function () { 711 return this.year() % 100; 712 }); 713 714 addFormatToken(0, ['YYYY', 4], 0, 'year'); 715 addFormatToken(0, ['YYYYY', 5], 0, 'year'); 716 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); 717 718 // PARSING 719 720 addRegexToken('Y', matchSigned); 721 addRegexToken('YY', match1to2, match2); 722 addRegexToken('YYYY', match1to4, match4); 723 addRegexToken('YYYYY', match1to6, match6); 724 addRegexToken('YYYYYY', match1to6, match6); 725 726 addParseToken(['YYYYY', 'YYYYYY'], YEAR); 727 addParseToken('YYYY', function (input, array) { 728 array[YEAR] = 729 input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input); 730 }); 731 addParseToken('YY', function (input, array) { 732 array[YEAR] = hooks.parseTwoDigitYear(input); 733 }); 734 addParseToken('Y', function (input, array) { 735 array[YEAR] = parseInt(input, 10); 736 }); 737 738 // HELPERS 739 740 function daysInYear(year) { 741 return isLeapYear(year) ? 366 : 365; 742 } 743 744 // HOOKS 745 746 hooks.parseTwoDigitYear = function (input) { 747 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); 748 }; 749 750 // MOMENTS 751 752 var getSetYear = makeGetSet('FullYear', true); 753 754 function getIsLeapYear() { 755 return isLeapYear(this.year()); 756 } 757 758 function makeGetSet(unit, keepTime) { 759 return function (value) { 760 if (value != null) { 761 set$1(this, unit, value); 762 hooks.updateOffset(this, keepTime); 763 return this; 764 } else { 765 return get$2(this, unit); 766 } 767 }; 768 } 769 770 function get$2(mom, unit) { 771 if (!mom.isValid()) { 772 return NaN; 773 } 774 775 var d = mom._d, 776 isUTC = mom._isUTC; 777 778 switch (unit) { 779 case 'Milliseconds': 780 return isUTC ? d.getUTCMilliseconds() : d.getMilliseconds(); 781 case 'Seconds': 782 return isUTC ? d.getUTCSeconds() : d.getSeconds(); 783 case 'Minutes': 784 return isUTC ? d.getUTCMinutes() : d.getMinutes(); 785 case 'Hours': 786 return isUTC ? d.getUTCHours() : d.getHours(); 787 case 'Date': 788 return isUTC ? d.getUTCDate() : d.getDate(); 789 case 'Day': 790 return isUTC ? d.getUTCDay() : d.getDay(); 791 case 'Month': 792 return isUTC ? d.getUTCMonth() : d.getMonth(); 793 case 'FullYear': 794 return isUTC ? d.getUTCFullYear() : d.getFullYear(); 795 default: 796 return NaN; // Just in case 797 } 798 } 799 800 function set$1(mom, unit, value) { 801 var d, isUTC, year, month, date; 802 803 if (!mom.isValid() || isNaN(value)) { 804 return; 805 } 806 807 d = mom._d; 808 isUTC = mom._isUTC; 809 810 switch (unit) { 811 case 'Milliseconds': 812 return void (isUTC 813 ? d.setUTCMilliseconds(value) 814 : d.setMilliseconds(value)); 815 case 'Seconds': 816 return void (isUTC ? d.setUTCSeconds(value) : d.setSeconds(value)); 817 case 'Minutes': 818 return void (isUTC ? d.setUTCMinutes(value) : d.setMinutes(value)); 819 case 'Hours': 820 return void (isUTC ? d.setUTCHours(value) : d.setHours(value)); 821 case 'Date': 822 return void (isUTC ? d.setUTCDate(value) : d.setDate(value)); 823 // case 'Day': // Not real 824 // return void (isUTC ? d.setUTCDay(value) : d.setDay(value)); 825 // case 'Month': // Not used because we need to pass two variables 826 // return void (isUTC ? d.setUTCMonth(value) : d.setMonth(value)); 827 case 'FullYear': 828 break; // See below ... 829 default: 830 return; // Just in case 831 } 832 833 year = value; 834 month = mom.month(); 835 date = mom.date(); 836 date = date === 29 && month === 1 && !isLeapYear(year) ? 28 : date; 837 void (isUTC 838 ? d.setUTCFullYear(year, month, date) 839 : d.setFullYear(year, month, date)); 840 } 841 842 // MOMENTS 843 844 function stringGet(units) { 845 units = normalizeUnits(units); 846 if (isFunction(this[units])) { 847 return this[units](); 848 } 849 return this; 850 } 851 852 function stringSet(units, value) { 853 if (typeof units === 'object') { 854 units = normalizeObjectUnits(units); 855 var prioritized = getPrioritizedUnits(units), 856 i, 857 prioritizedLen = prioritized.length; 858 for (i = 0; i < prioritizedLen; i++) { 859 this[prioritized[i].unit](units[prioritized[i].unit]); 860 } 861 } else { 862 units = normalizeUnits(units); 863 if (isFunction(this[units])) { 864 return this[units](value); 865 } 866 } 867 return this; 868 } 869 870 function mod$1(n, x) { 871 return ((n % x) + x) % x; 872 } 873 874 var indexOf; 875 876 if (Array.prototype.indexOf) { 877 indexOf = Array.prototype.indexOf; 878 } else { 879 indexOf = function (o) { 880 // I know 881 var i; 882 for (i = 0; i < this.length; ++i) { 883 if (this[i] === o) { 884 return i; 885 } 886 } 887 return -1; 888 }; 889 } 890 891 function daysInMonth(year, month) { 892 if (isNaN(year) || isNaN(month)) { 893 return NaN; 894 } 895 var modMonth = mod$1(month, 12); 896 year += (month - modMonth) / 12; 897 return modMonth === 1 898 ? isLeapYear(year) 899 ? 29 900 : 28 901 : 31 - ((modMonth % 7) % 2); 902 } 903 904 // FORMATTING 905 906 addFormatToken('M', ['MM', 2], 'Mo', function () { 907 return this.month() + 1; 908 }); 909 910 addFormatToken('MMM', 0, 0, function (format) { 911 return this.localeData().monthsShort(this, format); 912 }); 913 914 addFormatToken('MMMM', 0, 0, function (format) { 915 return this.localeData().months(this, format); 916 }); 917 918 // PARSING 919 920 addRegexToken('M', match1to2, match1to2NoLeadingZero); 921 addRegexToken('MM', match1to2, match2); 922 addRegexToken('MMM', function (isStrict, locale) { 923 return locale.monthsShortRegex(isStrict); 924 }); 925 addRegexToken('MMMM', function (isStrict, locale) { 926 return locale.monthsRegex(isStrict); 927 }); 928 929 addParseToken(['M', 'MM'], function (input, array) { 930 array[MONTH] = toInt(input) - 1; 931 }); 932 933 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) { 934 var month = config._locale.monthsParse(input, token, config._strict); 935 // if we didn't find a month name, mark the date as invalid. 936 if (month != null) { 937 array[MONTH] = month; 938 } else { 939 getParsingFlags(config).invalidMonth = input; 940 } 941 }); 942 943 // LOCALES 944 945 var defaultLocaleMonths = 946 'January_February_March_April_May_June_July_August_September_October_November_December'.split( 947 '_' 948 ), 949 defaultLocaleMonthsShort = 950 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'), 951 MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/, 952 defaultMonthsShortRegex = matchWord, 953 defaultMonthsRegex = matchWord, 954 monthsParseProperties = [ 955 'monthsParse', 956 'longMonthsParse', 957 'shortMonthsParse', 958 'monthsRegex', 959 'monthsShortRegex', 960 'monthsStrictRegex', 961 'monthsShortStrictRegex', 962 ]; 963 964 function clearMonthsParseCache(locale, config) { 965 var i, prop; 966 for (i = 0; i < monthsParseProperties.length; i++) { 967 prop = monthsParseProperties[i]; 968 if (!hasOwnProp(config, prop)) { 969 delete locale['_' + prop]; 970 } 971 } 972 } 973 974 function localeMonths(m, format) { 975 if (!m) { 976 return isArray(this._months) 977 ? this._months 978 : this._months['standalone']; 979 } 980 return isArray(this._months) 981 ? this._months[m.month()] 982 : this._months[ 983 (this._months.isFormat || MONTHS_IN_FORMAT).test(format) 984 ? 'format' 985 : 'standalone' 986 ][m.month()]; 987 } 988 989 function localeMonthsShort(m, format) { 990 if (!m) { 991 return isArray(this._monthsShort) 992 ? this._monthsShort 993 : this._monthsShort['standalone']; 994 } 995 return isArray(this._monthsShort) 996 ? this._monthsShort[m.month()] 997 : this._monthsShort[ 998 MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone' 999 ][m.month()]; 1000 } 1001 1002 function handleStrictParse$1(monthName, format, strict) { 1003 var i, 1004 ii, 1005 mom, 1006 llc = monthName.toLocaleLowerCase(); 1007 if (!this._monthsParse) { 1008 // this is not used 1009 this._monthsParse = []; 1010 this._longMonthsParse = []; 1011 this._shortMonthsParse = []; 1012 for (i = 0; i < 12; ++i) { 1013 mom = createUTC([2000, i]); 1014 this._shortMonthsParse[i] = this.monthsShort( 1015 mom, 1016 '' 1017 ).toLocaleLowerCase(); 1018 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase(); 1019 } 1020 } 1021 1022 if (strict) { 1023 if (format === 'MMM') { 1024 ii = indexOf.call(this._shortMonthsParse, llc); 1025 return ii !== -1 ? ii : null; 1026 } else { 1027 ii = indexOf.call(this._longMonthsParse, llc); 1028 return ii !== -1 ? ii : null; 1029 } 1030 } else { 1031 if (format === 'MMM') { 1032 ii = indexOf.call(this._shortMonthsParse, llc); 1033 if (ii !== -1) { 1034 return ii; 1035 } 1036 ii = indexOf.call(this._longMonthsParse, llc); 1037 return ii !== -1 ? ii : null; 1038 } else { 1039 ii = indexOf.call(this._longMonthsParse, llc); 1040 if (ii !== -1) { 1041 return ii; 1042 } 1043 ii = indexOf.call(this._shortMonthsParse, llc); 1044 return ii !== -1 ? ii : null; 1045 } 1046 } 1047 } 1048 1049 function localeMonthsParse(monthName, format, strict) { 1050 var i, mom, regex; 1051 1052 if (this._monthsParseExact) { 1053 return handleStrictParse$1.call(this, monthName, format, strict); 1054 } 1055 1056 if (!this._monthsParse) { 1057 this._monthsParse = []; 1058 this._longMonthsParse = []; 1059 this._shortMonthsParse = []; 1060 } 1061 1062 // TODO: add sorting 1063 // Sorting makes sure if one month (or abbr) is a prefix of another 1064 // see sorting in computeMonthsParse 1065 for (i = 0; i < 12; i++) { 1066 // make the regex if we don't have it already 1067 mom = createUTC([2000, i]); 1068 if (strict && !this._longMonthsParse[i]) { 1069 this._longMonthsParse[i] = new RegExp( 1070 '^' + this.months(mom, '').replace('.', '') + '$', 1071 'i' 1072 ); 1073 this._shortMonthsParse[i] = new RegExp( 1074 '^' + this.monthsShort(mom, '').replace('.', '') + '$', 1075 'i' 1076 ); 1077 } 1078 if (!strict && !this._monthsParse[i]) { 1079 regex = 1080 '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, ''); 1081 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i'); 1082 } 1083 // test the regex 1084 if ( 1085 strict && 1086 format === 'MMMM' && 1087 this._longMonthsParse[i].test(monthName) 1088 ) { 1089 return i; 1090 } else if ( 1091 strict && 1092 format === 'MMM' && 1093 this._shortMonthsParse[i].test(monthName) 1094 ) { 1095 return i; 1096 } else if (!strict && this._monthsParse[i].test(monthName)) { 1097 return i; 1098 } 1099 } 1100 } 1101 1102 // MOMENTS 1103 1104 function setMonth(mom, value) { 1105 if (!mom.isValid()) { 1106 // No op 1107 return mom; 1108 } 1109 1110 if (typeof value === 'string') { 1111 if (/^\d+$/.test(value)) { 1112 value = toInt(value); 1113 } else { 1114 value = mom.localeData().monthsParse(value); 1115 // TODO: Another silent failure? 1116 if (!isNumber(value)) { 1117 return mom; 1118 } 1119 } 1120 } 1121 1122 var month = value, 1123 date = mom.date(); 1124 1125 date = date < 29 ? date : Math.min(date, daysInMonth(mom.year(), month)); 1126 void (mom._isUTC 1127 ? mom._d.setUTCMonth(month, date) 1128 : mom._d.setMonth(month, date)); 1129 return mom; 1130 } 1131 1132 function getSetMonth(value) { 1133 if (value != null) { 1134 setMonth(this, value); 1135 hooks.updateOffset(this, true); 1136 return this; 1137 } else { 1138 return get$2(this, 'Month'); 1139 } 1140 } 1141 1142 function getDaysInMonth() { 1143 return daysInMonth(this.year(), this.month()); 1144 } 1145 1146 function monthsShortRegex(isStrict) { 1147 if (this._monthsParseExact) { 1148 if (!hasOwnProp(this, '_monthsRegex')) { 1149 computeMonthsParse.call(this); 1150 } 1151 if (isStrict) { 1152 return this._monthsShortStrictRegex; 1153 } else { 1154 return this._monthsShortRegex; 1155 } 1156 } else { 1157 if (!hasOwnProp(this, '_monthsShortRegex')) { 1158 this._monthsShortRegex = defaultMonthsShortRegex; 1159 } 1160 return this._monthsShortStrictRegex && isStrict 1161 ? this._monthsShortStrictRegex 1162 : this._monthsShortRegex; 1163 } 1164 } 1165 1166 function monthsRegex(isStrict) { 1167 if (this._monthsParseExact) { 1168 if (!hasOwnProp(this, '_monthsRegex')) { 1169 computeMonthsParse.call(this); 1170 } 1171 if (isStrict) { 1172 return this._monthsStrictRegex; 1173 } else { 1174 return this._monthsRegex; 1175 } 1176 } else { 1177 if (!hasOwnProp(this, '_monthsRegex')) { 1178 this._monthsRegex = defaultMonthsRegex; 1179 } 1180 return this._monthsStrictRegex && isStrict 1181 ? this._monthsStrictRegex 1182 : this._monthsRegex; 1183 } 1184 } 1185 1186 function computeMonthsParse() { 1187 function cmpLenRev(a, b) { 1188 return b.length - a.length; 1189 } 1190 1191 var shortPieces = [], 1192 longPieces = [], 1193 mixedPieces = [], 1194 i, 1195 mom, 1196 shortP, 1197 longP; 1198 for (i = 0; i < 12; i++) { 1199 // make the regex if we don't have it already 1200 mom = createUTC([2000, i]); 1201 shortP = regexEscape(this.monthsShort(mom, '')); 1202 longP = regexEscape(this.months(mom, '')); 1203 shortPieces.push(shortP); 1204 longPieces.push(longP); 1205 mixedPieces.push(longP); 1206 mixedPieces.push(shortP); 1207 } 1208 // Sorting makes sure if one month (or abbr) is a prefix of another it 1209 // will match the longer piece. 1210 shortPieces.sort(cmpLenRev); 1211 longPieces.sort(cmpLenRev); 1212 mixedPieces.sort(cmpLenRev); 1213 1214 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); 1215 this._monthsShortRegex = this._monthsRegex; 1216 this._monthsStrictRegex = new RegExp( 1217 '^(' + longPieces.join('|') + ')', 1218 'i' 1219 ); 1220 this._monthsShortStrictRegex = new RegExp( 1221 '^(' + shortPieces.join('|') + ')', 1222 'i' 1223 ); 1224 } 1225 1226 // FORMATTING 1227 1228 addFormatToken('d', 0, 'do', 'day'); 1229 1230 addFormatToken('dd', 0, 0, function (format) { 1231 return this.localeData().weekdaysMin(this, format); 1232 }); 1233 1234 addFormatToken('ddd', 0, 0, function (format) { 1235 return this.localeData().weekdaysShort(this, format); 1236 }); 1237 1238 addFormatToken('dddd', 0, 0, function (format) { 1239 return this.localeData().weekdays(this, format); 1240 }); 1241 1242 addFormatToken('e', 0, 0, 'weekday'); 1243 addFormatToken('E', 0, 0, 'isoWeekday'); 1244 addFormatToken('eHHmm', 0, 0, function () { 1245 return ( 1246 '' + 1247 this.weekday() + 1248 zeroFill(this.hours(), 2) + 1249 zeroFill(this.minutes(), 2) 1250 ); 1251 }); 1252 1253 // PARSING 1254 1255 addRegexToken('d', match1to2); 1256 addRegexToken('e', match1to2); 1257 addRegexToken('E', match1to2); 1258 addRegexToken('eHHmm', match5to6); 1259 addRegexToken('dd', function (isStrict, locale) { 1260 return locale.weekdaysMinRegex(isStrict); 1261 }); 1262 addRegexToken('ddd', function (isStrict, locale) { 1263 return locale.weekdaysShortRegex(isStrict); 1264 }); 1265 addRegexToken('dddd', function (isStrict, locale) { 1266 return locale.weekdaysRegex(isStrict); 1267 }); 1268 1269 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) { 1270 var weekday = config._locale.weekdaysParse(input, token, config._strict); 1271 // if we didn't get a weekday name, mark the date as invalid 1272 if (weekday != null) { 1273 week.d = weekday; 1274 } else { 1275 getParsingFlags(config).invalidWeekday = input; 1276 } 1277 }); 1278 1279 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) { 1280 week[token] = toInt(input); 1281 }); 1282 1283 addWeekParseToken('eHHmm', function (input, week, config) { 1284 var weekdayEnd = input.length - 4; 1285 1286 week.e = toInt(input.substr(0, weekdayEnd)); 1287 config._a[HOUR] = toInt(input.substr(weekdayEnd, 2)); 1288 config._a[MINUTE] = toInt(input.substr(weekdayEnd + 2)); 1289 }); 1290 1291 // HELPERS 1292 1293 function parseWeekday(input, locale) { 1294 if (typeof input !== 'string') { 1295 return input; 1296 } 1297 1298 if (!isNaN(input)) { 1299 return parseInt(input, 10); 1300 } 1301 1302 input = locale.weekdaysParse(input); 1303 if (typeof input === 'number') { 1304 return input; 1305 } 1306 1307 return null; 1308 } 1309 1310 function parseIsoWeekday(input, locale) { 1311 if (typeof input === 'string') { 1312 return locale.weekdaysParse(input) % 7 || 7; 1313 } 1314 return isNaN(input) ? null : input; 1315 } 1316 1317 // LOCALES 1318 function shiftWeekdays(ws, n) { 1319 return ws.slice(n, 7).concat(ws.slice(0, n)); 1320 } 1321 1322 var defaultLocaleWeekdays = 1323 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), 1324 defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'), 1325 defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'), 1326 defaultWeekdaysRegex = matchWord, 1327 defaultWeekdaysShortRegex = matchWord, 1328 defaultWeekdaysMinRegex = matchWord, 1329 weekdaysParseProperties = [ 1330 'weekdaysParse', 1331 'fullWeekdaysParse', 1332 'shortWeekdaysParse', 1333 'minWeekdaysParse', 1334 'weekdaysRegex', 1335 'weekdaysShortRegex', 1336 'weekdaysMinRegex', 1337 'weekdaysStrictRegex', 1338 'weekdaysShortStrictRegex', 1339 'weekdaysMinStrictRegex', 1340 ]; 1341 1342 function clearWeekdaysParseCache(locale, config) { 1343 var i, prop; 1344 for (i = 0; i < weekdaysParseProperties.length; i++) { 1345 prop = weekdaysParseProperties[i]; 1346 if (!hasOwnProp(config, prop)) { 1347 delete locale['_' + prop]; 1348 } 1349 } 1350 } 1351 1352 function localeWeekdays(m, format) { 1353 var weekdays = isArray(this._weekdays) 1354 ? this._weekdays 1355 : this._weekdays[ 1356 m && m !== true && this._weekdays.isFormat.test(format) 1357 ? 'format' 1358 : 'standalone' 1359 ]; 1360 return m === true 1361 ? shiftWeekdays(weekdays, this._week.dow) 1362 : m 1363 ? weekdays[m.day()] 1364 : weekdays; 1365 } 1366 1367 function localeWeekdaysShort(m) { 1368 return m === true 1369 ? shiftWeekdays(this._weekdaysShort, this._week.dow) 1370 : m 1371 ? this._weekdaysShort[m.day()] 1372 : this._weekdaysShort; 1373 } 1374 1375 function localeWeekdaysMin(m) { 1376 return m === true 1377 ? shiftWeekdays(this._weekdaysMin, this._week.dow) 1378 : m 1379 ? this._weekdaysMin[m.day()] 1380 : this._weekdaysMin; 1381 } 1382 1383 function handleStrictParse(weekdayName, format, strict) { 1384 var i, 1385 ii, 1386 mom, 1387 llc = weekdayName.toLocaleLowerCase(); 1388 if (!this._weekdaysParse) { 1389 this._weekdaysParse = []; 1390 this._shortWeekdaysParse = []; 1391 this._minWeekdaysParse = []; 1392 1393 for (i = 0; i < 7; ++i) { 1394 mom = createUTC([2000, 1]).day(i); 1395 this._minWeekdaysParse[i] = this.weekdaysMin( 1396 mom, 1397 '' 1398 ).toLocaleLowerCase(); 1399 this._shortWeekdaysParse[i] = this.weekdaysShort( 1400 mom, 1401 '' 1402 ).toLocaleLowerCase(); 1403 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase(); 1404 } 1405 } 1406 1407 if (strict) { 1408 if (format === 'dddd') { 1409 ii = indexOf.call(this._weekdaysParse, llc); 1410 return ii !== -1 ? ii : null; 1411 } else if (format === 'ddd') { 1412 ii = indexOf.call(this._shortWeekdaysParse, llc); 1413 return ii !== -1 ? ii : null; 1414 } else { 1415 ii = indexOf.call(this._minWeekdaysParse, llc); 1416 return ii !== -1 ? ii : null; 1417 } 1418 } else { 1419 if (format === 'dddd') { 1420 ii = indexOf.call(this._weekdaysParse, llc); 1421 if (ii !== -1) { 1422 return ii; 1423 } 1424 ii = indexOf.call(this._shortWeekdaysParse, llc); 1425 if (ii !== -1) { 1426 return ii; 1427 } 1428 ii = indexOf.call(this._minWeekdaysParse, llc); 1429 return ii !== -1 ? ii : null; 1430 } else if (format === 'ddd') { 1431 ii = indexOf.call(this._shortWeekdaysParse, llc); 1432 if (ii !== -1) { 1433 return ii; 1434 } 1435 ii = indexOf.call(this._weekdaysParse, llc); 1436 if (ii !== -1) { 1437 return ii; 1438 } 1439 ii = indexOf.call(this._minWeekdaysParse, llc); 1440 return ii !== -1 ? ii : null; 1441 } else { 1442 ii = indexOf.call(this._minWeekdaysParse, llc); 1443 if (ii !== -1) { 1444 return ii; 1445 } 1446 ii = indexOf.call(this._weekdaysParse, llc); 1447 if (ii !== -1) { 1448 return ii; 1449 } 1450 ii = indexOf.call(this._shortWeekdaysParse, llc); 1451 return ii !== -1 ? ii : null; 1452 } 1453 } 1454 } 1455 1456 function localeWeekdaysParse(weekdayName, format, strict) { 1457 var i, mom, regex; 1458 1459 if (this._weekdaysParseExact) { 1460 return handleStrictParse.call(this, weekdayName, format, strict); 1461 } 1462 1463 if (!this._weekdaysParse) { 1464 this._weekdaysParse = []; 1465 this._minWeekdaysParse = []; 1466 this._shortWeekdaysParse = []; 1467 this._fullWeekdaysParse = []; 1468 } 1469 1470 for (i = 0; i < 7; i++) { 1471 // make the regex if we don't have it already 1472 1473 mom = createUTC([2000, 1]).day(i); 1474 if (strict && !this._fullWeekdaysParse[i]) { 1475 this._fullWeekdaysParse[i] = new RegExp( 1476 '^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 1477 'i' 1478 ); 1479 this._shortWeekdaysParse[i] = new RegExp( 1480 '^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 1481 'i' 1482 ); 1483 this._minWeekdaysParse[i] = new RegExp( 1484 '^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 1485 'i' 1486 ); 1487 } 1488 if (!this._weekdaysParse[i]) { 1489 regex = 1490 '^' + 1491 this.weekdays(mom, '') + 1492 '|^' + 1493 this.weekdaysShort(mom, '') + 1494 '|^' + 1495 this.weekdaysMin(mom, ''); 1496 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i'); 1497 } 1498 // test the regex 1499 if ( 1500 strict && 1501 format === 'dddd' && 1502 this._fullWeekdaysParse[i].test(weekdayName) 1503 ) { 1504 return i; 1505 } else if ( 1506 strict && 1507 format === 'ddd' && 1508 this._shortWeekdaysParse[i].test(weekdayName) 1509 ) { 1510 return i; 1511 } else if ( 1512 strict && 1513 format === 'dd' && 1514 this._minWeekdaysParse[i].test(weekdayName) 1515 ) { 1516 return i; 1517 } else if (!strict && this._weekdaysParse[i].test(weekdayName)) { 1518 return i; 1519 } 1520 } 1521 } 1522 1523 // MOMENTS 1524 1525 function getSetDayOfWeek(input) { 1526 if (!this.isValid()) { 1527 return input != null ? this : NaN; 1528 } 1529 1530 var day = get$2(this, 'Day'); 1531 if (input != null) { 1532 input = parseWeekday(input, this.localeData()); 1533 return this.add(input - day, 'd'); 1534 } else { 1535 return day; 1536 } 1537 } 1538 1539 function getSetLocaleDayOfWeek(input) { 1540 if (!this.isValid()) { 1541 return input != null ? this : NaN; 1542 } 1543 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7; 1544 return input == null ? weekday : this.add(input - weekday, 'd'); 1545 } 1546 1547 function getSetISODayOfWeek(input) { 1548 if (!this.isValid()) { 1549 return input != null ? this : NaN; 1550 } 1551 1552 // behaves the same as moment#day except 1553 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6) 1554 // as a setter, sunday should belong to the previous week. 1555 1556 if (input != null) { 1557 var weekday = parseIsoWeekday(input, this.localeData()); 1558 return this.day(this.day() % 7 ? weekday : weekday - 7); 1559 } else { 1560 return this.day() || 7; 1561 } 1562 } 1563 1564 function weekdaysRegex(isStrict) { 1565 if (this._weekdaysParseExact) { 1566 if (!hasOwnProp(this, '_weekdaysRegex')) { 1567 computeWeekdaysParse.call(this); 1568 } 1569 if (isStrict) { 1570 return this._weekdaysStrictRegex; 1571 } else { 1572 return this._weekdaysRegex; 1573 } 1574 } else { 1575 if (!hasOwnProp(this, '_weekdaysRegex')) { 1576 this._weekdaysRegex = defaultWeekdaysRegex; 1577 } 1578 return this._weekdaysStrictRegex && isStrict 1579 ? this._weekdaysStrictRegex 1580 : this._weekdaysRegex; 1581 } 1582 } 1583 1584 function weekdaysShortRegex(isStrict) { 1585 if (this._weekdaysParseExact) { 1586 if (!hasOwnProp(this, '_weekdaysRegex')) { 1587 computeWeekdaysParse.call(this); 1588 } 1589 if (isStrict) { 1590 return this._weekdaysShortStrictRegex; 1591 } else { 1592 return this._weekdaysShortRegex; 1593 } 1594 } else { 1595 if (!hasOwnProp(this, '_weekdaysShortRegex')) { 1596 this._weekdaysShortRegex = defaultWeekdaysShortRegex; 1597 } 1598 return this._weekdaysShortStrictRegex && isStrict 1599 ? this._weekdaysShortStrictRegex 1600 : this._weekdaysShortRegex; 1601 } 1602 } 1603 1604 function weekdaysMinRegex(isStrict) { 1605 if (this._weekdaysParseExact) { 1606 if (!hasOwnProp(this, '_weekdaysRegex')) { 1607 computeWeekdaysParse.call(this); 1608 } 1609 if (isStrict) { 1610 return this._weekdaysMinStrictRegex; 1611 } else { 1612 return this._weekdaysMinRegex; 1613 } 1614 } else { 1615 if (!hasOwnProp(this, '_weekdaysMinRegex')) { 1616 this._weekdaysMinRegex = defaultWeekdaysMinRegex; 1617 } 1618 return this._weekdaysMinStrictRegex && isStrict 1619 ? this._weekdaysMinStrictRegex 1620 : this._weekdaysMinRegex; 1621 } 1622 } 1623 1624 function computeWeekdaysParse() { 1625 function cmpLenRev(a, b) { 1626 return b.length - a.length; 1627 } 1628 1629 var minPieces = [], 1630 shortPieces = [], 1631 longPieces = [], 1632 mixedPieces = [], 1633 i, 1634 mom, 1635 minp, 1636 shortp, 1637 longp; 1638 for (i = 0; i < 7; i++) { 1639 // make the regex if we don't have it already 1640 mom = createUTC([2000, 1]).day(i); 1641 minp = regexEscape(this.weekdaysMin(mom, '')); 1642 shortp = regexEscape(this.weekdaysShort(mom, '')); 1643 longp = regexEscape(this.weekdays(mom, '')); 1644 minPieces.push(minp); 1645 shortPieces.push(shortp); 1646 longPieces.push(longp); 1647 mixedPieces.push(minp); 1648 mixedPieces.push(shortp); 1649 mixedPieces.push(longp); 1650 } 1651 // Sorting makes sure if one weekday (or abbr) is a prefix of another it 1652 // will match the longer piece. 1653 minPieces.sort(cmpLenRev); 1654 shortPieces.sort(cmpLenRev); 1655 longPieces.sort(cmpLenRev); 1656 mixedPieces.sort(cmpLenRev); 1657 1658 this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); 1659 this._weekdaysShortRegex = this._weekdaysRegex; 1660 this._weekdaysMinRegex = this._weekdaysRegex; 1661 1662 this._weekdaysStrictRegex = new RegExp( 1663 '^(' + longPieces.join('|') + ')', 1664 'i' 1665 ); 1666 this._weekdaysShortStrictRegex = new RegExp( 1667 '^(' + shortPieces.join('|') + ')', 1668 'i' 1669 ); 1670 this._weekdaysMinStrictRegex = new RegExp( 1671 '^(' + minPieces.join('|') + ')', 1672 'i' 1673 ); 1674 } 1675 1676 function set(config) { 1677 var prop, i; 1678 clearMonthsParseCache(this, config); 1679 clearWeekdaysParseCache(this, config); 1680 for (i in config) { 1681 if (hasOwnProp(config, i)) { 1682 prop = config[i]; 1683 if (isFunction(prop)) { 1684 this[i] = prop; 1685 } else { 1686 this['_' + i] = prop; 1687 } 1688 } 1689 } 1690 this._config = config; 1691 // Lenient ordinal parsing accepts just a number in addition to 1692 // number + (possibly) stuff coming from _dayOfMonthOrdinalParse. 1693 // TODO: Remove "ordinalParse" fallback in next major release. 1694 this._dayOfMonthOrdinalParseLenient = new RegExp( 1695 (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) + 1696 '|' + 1697 /\d{1,2}/.source 1698 ); 1699 } 1700 1701 function mergeConfigs(parentConfig, childConfig) { 1702 var res = extend({}, parentConfig), 1703 prop; 1704 for (prop in childConfig) { 1705 if (hasOwnProp(childConfig, prop)) { 1706 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) { 1707 res[prop] = {}; 1708 extend(res[prop], parentConfig[prop]); 1709 extend(res[prop], childConfig[prop]); 1710 } else if (childConfig[prop] != null) { 1711 res[prop] = childConfig[prop]; 1712 } else { 1713 delete res[prop]; 1714 } 1715 } 1716 } 1717 for (prop in parentConfig) { 1718 if ( 1719 hasOwnProp(parentConfig, prop) && 1720 !hasOwnProp(childConfig, prop) && 1721 isObject(parentConfig[prop]) 1722 ) { 1723 // make sure changes to properties don't modify parent config 1724 res[prop] = extend({}, res[prop]); 1725 } 1726 } 1727 return res; 1728 } 1729 1730 function Locale(config) { 1731 if (config != null) { 1732 this.set(config); 1733 } 1734 } 1735 1736 var keys; 1737 1738 if (Object.keys) { 1739 keys = Object.keys; 1740 } else { 1741 keys = function (obj) { 1742 var i, 1743 res = []; 1744 for (i in obj) { 1745 if (hasOwnProp(obj, i)) { 1746 res.push(i); 1747 } 1748 } 1749 return res; 1750 }; 1751 } 1752 1753 var defaultCalendar = { 1754 sameDay: '[Today at] LT', 1755 nextDay: '[Tomorrow at] LT', 1756 nextWeek: 'dddd [at] LT', 1757 lastDay: '[Yesterday at] LT', 1758 lastWeek: '[Last] dddd [at] LT', 1759 sameElse: 'L', 1760 }; 1761 1762 function calendar$1(key, mom, now) { 1763 var output = this._calendar[key] || this._calendar['sameElse']; 1764 return isFunction(output) ? output.call(mom, now) : output; 1765 } 1766 1767 var defaultLongDateFormat = { 1768 LTS: 'h:mm:ss A', 1769 LT: 'h:mm A', 1770 L: 'MM/DD/YYYY', 1771 LL: 'MMMM D, YYYY', 1772 LLL: 'MMMM D, YYYY h:mm A', 1773 LLLL: 'dddd, MMMM D, YYYY h:mm A', 1774 }; 1775 1776 function longDateFormat(key) { 1777 var format = this._longDateFormat[key], 1778 formatUpper = this._longDateFormat[key.toUpperCase()], 1779 formatCache = this._longDateFormatCache; 1780 1781 if (format || !formatUpper) { 1782 return format; 1783 } 1784 1785 if ( 1786 formatCache && 1787 formatCache[key] && 1788 formatCache[key].formatUpper === formatUpper 1789 ) { 1790 return formatCache[key].format; 1791 } 1792 1793 format = formatUpper 1794 .match(formattingTokens) 1795 .map(function (tok) { 1796 if ( 1797 tok === 'MMMM' || 1798 tok === 'MM' || 1799 tok === 'DD' || 1800 tok === 'dddd' 1801 ) { 1802 return tok.slice(1); 1803 } 1804 return tok; 1805 }) 1806 .join(''); 1807 1808 if (!formatCache) { 1809 formatCache = this._longDateFormatCache = {}; 1810 } 1811 formatCache[key] = { 1812 formatUpper: formatUpper, 1813 format: format, 1814 }; 1815 return format; 1816 } 1817 1818 var defaultInvalidDate = 'Invalid date'; 1819 1820 function invalidDate() { 1821 return this._invalidDate; 1822 } 1823 1824 var defaultOrdinal = '%d', 1825 defaultDayOfMonthOrdinalParse = /\d{1,2}/; 1826 1827 function ordinal(number) { 1828 return this._ordinal.replace('%d', number); 1829 } 1830 1831 var defaultRelativeTime = { 1832 future: 'in %s', 1833 past: '%s ago', 1834 s: 'a few seconds', 1835 ss: '%d seconds', 1836 m: 'a minute', 1837 mm: '%d minutes', 1838 h: 'an hour', 1839 hh: '%d hours', 1840 d: 'a day', 1841 dd: '%d days', 1842 w: 'a week', 1843 ww: '%d weeks', 1844 M: 'a month', 1845 MM: '%d months', 1846 y: 'a year', 1847 yy: '%d years', 1848 }; 1849 1850 function relativeTimeWithoutPostformat( 1851 number, 1852 withoutSuffix, 1853 string, 1854 isFuture 1855 ) { 1856 var output = this._relativeTime[string]; 1857 return isFunction(output) 1858 ? output(number, withoutSuffix, string, isFuture) 1859 : output.replace(/%d/i, number); 1860 } 1861 1862 function relativeTime$1(number, withoutSuffix, string, isFuture) { 1863 return this.postformat( 1864 relativeTimeWithoutPostformat.call( 1865 this, 1866 number, 1867 withoutSuffix, 1868 string, 1869 isFuture 1870 ) 1871 ); 1872 } 1873 1874 function pastFutureWithoutPostformat(diff, output) { 1875 var format = this._relativeTime[diff > 0 ? 'future' : 'past']; 1876 return isFunction(format) ? format(output) : format.replace(/%s/i, output); 1877 } 1878 1879 function pastFuture(diff, output) { 1880 return this.postformat( 1881 pastFutureWithoutPostformat.call(this, diff, output) 1882 ); 1883 } 1884 1885 function createDate(y, m, d, h, M, s, ms) { 1886 // can't just apply() to create a date: 1887 // https://stackoverflow.com/q/181348 1888 var date; 1889 // the date constructor remaps years 0-99 to 1900-1999 1890 if (y < 100 && y >= 0) { 1891 // preserve leap years using a full 400 year cycle, then reset 1892 date = new Date(y + 400, m, d, h, M, s, ms); 1893 if (isFinite(date.getFullYear())) { 1894 date.setFullYear(y); 1895 } 1896 } else { 1897 date = new Date(y, m, d, h, M, s, ms); 1898 } 1899 1900 return date; 1901 } 1902 1903 function createUTCDate(y) { 1904 var date, args; 1905 // the Date.UTC function remaps years 0-99 to 1900-1999 1906 if (y < 100 && y >= 0) { 1907 args = Array.prototype.slice.call(arguments); 1908 // preserve leap years using a full 400 year cycle, then reset 1909 args[0] = y + 400; 1910 date = new Date(Date.UTC.apply(null, args)); 1911 if (isFinite(date.getUTCFullYear())) { 1912 date.setUTCFullYear(y); 1913 } 1914 } else { 1915 date = new Date(Date.UTC.apply(null, arguments)); 1916 } 1917 1918 return date; 1919 } 1920 1921 // start-of-first-week - start-of-year 1922 function firstWeekOffset(year, dow, doy) { 1923 var // first-week day -- which january is always in the first week (4 for iso, 1 for other) 1924 fwd = 7 + dow - doy, 1925 // first-week day local weekday -- which local weekday is fwd 1926 fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7; 1927 1928 return -fwdlw + fwd - 1; 1929 } 1930 1931 // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday 1932 function dayOfYearFromWeeks(year, week, weekday, dow, doy) { 1933 var localWeekday = (7 + weekday - dow) % 7, 1934 weekOffset = firstWeekOffset(year, dow, doy), 1935 dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset, 1936 resYear, 1937 resDayOfYear; 1938 1939 if (dayOfYear <= 0) { 1940 resYear = year - 1; 1941 resDayOfYear = daysInYear(resYear) + dayOfYear; 1942 } else if (dayOfYear > daysInYear(year)) { 1943 resYear = year + 1; 1944 resDayOfYear = dayOfYear - daysInYear(year); 1945 } else { 1946 resYear = year; 1947 resDayOfYear = dayOfYear; 1948 } 1949 1950 return { 1951 year: resYear, 1952 dayOfYear: resDayOfYear, 1953 }; 1954 } 1955 1956 function weekOfYearFromDayOfYear(year, dayOfYear, dow, doy) { 1957 var weekOffset = firstWeekOffset(year, dow, doy), 1958 week = Math.floor((dayOfYear - weekOffset - 1) / 7) + 1, 1959 resWeek, 1960 resYear; 1961 1962 if (week < 1) { 1963 resYear = year - 1; 1964 resWeek = week + weeksInYear(resYear, dow, doy); 1965 } else if (week > weeksInYear(year, dow, doy)) { 1966 resWeek = week - weeksInYear(year, dow, doy); 1967 resYear = year + 1; 1968 } else { 1969 resYear = year; 1970 resWeek = week; 1971 } 1972 1973 return { 1974 week: resWeek, 1975 year: resYear, 1976 }; 1977 } 1978 1979 function weekOfYear(mom, dow, doy) { 1980 return weekOfYearFromDayOfYear(mom.year(), mom.dayOfYear(), dow, doy); 1981 } 1982 1983 function weekOfYearFromDate(year, month, date, dow, doy) { 1984 var dayOfYear = 1985 Math.round( 1986 (createUTCDate(year, month, date) - createUTCDate(year, 0, 1)) / 1987 864e5 1988 ) + 1; 1989 1990 return weekOfYearFromDayOfYear(year, dayOfYear, dow, doy); 1991 } 1992 1993 function weeksInYear(year, dow, doy) { 1994 var weekOffset = firstWeekOffset(year, dow, doy), 1995 weekOffsetNext = firstWeekOffset(year + 1, dow, doy); 1996 return (daysInYear(year) - weekOffset + weekOffsetNext) / 7; 1997 } 1998 1999 // FORMATTING 2000 2001 addFormatToken('w', ['ww', 2], 'wo', 'week'); 2002 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); 2003 2004 // PARSING 2005 2006 addRegexToken('w', match1to2, match1to2NoLeadingZero); 2007 addRegexToken('ww', match1to2, match2); 2008 addRegexToken('W', match1to2, match1to2NoLeadingZero); 2009 addRegexToken('WW', match1to2, match2); 2010 2011 addWeekParseToken( 2012 ['w', 'ww', 'W', 'WW'], 2013 function (input, week, config, token) { 2014 week[token.substr(0, 1)] = toInt(input); 2015 } 2016 ); 2017 2018 // HELPERS 2019 2020 // LOCALES 2021 2022 function localeWeek(mom) { 2023 return weekOfYear(mom, this._week.dow, this._week.doy).week; 2024 } 2025 2026 var defaultLocaleWeek = { 2027 dow: 0, // Sunday is the first day of the week. 2028 doy: 6, // The week that contains Jan 6th is the first week of the year. 2029 }; 2030 2031 function localeFirstDayOfWeek() { 2032 return this._week.dow; 2033 } 2034 2035 function localeFirstDayOfYear() { 2036 return this._week.doy; 2037 } 2038 2039 // MOMENTS 2040 2041 function getSetWeek(input) { 2042 var week = this.localeData().week(this); 2043 return input == null ? week : this.add((input - week) * 7, 'd'); 2044 } 2045 2046 function getSetISOWeek(input) { 2047 var week = weekOfYear(this, 1, 4).week; 2048 return input == null ? week : this.add((input - week) * 7, 'd'); 2049 } 2050 2051 // FORMATTING 2052 2053 function hFormat() { 2054 return this.hours() % 12 || 12; 2055 } 2056 2057 function kFormat() { 2058 return this.hours() || 24; 2059 } 2060 2061 addFormatToken('H', ['HH', 2], 0, 'hour'); 2062 addFormatToken('h', ['hh', 2], 0, hFormat); 2063 addFormatToken('k', ['kk', 2], 0, kFormat); 2064 2065 addFormatToken('hmm', 0, 0, function () { 2066 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2); 2067 }); 2068 2069 addFormatToken('hmmss', 0, 0, function () { 2070 return ( 2071 '' + 2072 hFormat.apply(this) + 2073 zeroFill(this.minutes(), 2) + 2074 zeroFill(this.seconds(), 2) 2075 ); 2076 }); 2077 2078 addFormatToken('Hmm', 0, 0, function () { 2079 return '' + this.hours() + zeroFill(this.minutes(), 2); 2080 }); 2081 2082 addFormatToken('Hmmss', 0, 0, function () { 2083 return ( 2084 '' + 2085 this.hours() + 2086 zeroFill(this.minutes(), 2) + 2087 zeroFill(this.seconds(), 2) 2088 ); 2089 }); 2090 2091 function meridiem(token, lowercase) { 2092 addFormatToken(token, 0, 0, function () { 2093 return this.localeData().meridiem( 2094 this.hours(), 2095 this.minutes(), 2096 lowercase 2097 ); 2098 }); 2099 } 2100 2101 meridiem('a', true); 2102 meridiem('A', false); 2103 2104 // PARSING 2105 2106 function matchMeridiem(isStrict, locale) { 2107 return locale._meridiemParse; 2108 } 2109 2110 addRegexToken('a', matchMeridiem); 2111 addRegexToken('A', matchMeridiem); 2112 addRegexToken('H', match1to2, match1to2HasZero); 2113 addRegexToken('h', match1to2, match1to2NoLeadingZero); 2114 addRegexToken('k', match1to2, match1to2NoLeadingZero); 2115 addRegexToken('HH', match1to2, match2); 2116 addRegexToken('hh', match1to2, match2); 2117 addRegexToken('kk', match1to2, match2); 2118 2119 addRegexToken('hmm', match3to4); 2120 addRegexToken('hmmss', match5to6); 2121 addRegexToken('Hmm', match3to4); 2122 addRegexToken('Hmmss', match5to6); 2123 2124 addParseToken(['H', 'HH'], HOUR); 2125 addParseToken(['k', 'kk'], function (input, array, config) { 2126 var kInput = toInt(input); 2127 array[HOUR] = kInput === 24 ? 0 : kInput; 2128 }); 2129 addParseToken(['a', 'A'], function (input, array, config) { 2130 config._isPm = config._locale.isPM(input); 2131 config._meridiem = input; 2132 }); 2133 addParseToken(['h', 'hh'], function (input, array, config) { 2134 array[HOUR] = toInt(input); 2135 getParsingFlags(config).bigHour = true; 2136 }); 2137 addParseToken('hmm', function (input, array, config) { 2138 var pos = input.length - 2; 2139 array[HOUR] = toInt(input.substr(0, pos)); 2140 array[MINUTE] = toInt(input.substr(pos)); 2141 getParsingFlags(config).bigHour = true; 2142 }); 2143 addParseToken('hmmss', function (input, array, config) { 2144 var pos1 = input.length - 4, 2145 pos2 = input.length - 2; 2146 array[HOUR] = toInt(input.substr(0, pos1)); 2147 array[MINUTE] = toInt(input.substr(pos1, 2)); 2148 array[SECOND] = toInt(input.substr(pos2)); 2149 getParsingFlags(config).bigHour = true; 2150 }); 2151 addParseToken('Hmm', function (input, array, config) { 2152 var pos = input.length - 2; 2153 array[HOUR] = toInt(input.substr(0, pos)); 2154 array[MINUTE] = toInt(input.substr(pos)); 2155 }); 2156 addParseToken('Hmmss', function (input, array, config) { 2157 var pos1 = input.length - 4, 2158 pos2 = input.length - 2; 2159 array[HOUR] = toInt(input.substr(0, pos1)); 2160 array[MINUTE] = toInt(input.substr(pos1, 2)); 2161 array[SECOND] = toInt(input.substr(pos2)); 2162 }); 2163 2164 // LOCALES 2165 2166 function localeIsPM(input) { 2167 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays 2168 // Using charAt should be more compatible. 2169 return (input + '').toLowerCase().charAt(0) === 'p'; 2170 } 2171 2172 var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i, 2173 // Setting the hour should keep the time, because the user explicitly 2174 // specified which hour they want. So trying to maintain the same hour (in 2175 // a new timezone) makes sense. Adding/subtracting hours does not follow 2176 // this rule. 2177 getSetHour = makeGetSet('Hours', true); 2178 2179 function localeMeridiem(hours, minutes, isLower) { 2180 if (hours > 11) { 2181 return isLower ? 'pm' : 'PM'; 2182 } else { 2183 return isLower ? 'am' : 'AM'; 2184 } 2185 } 2186 2187 var baseConfig = { 2188 calendar: defaultCalendar, 2189 longDateFormat: defaultLongDateFormat, 2190 invalidDate: defaultInvalidDate, 2191 ordinal: defaultOrdinal, 2192 dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse, 2193 relativeTime: defaultRelativeTime, 2194 2195 months: defaultLocaleMonths, 2196 monthsShort: defaultLocaleMonthsShort, 2197 2198 week: defaultLocaleWeek, 2199 2200 weekdays: defaultLocaleWeekdays, 2201 weekdaysMin: defaultLocaleWeekdaysMin, 2202 weekdaysShort: defaultLocaleWeekdaysShort, 2203 2204 meridiemParse: defaultLocaleMeridiemParse, 2205 }; 2206 2207 // internal storage for locale config files 2208 var locales = {}, 2209 localeFamilies = {}, 2210 globalLocale; 2211 2212 function commonPrefix(arr1, arr2) { 2213 var i, 2214 minl = Math.min(arr1.length, arr2.length); 2215 for (i = 0; i < minl; i += 1) { 2216 if (arr1[i] !== arr2[i]) { 2217 return i; 2218 } 2219 } 2220 return minl; 2221 } 2222 2223 function normalizeLocale(key) { 2224 return key ? key.toLowerCase().replace('_', '-') : key; 2225 } 2226 2227 // pick the locale from the array 2228 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each 2229 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root 2230 function chooseLocale(names) { 2231 var i = 0, 2232 j, 2233 next, 2234 locale, 2235 split; 2236 2237 while (i < names.length) { 2238 split = normalizeLocale(names[i]).split('-'); 2239 j = split.length; 2240 next = normalizeLocale(names[i + 1]); 2241 next = next ? next.split('-') : null; 2242 while (j > 0) { 2243 locale = loadLocale(split.slice(0, j).join('-')); 2244 if (locale) { 2245 return locale; 2246 } 2247 if ( 2248 next && 2249 next.length >= j && 2250 commonPrefix(split, next) >= j - 1 2251 ) { 2252 //the next array item is better than a shallower substring of this one 2253 break; 2254 } 2255 j--; 2256 } 2257 i++; 2258 } 2259 return globalLocale; 2260 } 2261 2262 function isLocaleNameSane(name) { 2263 // Only canonical locale module names are safe to append to the require path. 2264 return typeof name === 'string' && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name); 2265 } 2266 2267 function loadLocale(name) { 2268 var oldLocale = null, 2269 aliasedRequire, 2270 normalizedName; 2271 2272 // Preserve exact custom locale names before trying the canonical built-in name. 2273 // Use hasOwnProp rather than a plain lookup so that names like "__proto__", 2274 // "constructor", or "prototype" can't resolve to an inherited Object.prototype 2275 // property instead of a real (or missing) locale entry. 2276 if (hasOwnProp(locales, name)) { 2277 return locales[name]; 2278 } 2279 2280 normalizedName = normalizeLocale(name); 2281 if (hasOwnProp(locales, normalizedName)) { 2282 return locales[normalizedName]; 2283 } 2284 2285 // TODO: Find a better way to register and load all the locales in Node 2286 if ( 2287 typeof module !== 'undefined' && 2288 module && 2289 module.exports && 2290 isLocaleNameSane(normalizedName) 2291 ) { 2292 try { 2293 oldLocale = globalLocale._abbr; 2294 aliasedRequire = require; 2295 aliasedRequire('./locale/' + normalizedName); 2296 getSetGlobalLocale(oldLocale); 2297 } catch (e) { 2298 // mark as not found to avoid repeating expensive file require call causing high CPU 2299 // when trying to find en-US, en_US, en-us for every format call 2300 locales[normalizedName] = null; // null means not found 2301 } 2302 } 2303 if (hasOwnProp(locales, normalizedName)) { 2304 return locales[normalizedName]; 2305 } 2306 } 2307 2308 // This function will load locale and then set the global locale. If 2309 // no arguments are passed in, it will simply return the current global 2310 // locale key. 2311 function getSetGlobalLocale(key, values) { 2312 var data; 2313 if (key) { 2314 if (isUndefined(values)) { 2315 data = getLocale(key); 2316 } else { 2317 data = defineLocale(key, values); 2318 } 2319 2320 if (data) { 2321 // moment.duration._locale = moment._locale = data; 2322 globalLocale = data; 2323 } else { 2324 if (typeof console !== 'undefined' && console.warn) { 2325 //warn user if arguments are passed but the locale could not be set 2326 console.warn( 2327 'Locale ' + key + ' not found. Did you forget to load it?' 2328 ); 2329 } 2330 } 2331 } 2332 2333 return globalLocale._abbr; 2334 } 2335 2336 function defineLocale(name, config) { 2337 if (config !== null) { 2338 var locale, 2339 parentConfig = baseConfig; 2340 config.abbr = name; 2341 if (locales[name] != null) { 2342 deprecateSimple( 2343 'defineLocaleOverride', 2344 'use moment.updateLocale(localeName, config) to change ' + 2345 'an existing locale. moment.defineLocale(localeName, ' + 2346 'config) should only be used for creating a new locale ' + 2347 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.' 2348 ); 2349 parentConfig = locales[name]._config; 2350 } else if (config.parentLocale != null) { 2351 if (locales[config.parentLocale] != null) { 2352 parentConfig = locales[config.parentLocale]._config; 2353 } else { 2354 locale = loadLocale(config.parentLocale); 2355 if (locale != null) { 2356 parentConfig = locale._config; 2357 } else { 2358 if (!localeFamilies[config.parentLocale]) { 2359 localeFamilies[config.parentLocale] = []; 2360 } 2361 localeFamilies[config.parentLocale].push({ 2362 name: name, 2363 config: config, 2364 }); 2365 return null; 2366 } 2367 } 2368 } 2369 locales[name] = new Locale(mergeConfigs(parentConfig, config)); 2370 2371 if (localeFamilies[name]) { 2372 localeFamilies[name].forEach(function (x) { 2373 defineLocale(x.name, x.config); 2374 }); 2375 } 2376 2377 // backwards compat for now: also set the locale 2378 // make sure we set the locale AFTER all child locales have been 2379 // created, so we won't end up with the child locale set. 2380 getSetGlobalLocale(name); 2381 2382 return locales[name]; 2383 } else { 2384 // useful for testing 2385 delete locales[name]; 2386 return null; 2387 } 2388 } 2389 2390 function updateLocale(name, config) { 2391 var locale, 2392 tmpLocale = loadLocale(name), 2393 parentConfig = baseConfig; 2394 2395 if (tmpLocale != null) { 2396 name = tmpLocale._abbr; 2397 } 2398 2399 if (config != null) { 2400 if (locales[name] != null && locales[name].parentLocale != null) { 2401 // Update existing child locale in-place to avoid memory-leaks 2402 locales[name].set(mergeConfigs(locales[name]._config, config)); 2403 } else { 2404 // MERGE 2405 if (tmpLocale != null) { 2406 parentConfig = tmpLocale._config; 2407 } 2408 config = mergeConfigs(parentConfig, config); 2409 if (tmpLocale == null) { 2410 // updateLocale is called for creating a new locale 2411 // Set abbr so it will have a name (getters return 2412 // undefined otherwise). 2413 config.abbr = name; 2414 } 2415 locale = new Locale(config); 2416 locale.parentLocale = locales[name]; 2417 locales[name] = locale; 2418 } 2419 2420 // backwards compat for now: also set the locale 2421 getSetGlobalLocale(name); 2422 } else { 2423 // pass null for config to unupdate, useful for tests 2424 if (locales[name] != null) { 2425 if (locales[name].parentLocale != null) { 2426 locales[name] = locales[name].parentLocale; 2427 if (name === getSetGlobalLocale()) { 2428 getSetGlobalLocale(name); 2429 } 2430 } else if (locales[name] != null) { 2431 delete locales[name]; 2432 } 2433 } 2434 } 2435 return locales[name]; 2436 } 2437 2438 // returns locale data 2439 function getLocale(key) { 2440 var locale; 2441 2442 if (key && key._locale && key._locale._abbr) { 2443 key = key._locale._abbr; 2444 } 2445 2446 if (!key) { 2447 return globalLocale; 2448 } 2449 2450 if (!isArray(key)) { 2451 //short-circuit everything else 2452 locale = loadLocale(key); 2453 if (locale) { 2454 return locale; 2455 } 2456 key = [key]; 2457 } 2458 2459 return chooseLocale(key); 2460 } 2461 2462 function listLocales() { 2463 return keys(locales); 2464 } 2465 2466 function checkOverflow(m) { 2467 var overflow, 2468 a = m._a; 2469 2470 if (a && getParsingFlags(m).overflow === -2) { 2471 overflow = 2472 a[MONTH] < 0 || a[MONTH] > 11 2473 ? MONTH 2474 : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) 2475 ? DATE 2476 : a[HOUR] < 0 || 2477 a[HOUR] > 24 || 2478 (a[HOUR] === 24 && 2479 (a[MINUTE] !== 0 || 2480 a[SECOND] !== 0 || 2481 a[MILLISECOND] !== 0)) 2482 ? HOUR 2483 : a[MINUTE] < 0 || a[MINUTE] > 59 2484 ? MINUTE 2485 : a[SECOND] < 0 || a[SECOND] > 59 2486 ? SECOND 2487 : a[MILLISECOND] < 0 || a[MILLISECOND] > 999 2488 ? MILLISECOND 2489 : -1; 2490 2491 if ( 2492 getParsingFlags(m)._overflowDayOfYear && 2493 (overflow < YEAR || overflow > DATE) 2494 ) { 2495 overflow = DATE; 2496 } 2497 if (getParsingFlags(m)._overflowWeeks && overflow === -1) { 2498 overflow = WEEK; 2499 } 2500 if (getParsingFlags(m)._overflowWeekday && overflow === -1) { 2501 overflow = WEEKDAY; 2502 } 2503 2504 getParsingFlags(m).overflow = overflow; 2505 } 2506 2507 return m; 2508 } 2509 2510 // iso 8601 regex 2511 // 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) 2512 var extendedIsoRegex = 2513 /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/, 2514 basicIsoRegex = 2515 /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/, 2516 tzRegex = /Z|[+-]\d\d(?::?\d\d)?/, 2517 isoDates = [ 2518 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/], 2519 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/], 2520 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/], 2521 ['GGGG-[W]WW', /\d{4}-W\d\d/, false], 2522 ['YYYY-DDD', /\d{4}-\d{3}/], 2523 ['YYYY-MM', /\d{4}-\d\d/, false], 2524 ['YYYYYYMMDD', /[+-]\d{10}/], 2525 ['YYYYMMDD', /\d{8}/], 2526 ['GGGG[W]WWE', /\d{4}W\d{3}/], 2527 ['GGGG[W]WW', /\d{4}W\d{2}/, false], 2528 ['YYYYDDD', /\d{7}/], 2529 ['YYYYMM', /\d{6}/, false], 2530 ['YYYY', /\d{4}/, false], 2531 ], 2532 // iso time formats and regexes 2533 isoTimes = [ 2534 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/], 2535 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/], 2536 ['HH:mm:ss', /\d\d:\d\d:\d\d/], 2537 ['HH:mm', /\d\d:\d\d/], 2538 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/], 2539 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/], 2540 ['HHmmss', /\d\d\d\d\d\d/], 2541 ['HHmm', /\d\d\d\d/], 2542 ['HH', /\d\d/], 2543 ], 2544 aspNetJsonRegex = /^\/?Date\((-?\d+)/i, 2545 // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3 2546 rfc2822 = 2547 /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/, 2548 obsOffsets = { 2549 UT: 0, 2550 GMT: 0, 2551 EDT: -4 * 60, 2552 EST: -5 * 60, 2553 CDT: -5 * 60, 2554 CST: -6 * 60, 2555 MDT: -6 * 60, 2556 MST: -7 * 60, 2557 PDT: -7 * 60, 2558 PST: -8 * 60, 2559 }; 2560 2561 // date from iso format 2562 function configFromISO(config) { 2563 var i, 2564 l, 2565 string = config._i, 2566 match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string), 2567 allowTime, 2568 dateFormat, 2569 timeFormat, 2570 tzFormat, 2571 isoDatesLen = isoDates.length, 2572 isoTimesLen = isoTimes.length; 2573 2574 if (match) { 2575 getParsingFlags(config).iso = true; 2576 for (i = 0, l = isoDatesLen; i < l; i++) { 2577 if (isoDates[i][1].exec(match[1])) { 2578 dateFormat = isoDates[i][0]; 2579 allowTime = isoDates[i][2] !== false; 2580 break; 2581 } 2582 } 2583 if (dateFormat == null) { 2584 config._isValid = false; 2585 return; 2586 } 2587 if (match[3]) { 2588 for (i = 0, l = isoTimesLen; i < l; i++) { 2589 if (isoTimes[i][1].exec(match[3])) { 2590 // match[2] should be 'T' or space 2591 timeFormat = (match[2] || ' ') + isoTimes[i][0]; 2592 break; 2593 } 2594 } 2595 if (timeFormat == null) { 2596 config._isValid = false; 2597 return; 2598 } 2599 } 2600 if (!allowTime && timeFormat != null) { 2601 config._isValid = false; 2602 return; 2603 } 2604 if (match[4]) { 2605 if (tzRegex.exec(match[4])) { 2606 tzFormat = 'Z'; 2607 } else { 2608 config._isValid = false; 2609 return; 2610 } 2611 } 2612 config._f = dateFormat + (timeFormat || '') + (tzFormat || ''); 2613 configFromStringAndFormat(config); 2614 } else { 2615 config._isValid = false; 2616 } 2617 } 2618 2619 function extractFromRFC2822Strings( 2620 yearStr, 2621 monthStr, 2622 dayStr, 2623 hourStr, 2624 minuteStr, 2625 secondStr 2626 ) { 2627 var result = [ 2628 untruncateYear(yearStr), 2629 defaultLocaleMonthsShort.indexOf(monthStr), 2630 parseInt(dayStr, 10), 2631 parseInt(hourStr, 10), 2632 parseInt(minuteStr, 10), 2633 ]; 2634 2635 if (secondStr) { 2636 result.push(parseInt(secondStr, 10)); 2637 } 2638 2639 return result; 2640 } 2641 2642 function untruncateYear(yearStr) { 2643 var year = parseInt(yearStr, 10); 2644 if (year <= 49) { 2645 return 2000 + year; 2646 } else if (year <= 999) { 2647 return 1900 + year; 2648 } 2649 return year; 2650 } 2651 2652 function preprocessRFC2822(s) { 2653 // Remove comments and folding whitespace and replace multiple-spaces with a single space 2654 return s 2655 .replace(/\([^()]*\)|[\n\t]/g, ' ') 2656 .replace(/(\s\s+)/g, ' ') 2657 .replace(/^\s\s*/, '') 2658 .replace(/\s\s*$/, ''); 2659 } 2660 2661 function checkWeekday(weekdayStr, parsedInput, config) { 2662 if (weekdayStr) { 2663 // TODO: Replace the vanilla JS Date object with an independent day-of-week check. 2664 var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr), 2665 weekdayActual = new Date( 2666 parsedInput[0], 2667 parsedInput[1], 2668 parsedInput[2] 2669 ).getDay(); 2670 if (weekdayProvided !== weekdayActual) { 2671 getParsingFlags(config).weekdayMismatch = true; 2672 config._isValid = false; 2673 return false; 2674 } 2675 } 2676 return true; 2677 } 2678 2679 function calculateOffset(obsOffset, militaryOffset, numOffset) { 2680 if (obsOffset) { 2681 return obsOffsets[obsOffset]; 2682 } else if (militaryOffset) { 2683 // the only allowed military tz is Z 2684 return 0; 2685 } else { 2686 var hm = parseInt(numOffset, 10), 2687 m = hm % 100, 2688 h = (hm - m) / 100; 2689 return h * 60 + m; 2690 } 2691 } 2692 2693 // date and time from ref 2822 format 2694 function configFromRFC2822(config) { 2695 var match = rfc2822.exec(preprocessRFC2822(config._i)), 2696 parsedArray; 2697 if (match) { 2698 parsedArray = extractFromRFC2822Strings( 2699 match[4], 2700 match[3], 2701 match[2], 2702 match[5], 2703 match[6], 2704 match[7] 2705 ); 2706 if (!checkWeekday(match[1], parsedArray, config)) { 2707 return; 2708 } 2709 2710 config._a = parsedArray; 2711 config._tzm = calculateOffset(match[8], match[9], match[10]); 2712 2713 config._d = createUTCDate.apply(null, config._a); 2714 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); 2715 2716 getParsingFlags(config).rfc2822 = true; 2717 } else { 2718 config._isValid = false; 2719 } 2720 } 2721 2722 // date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict 2723 function configFromString(config) { 2724 var matched = aspNetJsonRegex.exec(config._i); 2725 if (matched !== null) { 2726 config._d = new Date(+matched[1]); 2727 return; 2728 } 2729 2730 configFromISO(config); 2731 if (config._isValid === false) { 2732 delete config._isValid; 2733 } else { 2734 return; 2735 } 2736 2737 configFromRFC2822(config); 2738 if (config._isValid === false) { 2739 delete config._isValid; 2740 } else { 2741 return; 2742 } 2743 2744 if (config._strict) { 2745 config._isValid = false; 2746 } else { 2747 // Final attempt, use Input Fallback 2748 hooks.createFromInputFallback(config); 2749 } 2750 } 2751 2752 hooks.createFromInputFallback = deprecate( 2753 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' + 2754 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' + 2755 'discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.', 2756 function (config) { 2757 config._d = new Date(config._i + (config._useUTC ? ' UTC' : '')); 2758 } 2759 ); 2760 2761 // Pick the first defined of two or three arguments. 2762 function defaults(a, b, c) { 2763 if (a != null) { 2764 return a; 2765 } 2766 if (b != null) { 2767 return b; 2768 } 2769 return c; 2770 } 2771 2772 function currentDateArray(config, now, forWeek) { 2773 var hadWeekContext = Object.prototype.hasOwnProperty.call( 2774 config, 2775 '_isDefaultDatePartsForWeek' 2776 ), 2777 weekContext = config._isDefaultDatePartsForWeek; 2778 2779 // hooks is actually the exported moment object 2780 config._isDefaultDatePartsForWeek = !!forWeek; 2781 try { 2782 return hooks._getDefaultDateParts(config, now, forWeek); 2783 } finally { 2784 if (hadWeekContext) { 2785 config._isDefaultDatePartsForWeek = weekContext; 2786 } else { 2787 delete config._isDefaultDatePartsForWeek; 2788 } 2789 } 2790 } 2791 2792 function currentDateNow(config) { 2793 var now = config._defaultDatePartsNow; 2794 2795 if (!now) { 2796 return hooks.now(); 2797 } 2798 if (!now.hasValue) { 2799 now.value = hooks.now(); 2800 now.hasValue = true; 2801 } 2802 return now.value; 2803 } 2804 2805 // Internal hook for extensions that supply omitted calendar fields. 2806 function getDefaultDateParts(config, now, forWeek) { 2807 var useWeekDefaults = forWeek || config._isDefaultDatePartsForWeek, 2808 nowValue = useWeekDefaults ? createLocal(now) : new Date(now); 2809 if (useWeekDefaults) { 2810 return [nowValue.year(), nowValue.month(), nowValue.date()]; 2811 } 2812 if (config._useUTC) { 2813 return [ 2814 nowValue.getUTCFullYear(), 2815 nowValue.getUTCMonth(), 2816 nowValue.getUTCDate(), 2817 ]; 2818 } 2819 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; 2820 } 2821 2822 hooks._getDefaultDateParts = getDefaultDateParts; 2823 2824 // convert an array to a date. 2825 // the array should mirror the parameters below 2826 // note: all values past the year are optional and will default to the lowest possible value. 2827 // [year, month, day , hour, minute, second, millisecond] 2828 function configFromArray(config) { 2829 var i, 2830 date, 2831 input = [], 2832 now, 2833 currentDate, 2834 expectedWeekday, 2835 yearToUse, 2836 dateIsDefaulted; 2837 2838 if (config._d) { 2839 return; 2840 } 2841 2842 if ( 2843 config._a[YEAR] == null || 2844 config._a[MONTH] == null || 2845 config._a[DATE] == null 2846 ) { 2847 now = currentDateNow(config); 2848 currentDate = currentDateArray(config, now); 2849 } 2850 2851 //compute day of the year from weeks and weekdays 2852 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) { 2853 dayOfYearFromWeekInfo(config, currentDateArray(config, now, true)); 2854 } 2855 2856 //if the day of the year is set, figure out what it is 2857 if (config._dayOfYear != null) { 2858 yearToUse = 2859 config._a[YEAR] != null ? config._a[YEAR] : currentDate[YEAR]; 2860 2861 if ( 2862 config._dayOfYear > daysInYear(yearToUse) || 2863 config._dayOfYear === 0 2864 ) { 2865 getParsingFlags(config)._overflowDayOfYear = true; 2866 } 2867 2868 date = createUTCDate(yearToUse, 0, config._dayOfYear); 2869 config._a[MONTH] = date.getUTCMonth(); 2870 config._a[DATE] = date.getUTCDate(); 2871 } 2872 2873 dateIsDefaulted = 2874 config._a[YEAR] == null || 2875 config._a[MONTH] == null || 2876 config._a[DATE] == null; 2877 2878 // Default to current date. 2879 // * if no year, month, day of month are given, default to today 2880 // * if day of month is given, default month and year 2881 // * if month is given, default only year 2882 // * if year is given, don't default anything 2883 for (i = 0; i < 3 && config._a[i] == null; ++i) { 2884 config._a[i] = input[i] = currentDate[i]; 2885 } 2886 2887 // Zero out whatever was not defaulted, including time 2888 for (; i < 7; i++) { 2889 config._a[i] = input[i] = 2890 config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i]; 2891 } 2892 2893 // Check for 24:00:00.000 2894 if ( 2895 config._a[HOUR] === 24 && 2896 config._a[MINUTE] === 0 && 2897 config._a[SECOND] === 0 && 2898 config._a[MILLISECOND] === 0 2899 ) { 2900 config._nextDay = true; 2901 config._a[HOUR] = 0; 2902 } 2903 2904 config._d = (config._useUTC ? createUTCDate : createDate).apply( 2905 null, 2906 input 2907 ); 2908 expectedWeekday = config._useUTC 2909 ? config._d.getUTCDay() 2910 : config._d.getDay(); 2911 2912 // Apply timezone offset from input. The actual utcOffset can be changed 2913 // with parseZone. 2914 if (config._tzm != null) { 2915 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); 2916 } 2917 2918 if (config._nextDay) { 2919 config._a[HOUR] = 24; 2920 } 2921 2922 // check for mismatching day of week 2923 if ( 2924 config._w && 2925 typeof config._w.d !== 'undefined' && 2926 !dateIsDefaulted && 2927 config._w.d !== expectedWeekday 2928 ) { 2929 getParsingFlags(config).weekdayMismatch = true; 2930 } 2931 } 2932 2933 function dayOfYearFromWeekInfo(config, currentDate) { 2934 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek; 2935 2936 w = config._w; 2937 if (w.GG != null || w.W != null || w.E != null) { 2938 dow = 1; 2939 doy = 4; 2940 2941 // TODO: We need to take the current isoWeekYear, but that depends on 2942 // how we interpret now (local, utc, fixed offset). So create 2943 // a now version of current config (take local/utc/offset flags, and 2944 // create now). 2945 weekYear = defaults( 2946 w.GG, 2947 config._a[YEAR], 2948 weekOfYearFromDate( 2949 currentDate[YEAR], 2950 currentDate[MONTH], 2951 currentDate[DATE], 2952 1, 2953 4 2954 ).year 2955 ); 2956 week = defaults(w.W, 1); 2957 weekday = defaults(w.E, 1); 2958 if (weekday < 1 || weekday > 7) { 2959 weekdayOverflow = true; 2960 } 2961 } else { 2962 dow = config._locale._week.dow; 2963 doy = config._locale._week.doy; 2964 2965 curWeek = weekOfYearFromDate( 2966 currentDate[YEAR], 2967 currentDate[MONTH], 2968 currentDate[DATE], 2969 dow, 2970 doy 2971 ); 2972 2973 weekYear = defaults(w.gg, config._a[YEAR], curWeek.year); 2974 2975 // Default to current week. 2976 week = defaults(w.w, curWeek.week); 2977 2978 if (w.d != null) { 2979 // weekday -- low day numbers are considered next week 2980 weekday = w.d; 2981 if (weekday < 0 || weekday > 6) { 2982 weekdayOverflow = true; 2983 } 2984 } else if (w.e != null) { 2985 // local weekday -- counting starts from beginning of week 2986 weekday = w.e + dow; 2987 if (w.e < 0 || w.e > 6) { 2988 weekdayOverflow = true; 2989 } 2990 } else { 2991 // default to beginning of week 2992 weekday = dow; 2993 } 2994 } 2995 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) { 2996 getParsingFlags(config)._overflowWeeks = true; 2997 } else if (weekdayOverflow != null) { 2998 getParsingFlags(config)._overflowWeekday = true; 2999 } else { 3000 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy); 3001 config._a[YEAR] = temp.year; 3002 config._dayOfYear = temp.dayOfYear; 3003 } 3004 } 3005 3006 // constant that refers to the ISO standard 3007 hooks.ISO_8601 = function () {}; 3008 3009 // constant that refers to the RFC 2822 form 3010 hooks.RFC_2822 = function () {}; 3011 3012 // date from string and format string 3013 function configFromStringAndFormat(config) { 3014 // TODO: Move this to another part of the creation flow to prevent circular deps 3015 if (config._f === hooks.ISO_8601) { 3016 configFromISO(config); 3017 return; 3018 } 3019 if (config._f === hooks.RFC_2822) { 3020 configFromRFC2822(config); 3021 return; 3022 } 3023 config._a = []; 3024 getParsingFlags(config).empty = true; 3025 3026 // This array is used to make a Date, either with `new Date` or `Date.UTC` 3027 var string = '' + config._i, 3028 i, 3029 parsedInput, 3030 tokens, 3031 token, 3032 skipped, 3033 stringLength = string.length, 3034 totalParsedInputLength = 0, 3035 era, 3036 tokenLen; 3037 3038 tokens = 3039 expandFormat(config._f, config._locale).match(formattingTokens) || []; 3040 tokenLen = tokens.length; 3041 for (i = 0; i < tokenLen; i++) { 3042 token = tokens[i]; 3043 parsedInput = (string.match(getParseRegexForToken(token, config)) || 3044 [])[0]; 3045 if (parsedInput) { 3046 skipped = string.substr(0, string.indexOf(parsedInput)); 3047 if (skipped.length > 0) { 3048 getParsingFlags(config).unusedInput.push(skipped); 3049 } 3050 string = string.slice( 3051 string.indexOf(parsedInput) + parsedInput.length 3052 ); 3053 totalParsedInputLength += parsedInput.length; 3054 } 3055 // don't parse if it's not a known token 3056 if (formatTokenFunctions[token]) { 3057 if (parsedInput) { 3058 getParsingFlags(config).empty = false; 3059 } else { 3060 getParsingFlags(config).unusedTokens.push(token); 3061 } 3062 addTimeToArrayFromToken(token, parsedInput, config); 3063 } else if (config._strict && !parsedInput) { 3064 getParsingFlags(config).unusedTokens.push(token); 3065 } 3066 } 3067 3068 // add remaining unparsed input length to the string 3069 getParsingFlags(config).charsLeftOver = 3070 stringLength - totalParsedInputLength; 3071 if (string.length > 0) { 3072 getParsingFlags(config).unusedInput.push(string); 3073 } 3074 3075 // clear _12h flag if hour is <= 12 3076 if ( 3077 config._a[HOUR] <= 12 && 3078 getParsingFlags(config).bigHour === true && 3079 config._a[HOUR] > 0 3080 ) { 3081 getParsingFlags(config).bigHour = undefined; 3082 } 3083 3084 getParsingFlags(config).parsedDateParts = config._a.slice(0); 3085 getParsingFlags(config).meridiem = config._meridiem; 3086 // handle meridiem 3087 config._a[HOUR] = meridiemFixWrap( 3088 config._locale, 3089 config._a[HOUR], 3090 config._meridiem 3091 ); 3092 3093 // handle era 3094 era = getParsingFlags(config).era; 3095 if (era !== null) { 3096 config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]); 3097 } 3098 3099 configFromArray(config); 3100 checkOverflow(config); 3101 } 3102 3103 function meridiemFixWrap(locale, hour, meridiem) { 3104 var isPm; 3105 3106 if (meridiem == null) { 3107 // nothing to do 3108 return hour; 3109 } 3110 if (locale.meridiemHour != null) { 3111 return locale.meridiemHour(hour, meridiem); 3112 } else if (locale.isPM != null) { 3113 // Fallback 3114 isPm = locale.isPM(meridiem); 3115 if (isPm && hour < 12) { 3116 hour += 12; 3117 } 3118 if (!isPm && hour === 12) { 3119 hour = 0; 3120 } 3121 return hour; 3122 } else { 3123 // this is not supposed to happen 3124 return hour; 3125 } 3126 } 3127 3128 // date from string and array of format strings 3129 function configFromStringAndArray(config) { 3130 var tempConfig, 3131 bestMoment, 3132 scoreToBeat, 3133 i, 3134 currentScore, 3135 validFormatFound, 3136 bestFormatIsValid = false, 3137 defaultDatePartsNow = {}, 3138 configfLen = config._f.length; 3139 3140 if (configfLen === 0) { 3141 getParsingFlags(config).invalidFormat = true; 3142 config._d = new Date(NaN); 3143 return; 3144 } 3145 3146 for (i = 0; i < configfLen; i++) { 3147 currentScore = 0; 3148 validFormatFound = false; 3149 tempConfig = copyConfig({}, config); 3150 if (config._useUTC != null) { 3151 tempConfig._useUTC = config._useUTC; 3152 } 3153 tempConfig._defaultDatePartsNow = defaultDatePartsNow; 3154 tempConfig._f = config._f[i]; 3155 configFromStringAndFormat(tempConfig); 3156 3157 if (isValid$2(tempConfig)) { 3158 validFormatFound = true; 3159 } 3160 3161 // if there is any input that was not parsed add a penalty for that format 3162 currentScore += getParsingFlags(tempConfig).charsLeftOver; 3163 3164 //or tokens 3165 currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10; 3166 3167 getParsingFlags(tempConfig).score = currentScore; 3168 3169 if (!bestFormatIsValid) { 3170 if ( 3171 scoreToBeat == null || 3172 currentScore < scoreToBeat || 3173 validFormatFound 3174 ) { 3175 scoreToBeat = currentScore; 3176 bestMoment = tempConfig; 3177 if (validFormatFound) { 3178 bestFormatIsValid = true; 3179 } 3180 } 3181 } else { 3182 if (currentScore < scoreToBeat) { 3183 scoreToBeat = currentScore; 3184 bestMoment = tempConfig; 3185 } 3186 } 3187 } 3188 3189 extend(config, bestMoment || tempConfig); 3190 } 3191 3192 function configFromObject(config) { 3193 if (config._d) { 3194 return; 3195 } 3196 3197 var i = normalizeObjectUnits(config._i), 3198 dayOrDate = i.day === undefined ? i.date : i.day; 3199 config._a = map( 3200 [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond], 3201 function (obj) { 3202 return obj && parseInt(obj, 10); 3203 } 3204 ); 3205 3206 configFromArray(config); 3207 } 3208 3209 function createFromConfig(config) { 3210 var res = new Moment(checkOverflow(prepareConfig(config))); 3211 if (res._nextDay) { 3212 // Adding is smart enough around DST 3213 res.add(1, 'd'); 3214 res._nextDay = undefined; 3215 } 3216 3217 return res; 3218 } 3219 3220 function prepareConfig(config) { 3221 var input = config._i, 3222 format = config._f; 3223 3224 config._locale = config._locale || getLocale(config._l); 3225 3226 if (input === null || (format === undefined && input === '')) { 3227 return createInvalid$1({ nullInput: true }); 3228 } 3229 3230 if (typeof input === 'string') { 3231 config._i = input = config._locale.preparse(input); 3232 } 3233 3234 if (isMoment(input)) { 3235 return new Moment(checkOverflow(input)); 3236 } else if (isDate(input)) { 3237 config._d = input; 3238 } else if (isArray(format)) { 3239 configFromStringAndArray(config); 3240 } else if (format) { 3241 configFromStringAndFormat(config); 3242 } else { 3243 configFromInput(config); 3244 } 3245 3246 if (!isValid$2(config)) { 3247 config._d = null; 3248 } 3249 3250 return config; 3251 } 3252 3253 function configFromInput(config) { 3254 var input = config._i; 3255 if (isUndefined(input)) { 3256 config._d = new Date(hooks.now()); 3257 } else if (isDate(input)) { 3258 config._d = new Date(input.valueOf()); 3259 } else if (typeof input === 'string') { 3260 configFromString(config); 3261 } else if (isArray(input)) { 3262 config._a = map(input.slice(0), function (obj) { 3263 return parseInt(obj, 10); 3264 }); 3265 configFromArray(config); 3266 } else if (isObject(input)) { 3267 configFromObject(config); 3268 } else if (isNumber(input)) { 3269 // from milliseconds 3270 config._d = new Date(input); 3271 } else { 3272 hooks.createFromInputFallback(config); 3273 } 3274 } 3275 3276 function createLocalOrUTC(input, format, locale, strict, isUTC) { 3277 var c = {}; 3278 3279 if (format === true || format === false) { 3280 strict = format; 3281 format = undefined; 3282 } 3283 3284 if (locale === true || locale === false) { 3285 strict = locale; 3286 locale = undefined; 3287 } 3288 3289 if ( 3290 (isObject(input) && isObjectEmpty(input)) || 3291 (isArray(input) && input.length === 0) 3292 ) { 3293 input = undefined; 3294 } 3295 // object construction must be done this way. 3296 // https://github.com/moment/moment/issues/1423 3297 c._isAMomentObject = true; 3298 c._useUTC = c._isUTC = isUTC; 3299 c._l = locale; 3300 c._i = input; 3301 c._f = format; 3302 c._strict = strict; 3303 3304 return createFromConfig(c); 3305 } 3306 3307 function createLocal(input, format, locale, strict) { 3308 return createLocalOrUTC(input, format, locale, strict, false); 3309 } 3310 3311 var prototypeMin = deprecate( 3312 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/', 3313 function () { 3314 var other = createLocal.apply(null, arguments); 3315 if (this.isValid() && other.isValid()) { 3316 return other < this ? this : other; 3317 } else { 3318 return createInvalid$1(); 3319 } 3320 } 3321 ), 3322 prototypeMax = deprecate( 3323 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/', 3324 function () { 3325 var other = createLocal.apply(null, arguments); 3326 if (this.isValid() && other.isValid()) { 3327 return other > this ? this : other; 3328 } else { 3329 return createInvalid$1(); 3330 } 3331 } 3332 ); 3333 3334 // Pick a moment m from moments so that m[fn](other) is true for all 3335 // other. This relies on the function fn to be transitive. 3336 // 3337 // moments should either be an array of moment objects or an array, whose 3338 // first element is an array of moment objects. 3339 function pickBy(fn, moments) { 3340 var res, i; 3341 if (moments.length === 1 && isArray(moments[0])) { 3342 moments = moments[0]; 3343 } 3344 if (!moments.length) { 3345 return createLocal(); 3346 } 3347 for (i = 0; i < moments.length; ++i) { 3348 if (isMoment(moments[i])) { 3349 res = moments[i]; 3350 break; 3351 } 3352 } 3353 if (!res) { 3354 return createInvalid$1(); 3355 } 3356 for (++i; i < moments.length; ++i) { 3357 if ( 3358 isMoment(moments[i]) && 3359 (!moments[i].isValid() || moments[i][fn](res)) 3360 ) { 3361 res = moments[i]; 3362 } 3363 } 3364 return res; 3365 } 3366 3367 // TODO: Use [].sort instead? 3368 function min() { 3369 var args = [].slice.call(arguments, 0); 3370 3371 return pickBy('isBefore', args); 3372 } 3373 3374 function max() { 3375 var args = [].slice.call(arguments, 0); 3376 3377 return pickBy('isAfter', args); 3378 } 3379 3380 var now = function () { 3381 return Date.now ? Date.now() : +new Date(); 3382 }; 3383 3384 var ordering = [ 3385 'year', 3386 'quarter', 3387 'month', 3388 'week', 3389 'day', 3390 'hour', 3391 'minute', 3392 'second', 3393 'millisecond', 3394 ]; 3395 3396 function isDurationValid(m) { 3397 var key, 3398 unitHasDecimal = false, 3399 i, 3400 orderLen = ordering.length; 3401 for (key in m) { 3402 if ( 3403 hasOwnProp(m, key) && 3404 !( 3405 indexOf.call(ordering, key) !== -1 && 3406 (m[key] == null || !isNaN(m[key])) 3407 ) 3408 ) { 3409 return false; 3410 } 3411 } 3412 3413 for (i = 0; i < orderLen; ++i) { 3414 if (m[ordering[i]]) { 3415 if (unitHasDecimal) { 3416 return false; // only allow non-integers for smallest unit 3417 } 3418 if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) { 3419 unitHasDecimal = true; 3420 } 3421 } 3422 } 3423 3424 return true; 3425 } 3426 3427 function isValid$1() { 3428 return this._isValid; 3429 } 3430 3431 function createInvalid() { 3432 return createDuration(NaN); 3433 } 3434 3435 function Duration(duration) { 3436 var normalizedInput = normalizeObjectUnits(duration), 3437 years = normalizedInput.year || 0, 3438 quarters = normalizedInput.quarter || 0, 3439 months = normalizedInput.month || 0, 3440 weeks = normalizedInput.week || normalizedInput.isoWeek || 0, 3441 days = normalizedInput.day || 0, 3442 hours = normalizedInput.hour || 0, 3443 minutes = normalizedInput.minute || 0, 3444 seconds = normalizedInput.second || 0, 3445 milliseconds = normalizedInput.millisecond || 0; 3446 3447 this._isValid = isDurationValid(normalizedInput); 3448 3449 // representation for dateAddRemove 3450 this._milliseconds = 3451 +milliseconds + 3452 seconds * 1e3 + // 1000 3453 minutes * 6e4 + // 1000 * 60 3454 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978 3455 // Because of dateAddRemove treats 24 hours as different from a 3456 // day when working around DST, we need to store them separately 3457 this._days = +days + weeks * 7; 3458 // It is impossible to translate months into days without knowing 3459 // which months you are are talking about, so we have to store 3460 // it separately. 3461 this._months = +months + quarters * 3 + years * 12; 3462 3463 this._data = {}; 3464 3465 this._locale = getLocale(); 3466 3467 this._bubble(); 3468 } 3469 3470 function isDuration(obj) { 3471 return obj instanceof Duration; 3472 } 3473 3474 function absRound(number) { 3475 if (number < 0) { 3476 return Math.round(-1 * number) * -1; 3477 } else { 3478 return Math.round(number); 3479 } 3480 } 3481 3482 // compare two arrays, return the number of differences 3483 function compareArrays(array1, array2, dontConvert) { 3484 var len = Math.min(array1.length, array2.length), 3485 lengthDiff = Math.abs(array1.length - array2.length), 3486 diffs = 0, 3487 i; 3488 for (i = 0; i < len; i++) { 3489 if ( 3490 (toInt(array1[i]) !== toInt(array2[i])) 3491 ) { 3492 diffs++; 3493 } 3494 } 3495 return diffs + lengthDiff; 3496 } 3497 3498 // FORMATTING 3499 3500 function offset(token, separator) { 3501 addFormatToken(token, 0, 0, function () { 3502 var offset = this.utcOffset(), 3503 sign = '+'; 3504 if (offset < 0) { 3505 offset = -offset; 3506 sign = '-'; 3507 } 3508 return ( 3509 sign + 3510 zeroFill(~~(offset / 60), 2) + 3511 separator + 3512 zeroFill(~~offset % 60, 2) 3513 ); 3514 }); 3515 } 3516 3517 offset('Z', ':'); 3518 offset('ZZ', ''); 3519 3520 // PARSING 3521 3522 addRegexToken('Z', matchShortOffset); 3523 addRegexToken('ZZ', matchShortOffset); 3524 addParseToken(['Z', 'ZZ'], function (input, array, config) { 3525 var offset = offsetFromString(matchShortOffset, input); 3526 config._useUTC = true; 3527 config._tzm = offset; 3528 if (offset === null) { 3529 getParsingFlags(config).invalidOffset = input; 3530 } 3531 }); 3532 3533 // HELPERS 3534 3535 // timezone chunker 3536 // '+10:00' > ['10', '00'] 3537 // '-1530' > ['-15', '30'] 3538 var chunkOffset = /([\+\-]|\d\d)/gi; 3539 3540 function offsetFromString(matcher, string) { 3541 var matches = (string || '').match(matcher), 3542 chunk, 3543 parts, 3544 minutes; 3545 3546 if (matches === null) { 3547 return null; 3548 } 3549 3550 chunk = matches[matches.length - 1] || []; 3551 parts = (chunk + '').match(chunkOffset) || ['-', 0, 0]; 3552 minutes = +(parts[1] * 60) + toInt(parts[2]); 3553 3554 if ( 3555 toInt(parts[2]) > 59 || 3556 (parts[0] === '+' ? minutes > 14 * 60 : minutes > 12 * 60) 3557 ) { 3558 return null; 3559 } 3560 3561 return minutes === 0 ? 0 : parts[0] === '+' ? minutes : -minutes; 3562 } 3563 3564 // Return a moment from input, that is local/utc/zone equivalent to model. 3565 function cloneWithOffset(input, model) { 3566 var res, diff; 3567 if (model._isUTC) { 3568 res = model.clone(); 3569 diff = 3570 (isMoment(input) || isDate(input) 3571 ? input.valueOf() 3572 : createLocal(input).valueOf()) - res.valueOf(); 3573 // Use low-level api, because this fn is low-level api. 3574 res._d.setTime(res._d.valueOf() + diff); 3575 hooks.updateOffset(res, false); 3576 return res; 3577 } else { 3578 return createLocal(input).local(); 3579 } 3580 } 3581 3582 function getDateOffset(m) { 3583 // On Firefox.24 Date#getTimezoneOffset returns a floating point. 3584 // https://github.com/moment/moment/pull/1871 3585 return -Math.round(m._d.getTimezoneOffset()); 3586 } 3587 3588 // HOOKS 3589 3590 // This function will be called whenever a moment is mutated. 3591 // It is intended to keep the offset in sync with the timezone. 3592 hooks.updateOffset = function () {}; 3593 3594 // MOMENTS 3595 3596 // keepLocalTime = true means only change the timezone, without 3597 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]--> 3598 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset 3599 // +0200, so we adjust the time as needed, to be valid. 3600 // 3601 // Keeping the time actually adds/subtracts (one hour) 3602 // from the actual represented time. That is why we call updateOffset 3603 // a second time. In case it wants us to change the offset again 3604 // _changeInProgress == true case, then we have to adjust, because 3605 // there is no such time in the given timezone. 3606 function getSetOffset(input, keepLocalTime, keepMinutes) { 3607 var offset = this._offset || 0, 3608 localAdjust; 3609 if (!this.isValid()) { 3610 return input != null ? this : NaN; 3611 } 3612 if (input != null) { 3613 if (typeof input === 'string') { 3614 input = offsetFromString(matchShortOffset, input); 3615 if (input === null) { 3616 return this; 3617 } 3618 } else if (Math.abs(input) < 16 && !keepMinutes) { 3619 input = input * 60; 3620 } 3621 if (!this._isUTC && keepLocalTime) { 3622 localAdjust = getDateOffset(this); 3623 } 3624 this._offset = input; 3625 this._isUTC = true; 3626 if (localAdjust != null) { 3627 this.add(localAdjust, 'm'); 3628 } 3629 if (offset !== input) { 3630 if (!keepLocalTime || this._changeInProgress) { 3631 addSubtract$1( 3632 this, 3633 createDuration(input - offset, 'm'), 3634 1, 3635 false 3636 ); 3637 } else if (!this._changeInProgress) { 3638 this._changeInProgress = true; 3639 hooks.updateOffset(this, true); 3640 this._changeInProgress = null; 3641 } 3642 } 3643 return this; 3644 } else { 3645 return this._isUTC ? offset : getDateOffset(this); 3646 } 3647 } 3648 3649 function getSetZone(input, keepLocalTime) { 3650 if (input != null) { 3651 if (typeof input !== 'string') { 3652 input = -input; 3653 } 3654 3655 this.utcOffset(input, keepLocalTime); 3656 3657 return this; 3658 } else { 3659 return -this.utcOffset(); 3660 } 3661 } 3662 3663 function setOffsetToUTC(keepLocalTime) { 3664 return this.utcOffset(0, keepLocalTime); 3665 } 3666 3667 function setOffsetToLocal(keepLocalTime) { 3668 if (this._isUTC) { 3669 this.utcOffset(0, keepLocalTime); 3670 this._isUTC = false; 3671 3672 if (keepLocalTime) { 3673 this.subtract(getDateOffset(this), 'm'); 3674 } 3675 } 3676 return this; 3677 } 3678 3679 function setOffsetToParsedOffset() { 3680 if (this._tzm != null) { 3681 this.utcOffset(this._tzm, false, true); 3682 } else if (typeof this._i === 'string') { 3683 var tZone = offsetFromString(matchOffset, this._i); 3684 if (tZone != null) { 3685 this.utcOffset(tZone); 3686 } else { 3687 this.utcOffset(0, true); 3688 } 3689 } 3690 return this; 3691 } 3692 3693 function hasAlignedHourOffset(input) { 3694 if (!this.isValid()) { 3695 return false; 3696 } 3697 input = input ? createLocal(input).utcOffset() : 0; 3698 3699 return (this.utcOffset() - input) % 60 === 0; 3700 } 3701 3702 function isDaylightSavingTime() { 3703 return ( 3704 this.utcOffset() > this.clone().month(0).utcOffset() || 3705 this.utcOffset() > this.clone().month(5).utcOffset() 3706 ); 3707 } 3708 3709 function isDaylightSavingTimeShifted() { 3710 if (!isUndefined(this._isDSTShifted)) { 3711 return this._isDSTShifted; 3712 } 3713 3714 var c = {}, 3715 other; 3716 3717 copyConfig(c, this); 3718 c = prepareConfig(c); 3719 3720 if (c._a) { 3721 other = c._isUTC ? createUTC(c._a) : createLocal(c._a); 3722 this._isDSTShifted = 3723 this.isValid() && compareArrays(c._a, other.toArray()) > 0; 3724 } else { 3725 this._isDSTShifted = false; 3726 } 3727 3728 return this._isDSTShifted; 3729 } 3730 3731 function isLocal() { 3732 return this.isValid() ? !this._isUTC : false; 3733 } 3734 3735 function isUtcOffset() { 3736 return this.isValid() ? this._isUTC : false; 3737 } 3738 3739 function isUtc() { 3740 return this.isValid() ? this._isUTC && this._offset === 0 : false; 3741 } 3742 3743 // ASP.NET json date format regex 3744 var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/, 3745 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html 3746 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere 3747 // and further modified to allow for strings containing both week and day 3748 isoRegex = 3749 /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/; 3750 3751 function createDuration(input, key) { 3752 var duration = input, 3753 // matching against regexp is expensive, do it on demand 3754 match = null, 3755 sign, 3756 ret, 3757 diffRes; 3758 3759 if (isDuration(input)) { 3760 duration = { 3761 ms: input._milliseconds, 3762 d: input._days, 3763 M: input._months, 3764 }; 3765 } else if (isNumber(input) || !isNaN(+input)) { 3766 duration = {}; 3767 if (key) { 3768 duration[key] = +input; 3769 } else { 3770 duration.milliseconds = +input; 3771 } 3772 } else if ((match = aspNetRegex.exec(input))) { 3773 sign = match[1] === '-' ? -1 : 1; 3774 duration = { 3775 y: 0, 3776 d: toInt(match[DATE]) * sign, 3777 h: toInt(match[HOUR]) * sign, 3778 m: toInt(match[MINUTE]) * sign, 3779 s: toInt(match[SECOND]) * sign, 3780 ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match 3781 }; 3782 } else if ((match = isoRegex.exec(input))) { 3783 sign = match[1] === '-' ? -1 : 1; 3784 duration = { 3785 y: parseIso(match[2], sign), 3786 M: parseIso(match[3], sign), 3787 w: parseIso(match[4], sign), 3788 d: parseIso(match[5], sign), 3789 h: parseIso(match[6], sign), 3790 m: parseIso(match[7], sign), 3791 s: parseIso(match[8], sign), 3792 }; 3793 } else if (duration == null) { 3794 // checks for null or undefined 3795 duration = {}; 3796 } else if ( 3797 typeof duration === 'object' && 3798 ('from' in duration || 'to' in duration) 3799 ) { 3800 diffRes = momentsDifference( 3801 createLocal(duration.from), 3802 createLocal(duration.to) 3803 ); 3804 3805 duration = {}; 3806 duration.ms = diffRes.milliseconds; 3807 duration.M = diffRes.months; 3808 } 3809 3810 ret = new Duration(duration); 3811 3812 if (isDuration(input) && hasOwnProp(input, '_locale')) { 3813 ret._locale = input._locale; 3814 } 3815 3816 if (isDuration(input) && hasOwnProp(input, '_isValid')) { 3817 ret._isValid = input._isValid; 3818 } 3819 3820 return ret; 3821 } 3822 3823 createDuration.fn = Duration.prototype; 3824 createDuration.invalid = createInvalid; 3825 3826 function parseIso(inp, sign) { 3827 // We'd normally use ~~inp for this, but unfortunately it also 3828 // converts floats to ints. 3829 // inp may be undefined, so careful calling replace on it. 3830 var res = inp && parseFloat(inp.replace(',', '.')); 3831 // apply sign while we're at it 3832 return (isNaN(res) ? 0 : res) * sign; 3833 } 3834 3835 function positiveMomentsDifference(base, other) { 3836 var res = {}; 3837 3838 res.months = 3839 other.month() - base.month() + (other.year() - base.year()) * 12; 3840 if (base.clone().add(res.months, 'M').isAfter(other)) { 3841 --res.months; 3842 } 3843 3844 res.milliseconds = +other - +base.clone().add(res.months, 'M'); 3845 3846 return res; 3847 } 3848 3849 function momentsDifference(base, other) { 3850 var res; 3851 if (!(base.isValid() && other.isValid())) { 3852 return { milliseconds: 0, months: 0 }; 3853 } 3854 3855 other = cloneWithOffset(other, base); 3856 if (base.isBefore(other)) { 3857 res = positiveMomentsDifference(base, other); 3858 } else { 3859 res = positiveMomentsDifference(other, base); 3860 res.milliseconds = -res.milliseconds; 3861 res.months = -res.months; 3862 } 3863 3864 return res; 3865 } 3866 3867 // TODO: remove 'name' arg after deprecation is removed 3868 function createAdder(direction, name) { 3869 return function (val, period) { 3870 var dur, tmp; 3871 //invert the arguments, but complain about it 3872 if (period !== null && !isNaN(+period)) { 3873 deprecateSimple( 3874 name, 3875 'moment().' + 3876 name + 3877 '(period, number) is deprecated. Please use moment().' + 3878 name + 3879 '(number, period). ' + 3880 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.' 3881 ); 3882 tmp = val; 3883 val = period; 3884 period = tmp; 3885 } 3886 3887 dur = createDuration(val, period); 3888 addSubtract$1(this, dur, direction); 3889 return this; 3890 }; 3891 } 3892 3893 function addSubtract$1(mom, duration, isAdding, updateOffset) { 3894 var milliseconds = duration._milliseconds, 3895 days = absRound(duration._days), 3896 months = absRound(duration._months); 3897 3898 if (!mom.isValid()) { 3899 // No op 3900 return; 3901 } 3902 3903 updateOffset = updateOffset == null ? true : updateOffset; 3904 3905 if (months) { 3906 setMonth(mom, get$2(mom, 'Month') + months * isAdding); 3907 } 3908 if (days) { 3909 set$1(mom, 'Date', get$2(mom, 'Date') + days * isAdding); 3910 } 3911 if (milliseconds) { 3912 mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding); 3913 } 3914 if (updateOffset) { 3915 hooks.updateOffset(mom, days || months); 3916 } 3917 } 3918 3919 var add$1 = createAdder(1, 'add'), 3920 subtract$1 = createAdder(-1, 'subtract'); 3921 3922 function isString(input) { 3923 return typeof input === 'string' || input instanceof String; 3924 } 3925 3926 // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined 3927 function isMomentInput(input) { 3928 return ( 3929 isMoment(input) || 3930 isDate(input) || 3931 isString(input) || 3932 isNumber(input) || 3933 isNumberOrStringArray(input) || 3934 isMomentInputObject(input) || 3935 input === null || 3936 input === undefined 3937 ); 3938 } 3939 3940 function isMomentInputObject(input) { 3941 var objectTest = isObject(input) && !isObjectEmpty(input), 3942 propertyTest = false, 3943 properties = [ 3944 'years', 3945 'year', 3946 'y', 3947 'months', 3948 'month', 3949 'M', 3950 'days', 3951 'day', 3952 'd', 3953 'dates', 3954 'date', 3955 'D', 3956 'hours', 3957 'hour', 3958 'h', 3959 'minutes', 3960 'minute', 3961 'm', 3962 'seconds', 3963 'second', 3964 's', 3965 'milliseconds', 3966 'millisecond', 3967 'ms', 3968 ], 3969 i, 3970 property, 3971 propertyLen = properties.length; 3972 3973 for (i = 0; i < propertyLen; i += 1) { 3974 property = properties[i]; 3975 propertyTest = propertyTest || hasOwnProp(input, property); 3976 } 3977 3978 return objectTest && propertyTest; 3979 } 3980 3981 function isNumberOrStringArray(input) { 3982 var arrayTest = isArray(input), 3983 dataTypeTest = false; 3984 if (arrayTest) { 3985 dataTypeTest = 3986 input.filter(function (item) { 3987 return !isNumber(item) && isString(input); 3988 }).length === 0; 3989 } 3990 return arrayTest && dataTypeTest; 3991 } 3992 3993 function isCalendarSpec(input) { 3994 var objectTest = isObject(input) && !isObjectEmpty(input), 3995 propertyTest = false, 3996 properties = [ 3997 'sameDay', 3998 'nextDay', 3999 'lastDay', 4000 'nextWeek', 4001 'lastWeek', 4002 'sameElse', 4003 ], 4004 i, 4005 property; 4006 4007 for (i = 0; i < properties.length; i += 1) { 4008 property = properties[i]; 4009 propertyTest = propertyTest || hasOwnProp(input, property); 4010 } 4011 4012 return objectTest && propertyTest; 4013 } 4014 4015 function getCalendarFormat(myMoment, now) { 4016 var diff = myMoment.diff(now, 'days', true); 4017 return diff < -6 4018 ? 'sameElse' 4019 : diff < -1 4020 ? 'lastWeek' 4021 : diff < 0 4022 ? 'lastDay' 4023 : diff < 1 4024 ? 'sameDay' 4025 : diff < 2 4026 ? 'nextDay' 4027 : diff < 7 4028 ? 'nextWeek' 4029 : 'sameElse'; 4030 } 4031 4032 function calendar(time, formats) { 4033 // Support for single parameter, formats only overload to the calendar function 4034 if (arguments.length === 1) { 4035 if (!arguments[0]) { 4036 time = undefined; 4037 formats = undefined; 4038 } else if (isMomentInput(arguments[0])) { 4039 time = arguments[0]; 4040 formats = undefined; 4041 } else if (isCalendarSpec(arguments[0])) { 4042 formats = arguments[0]; 4043 time = undefined; 4044 } 4045 } 4046 // We want to compare the start of today, vs this. 4047 // Getting start-of-today depends on whether we're local/utc/offset or not. 4048 var now = time || createLocal(), 4049 sod = cloneWithOffset(now, this).startOf('day'), 4050 format = hooks.calendarFormat(this, sod) || 'sameElse', 4051 output = 4052 formats && 4053 (isFunction(formats[format]) 4054 ? formats[format].call(this, now) 4055 : formats[format]); 4056 4057 return this.format( 4058 output || this.localeData().calendar(format, this, createLocal(now)) 4059 ); 4060 } 4061 4062 function clone$1() { 4063 return new Moment(this); 4064 } 4065 4066 function isAfter(input, units) { 4067 var localInput = isMoment(input) ? input : createLocal(input); 4068 if (!(this.isValid() && localInput.isValid())) { 4069 return false; 4070 } 4071 units = normalizeUnits(units) || 'millisecond'; 4072 if (units === 'millisecond') { 4073 return this.valueOf() > localInput.valueOf(); 4074 } else { 4075 return localInput.valueOf() < this.clone().startOf(units).valueOf(); 4076 } 4077 } 4078 4079 function isBefore(input, units) { 4080 var localInput = isMoment(input) ? input : createLocal(input); 4081 if (!(this.isValid() && localInput.isValid())) { 4082 return false; 4083 } 4084 units = normalizeUnits(units) || 'millisecond'; 4085 if (units === 'millisecond') { 4086 return this.valueOf() < localInput.valueOf(); 4087 } else { 4088 return this.clone().endOf(units).valueOf() < localInput.valueOf(); 4089 } 4090 } 4091 4092 function isBetween(from, to, units, inclusivity) { 4093 var localFrom = isMoment(from) ? from : createLocal(from), 4094 localTo = isMoment(to) ? to : createLocal(to); 4095 if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) { 4096 return false; 4097 } 4098 inclusivity = inclusivity || '()'; 4099 return ( 4100 (inclusivity[0] === '(' 4101 ? this.isAfter(localFrom, units) 4102 : !this.isBefore(localFrom, units)) && 4103 (inclusivity[1] === ')' 4104 ? this.isBefore(localTo, units) 4105 : !this.isAfter(localTo, units)) 4106 ); 4107 } 4108 4109 function isSame(input, units) { 4110 var localInput = isMoment(input) ? input : createLocal(input), 4111 inputMs; 4112 if (!(this.isValid() && localInput.isValid())) { 4113 return false; 4114 } 4115 units = normalizeUnits(units) || 'millisecond'; 4116 if (units === 'millisecond') { 4117 return this.valueOf() === localInput.valueOf(); 4118 } else { 4119 inputMs = localInput.valueOf(); 4120 return ( 4121 this.clone().startOf(units).valueOf() <= inputMs && 4122 inputMs <= this.clone().endOf(units).valueOf() 4123 ); 4124 } 4125 } 4126 4127 function isSameOrAfter(input, units) { 4128 return this.isSame(input, units) || this.isAfter(input, units); 4129 } 4130 4131 function isSameOrBefore(input, units) { 4132 return this.isSame(input, units) || this.isBefore(input, units); 4133 } 4134 4135 function diff(input, units, asFloat) { 4136 var that, zoneDelta, output; 4137 4138 if (!this.isValid()) { 4139 return NaN; 4140 } 4141 4142 that = cloneWithOffset(input, this); 4143 4144 if (!that.isValid()) { 4145 return NaN; 4146 } 4147 4148 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4; 4149 4150 units = normalizeUnits(units); 4151 4152 switch (units) { 4153 case 'year': 4154 output = monthDiff(this, that) / 12; 4155 break; 4156 case 'month': 4157 output = monthDiff(this, that); 4158 break; 4159 case 'quarter': 4160 output = monthDiff(this, that) / 3; 4161 break; 4162 case 'second': 4163 output = (this - that) / 1e3; 4164 break; // 1000 4165 case 'minute': 4166 output = (this - that) / 6e4; 4167 break; // 1000 * 60 4168 case 'hour': 4169 output = (this - that) / 36e5; 4170 break; // 1000 * 60 * 60 4171 case 'day': 4172 output = (this - that - zoneDelta) / 864e5; 4173 break; // 1000 * 60 * 60 * 24, negate dst 4174 case 'week': 4175 output = (this - that - zoneDelta) / 6048e5; 4176 break; // 1000 * 60 * 60 * 24 * 7, negate dst 4177 default: 4178 output = this - that; 4179 } 4180 4181 return asFloat ? output : absFloor(output); 4182 } 4183 4184 function monthDiff(a, b) { 4185 if (a.date() < b.date()) { 4186 // end-of-month calculations work correct when the start month has more 4187 // days than the end month. 4188 return -monthDiff(b, a); 4189 } 4190 // difference in months 4191 var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()), 4192 // b is in (anchor - 1 month, anchor + 1 month) 4193 anchor = a.clone().add(wholeMonthDiff, 'months'), 4194 anchor2, 4195 adjust; 4196 4197 if (b - anchor < 0) { 4198 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months'); 4199 // linear across the month 4200 adjust = (b - anchor) / (anchor - anchor2); 4201 } else { 4202 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months'); 4203 // linear across the month 4204 adjust = (b - anchor) / (anchor2 - anchor); 4205 } 4206 4207 //check for negative zero, return zero if negative zero 4208 return -(wholeMonthDiff + adjust) || 0; 4209 } 4210 4211 hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ'; 4212 hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]'; 4213 4214 function toString() { 4215 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'); 4216 } 4217 4218 function toISOString$1(keepOffset) { 4219 if (!this.isValid()) { 4220 return null; 4221 } 4222 var utc = keepOffset !== true, 4223 m = utc ? this.clone().utc() : this; 4224 if (m.year() < 0 || m.year() > 9999) { 4225 return formatMoment( 4226 m, 4227 utc 4228 ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' 4229 : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ' 4230 ); 4231 } 4232 if (isFunction(Date.prototype.toISOString)) { 4233 // native implementation is ~50x faster, use it when we can 4234 if (utc) { 4235 return this.toDate().toISOString(); 4236 } else { 4237 return new Date(this.valueOf() + this.utcOffset() * 60 * 1000) 4238 .toISOString() 4239 .replace('Z', formatMoment(m, 'Z')); 4240 } 4241 } 4242 return formatMoment( 4243 m, 4244 utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ' 4245 ); 4246 } 4247 4248 /** 4249 * Return a human readable representation of a moment that can 4250 * also be evaluated to get a new moment which is the same 4251 * 4252 * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects 4253 */ 4254 function inspect() { 4255 if (!this.isValid()) { 4256 return 'moment.invalid(/* ' + this._i + ' */)'; 4257 } 4258 var func = 'moment', 4259 zone = '', 4260 prefix, 4261 year, 4262 datetime, 4263 suffix; 4264 if (!this.isLocal()) { 4265 func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone'; 4266 zone = 'Z'; 4267 } 4268 prefix = '[' + func + '("]'; 4269 year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY'; 4270 datetime = '-MM-DD[T]HH:mm:ss.SSS'; 4271 suffix = zone + '[")]'; 4272 4273 return this.format(prefix + year + datetime + suffix); 4274 } 4275 4276 function format(inputString) { 4277 if (!inputString) { 4278 inputString = this.isUtc() 4279 ? hooks.defaultFormatUtc 4280 : hooks.defaultFormat; 4281 } 4282 var output = formatMoment(this, inputString); 4283 return this.localeData().postformat(output); 4284 } 4285 4286 function from(time, withoutSuffix) { 4287 if ( 4288 this.isValid() && 4289 ((isMoment(time) && time.isValid()) || createLocal(time).isValid()) 4290 ) { 4291 return createDuration({ to: this, from: time }) 4292 .locale(this.locale()) 4293 .humanize(!withoutSuffix); 4294 } else { 4295 return this.localeData().invalidDate(); 4296 } 4297 } 4298 4299 function fromNow(withoutSuffix) { 4300 return this.from(createLocal(), withoutSuffix); 4301 } 4302 4303 function to(time, withoutSuffix) { 4304 if ( 4305 this.isValid() && 4306 ((isMoment(time) && time.isValid()) || createLocal(time).isValid()) 4307 ) { 4308 return createDuration({ from: this, to: time }) 4309 .locale(this.locale()) 4310 .humanize(!withoutSuffix); 4311 } else { 4312 return this.localeData().invalidDate(); 4313 } 4314 } 4315 4316 function toNow(withoutSuffix) { 4317 return this.to(createLocal(), withoutSuffix); 4318 } 4319 4320 // If passed a locale key, it will set the locale for this 4321 // instance. Otherwise, it will return the locale configuration 4322 // variables for this instance. 4323 function locale(key) { 4324 var newLocaleData; 4325 4326 if (key === undefined) { 4327 return this._locale._abbr; 4328 } else { 4329 newLocaleData = getLocale(key); 4330 if (newLocaleData != null) { 4331 this._locale = newLocaleData; 4332 } 4333 return this; 4334 } 4335 } 4336 4337 var lang = deprecate( 4338 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.', 4339 function (key) { 4340 if (key === undefined) { 4341 return this.localeData(); 4342 } else { 4343 return this.locale(key); 4344 } 4345 } 4346 ); 4347 4348 function localeData() { 4349 return this._locale; 4350 } 4351 4352 var MS_PER_SECOND = 1000, 4353 MS_PER_MINUTE = 60 * MS_PER_SECOND, 4354 MS_PER_HOUR = 60 * MS_PER_MINUTE, 4355 MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR; 4356 4357 // actual modulo - handles negative numbers (for dates before 1970): 4358 function mod(dividend, divisor) { 4359 return ((dividend % divisor) + divisor) % divisor; 4360 } 4361 4362 function localStartOfDate(y, m, d) { 4363 // the date constructor remaps years 0-99 to 1900-1999 4364 if (y < 100 && y >= 0) { 4365 // preserve leap years using a full 400 year cycle, then reset 4366 return new Date(y + 400, m, d) - MS_PER_400_YEARS; 4367 } else { 4368 return new Date(y, m, d).valueOf(); 4369 } 4370 } 4371 4372 function utcStartOfDate(y, m, d) { 4373 // Date.UTC remaps years 0-99 to 1900-1999 4374 if (y < 100 && y >= 0) { 4375 // preserve leap years using a full 400 year cycle, then reset 4376 return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS; 4377 } else { 4378 return Date.UTC(y, m, d); 4379 } 4380 } 4381 4382 function startOf(units) { 4383 var time, startOfDate; 4384 units = normalizeUnits(units); 4385 if (units === undefined || units === 'millisecond' || !this.isValid()) { 4386 return this; 4387 } 4388 4389 startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate; 4390 4391 switch (units) { 4392 case 'year': 4393 time = startOfDate(this.year(), 0, 1); 4394 break; 4395 case 'quarter': 4396 time = startOfDate( 4397 this.year(), 4398 this.month() - (this.month() % 3), 4399 1 4400 ); 4401 break; 4402 case 'month': 4403 time = startOfDate(this.year(), this.month(), 1); 4404 break; 4405 case 'week': 4406 time = startOfDate( 4407 this.year(), 4408 this.month(), 4409 this.date() - this.weekday() 4410 ); 4411 break; 4412 case 'isoWeek': 4413 time = startOfDate( 4414 this.year(), 4415 this.month(), 4416 this.date() - (this.isoWeekday() - 1) 4417 ); 4418 break; 4419 case 'day': 4420 case 'date': 4421 time = startOfDate(this.year(), this.month(), this.date()); 4422 break; 4423 case 'hour': 4424 time = this._d.valueOf(); 4425 time -= mod( 4426 time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), 4427 MS_PER_HOUR 4428 ); 4429 break; 4430 case 'minute': 4431 time = this._d.valueOf(); 4432 time -= mod(time, MS_PER_MINUTE); 4433 break; 4434 case 'second': 4435 time = this._d.valueOf(); 4436 time -= mod(time, MS_PER_SECOND); 4437 break; 4438 } 4439 4440 this._d.setTime(time); 4441 hooks.updateOffset(this, true); 4442 return this; 4443 } 4444 4445 function endOf(units) { 4446 var time, startOfDate; 4447 units = normalizeUnits(units); 4448 if (units === undefined || units === 'millisecond' || !this.isValid()) { 4449 return this; 4450 } 4451 4452 startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate; 4453 4454 switch (units) { 4455 case 'year': 4456 time = startOfDate(this.year() + 1, 0, 1) - 1; 4457 break; 4458 case 'quarter': 4459 time = 4460 startOfDate( 4461 this.year(), 4462 this.month() - (this.month() % 3) + 3, 4463 1 4464 ) - 1; 4465 break; 4466 case 'month': 4467 time = startOfDate(this.year(), this.month() + 1, 1) - 1; 4468 break; 4469 case 'week': 4470 time = 4471 startOfDate( 4472 this.year(), 4473 this.month(), 4474 this.date() - this.weekday() + 7 4475 ) - 1; 4476 break; 4477 case 'isoWeek': 4478 time = 4479 startOfDate( 4480 this.year(), 4481 this.month(), 4482 this.date() - (this.isoWeekday() - 1) + 7 4483 ) - 1; 4484 break; 4485 case 'day': 4486 case 'date': 4487 time = startOfDate(this.year(), this.month(), this.date() + 1) - 1; 4488 break; 4489 case 'hour': 4490 time = this._d.valueOf(); 4491 time += 4492 MS_PER_HOUR - 4493 mod( 4494 time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), 4495 MS_PER_HOUR 4496 ) - 4497 1; 4498 break; 4499 case 'minute': 4500 time = this._d.valueOf(); 4501 time += MS_PER_MINUTE - mod(time, MS_PER_MINUTE) - 1; 4502 break; 4503 case 'second': 4504 time = this._d.valueOf(); 4505 time += MS_PER_SECOND - mod(time, MS_PER_SECOND) - 1; 4506 break; 4507 } 4508 4509 this._d.setTime(time); 4510 hooks.updateOffset(this, true); 4511 return this; 4512 } 4513 4514 function valueOf$1() { 4515 return this._d.valueOf() - (this._offset || 0) * 60000; 4516 } 4517 4518 function unix() { 4519 return Math.floor(this.valueOf() / 1000); 4520 } 4521 4522 function toDate() { 4523 return new Date(this.valueOf()); 4524 } 4525 4526 function toArray() { 4527 var m = this; 4528 return [ 4529 m.year(), 4530 m.month(), 4531 m.date(), 4532 m.hour(), 4533 m.minute(), 4534 m.second(), 4535 m.millisecond(), 4536 ]; 4537 } 4538 4539 function toObject() { 4540 var m = this; 4541 return { 4542 years: m.year(), 4543 months: m.month(), 4544 date: m.date(), 4545 hours: m.hours(), 4546 minutes: m.minutes(), 4547 seconds: m.seconds(), 4548 milliseconds: m.milliseconds(), 4549 }; 4550 } 4551 4552 function toJSON() { 4553 // new Date(NaN).toJSON() === null 4554 return this.isValid() ? this.toISOString() : null; 4555 } 4556 4557 function isValid() { 4558 return isValid$2(this); 4559 } 4560 4561 function parsingFlags() { 4562 return extend({}, getParsingFlags(this)); 4563 } 4564 4565 function invalidAt() { 4566 return getParsingFlags(this).overflow; 4567 } 4568 4569 function creationData() { 4570 return { 4571 input: this._i, 4572 format: this._f, 4573 locale: this._locale, 4574 isUTC: this._isUTC, 4575 strict: this._strict, 4576 }; 4577 } 4578 4579 addFormatToken('N', 0, 0, 'eraAbbr'); 4580 addFormatToken('NN', 0, 0, 'eraAbbr'); 4581 addFormatToken('NNN', 0, 0, 'eraAbbr'); 4582 addFormatToken('NNNN', 0, 0, 'eraName'); 4583 addFormatToken('NNNNN', 0, 0, 'eraNarrow'); 4584 4585 addFormatToken('y', ['y', 1], 'yo', 'eraYear'); 4586 addFormatToken('y', ['yy', 2], 0, 'eraYear'); 4587 addFormatToken('y', ['yyy', 3], 0, 'eraYear'); 4588 addFormatToken('y', ['yyyy', 4], 0, 'eraYear'); 4589 4590 addRegexToken('N', matchEraAbbr); 4591 addRegexToken('NN', matchEraAbbr); 4592 addRegexToken('NNN', matchEraAbbr); 4593 addRegexToken('NNNN', matchEraName); 4594 addRegexToken('NNNNN', matchEraNarrow); 4595 4596 addParseToken( 4597 ['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], 4598 function (input, array, config, token) { 4599 var era = config._locale.erasParse(input, token, config._strict); 4600 if (era) { 4601 getParsingFlags(config).era = era; 4602 } else { 4603 getParsingFlags(config).invalidEra = input; 4604 } 4605 } 4606 ); 4607 4608 addRegexToken('y', matchUnsigned); 4609 addRegexToken('yy', matchUnsigned); 4610 addRegexToken('yyy', matchUnsigned); 4611 addRegexToken('yyyy', matchUnsigned); 4612 addRegexToken('yo', matchEraYearOrdinal); 4613 4614 addParseToken(['y', 'yy', 'yyy', 'yyyy'], YEAR); 4615 addParseToken(['yo'], function (input, array, config, token) { 4616 var match; 4617 if (config._locale._eraYearOrdinalRegex) { 4618 match = input.match(config._locale._eraYearOrdinalRegex); 4619 } 4620 4621 if (config._locale.eraYearOrdinalParse) { 4622 array[YEAR] = config._locale.eraYearOrdinalParse(input, match); 4623 } else { 4624 array[YEAR] = parseInt(input, 10); 4625 } 4626 }); 4627 4628 function localeEras(m, format) { 4629 var i, 4630 l, 4631 date, 4632 eras = this._eras || getLocale('en')._eras; 4633 for (i = 0, l = eras.length; i < l; ++i) { 4634 switch (typeof eras[i].since) { 4635 case 'string': 4636 // truncate time 4637 date = hooks(eras[i].since).startOf('day'); 4638 eras[i].since = date.valueOf(); 4639 break; 4640 } 4641 4642 switch (typeof eras[i].until) { 4643 case 'undefined': 4644 eras[i].until = +Infinity; 4645 break; 4646 case 'string': 4647 // truncate time 4648 date = hooks(eras[i].until).startOf('day').valueOf(); 4649 eras[i].until = date.valueOf(); 4650 break; 4651 } 4652 } 4653 return eras; 4654 } 4655 4656 function localeErasParse(eraName, format, strict) { 4657 var i, 4658 l, 4659 eras = this.eras(), 4660 name, 4661 abbr, 4662 narrow; 4663 eraName = eraName.toUpperCase(); 4664 4665 for (i = 0, l = eras.length; i < l; ++i) { 4666 name = eras[i].name.toUpperCase(); 4667 abbr = eras[i].abbr.toUpperCase(); 4668 narrow = eras[i].narrow.toUpperCase(); 4669 4670 if (strict) { 4671 switch (format) { 4672 case 'N': 4673 case 'NN': 4674 case 'NNN': 4675 if (abbr === eraName) { 4676 return eras[i]; 4677 } 4678 break; 4679 4680 case 'NNNN': 4681 if (name === eraName) { 4682 return eras[i]; 4683 } 4684 break; 4685 4686 case 'NNNNN': 4687 if (narrow === eraName) { 4688 return eras[i]; 4689 } 4690 break; 4691 } 4692 } else if ([name, abbr, narrow].indexOf(eraName) >= 0) { 4693 return eras[i]; 4694 } 4695 } 4696 } 4697 4698 function localeErasConvertYear(era, year) { 4699 var dir = era.since <= era.until ? 1 : -1; 4700 if (year === undefined) { 4701 return hooks(era.since).year(); 4702 } else { 4703 return hooks(era.since).year() + (year - era.offset) * dir; 4704 } 4705 } 4706 4707 function getEraName() { 4708 var i, 4709 l, 4710 val, 4711 eras = this.localeData().eras(); 4712 for (i = 0, l = eras.length; i < l; ++i) { 4713 // truncate time 4714 val = this.clone().startOf('day').valueOf(); 4715 4716 if (eras[i].since <= val && val <= eras[i].until) { 4717 return eras[i].name; 4718 } 4719 if (eras[i].until <= val && val <= eras[i].since) { 4720 return eras[i].name; 4721 } 4722 } 4723 4724 return ''; 4725 } 4726 4727 function getEraNarrow() { 4728 var i, 4729 l, 4730 val, 4731 eras = this.localeData().eras(); 4732 for (i = 0, l = eras.length; i < l; ++i) { 4733 // truncate time 4734 val = this.clone().startOf('day').valueOf(); 4735 4736 if (eras[i].since <= val && val <= eras[i].until) { 4737 return eras[i].narrow; 4738 } 4739 if (eras[i].until <= val && val <= eras[i].since) { 4740 return eras[i].narrow; 4741 } 4742 } 4743 4744 return ''; 4745 } 4746 4747 function getEraAbbr() { 4748 var i, 4749 l, 4750 val, 4751 eras = this.localeData().eras(); 4752 for (i = 0, l = eras.length; i < l; ++i) { 4753 // truncate time 4754 val = this.clone().startOf('day').valueOf(); 4755 4756 if (eras[i].since <= val && val <= eras[i].until) { 4757 return eras[i].abbr; 4758 } 4759 if (eras[i].until <= val && val <= eras[i].since) { 4760 return eras[i].abbr; 4761 } 4762 } 4763 4764 return ''; 4765 } 4766 4767 function getEraYear() { 4768 var i, 4769 l, 4770 dir, 4771 val, 4772 eras = this.localeData().eras(); 4773 for (i = 0, l = eras.length; i < l; ++i) { 4774 dir = eras[i].since <= eras[i].until ? 1 : -1; 4775 4776 // truncate time 4777 val = this.clone().startOf('day').valueOf(); 4778 4779 if ( 4780 (eras[i].since <= val && val <= eras[i].until) || 4781 (eras[i].until <= val && val <= eras[i].since) 4782 ) { 4783 return ( 4784 (this.year() - hooks(eras[i].since).year()) * dir + 4785 eras[i].offset 4786 ); 4787 } 4788 } 4789 4790 return this.year(); 4791 } 4792 4793 function erasNameRegex(isStrict) { 4794 if (!hasOwnProp(this, '_erasNameRegex')) { 4795 computeErasParse.call(this); 4796 } 4797 return isStrict ? this._erasNameRegex : this._erasRegex; 4798 } 4799 4800 function erasAbbrRegex(isStrict) { 4801 if (!hasOwnProp(this, '_erasAbbrRegex')) { 4802 computeErasParse.call(this); 4803 } 4804 return isStrict ? this._erasAbbrRegex : this._erasRegex; 4805 } 4806 4807 function erasNarrowRegex(isStrict) { 4808 if (!hasOwnProp(this, '_erasNarrowRegex')) { 4809 computeErasParse.call(this); 4810 } 4811 return isStrict ? this._erasNarrowRegex : this._erasRegex; 4812 } 4813 4814 function matchEraAbbr(isStrict, locale) { 4815 return locale.erasAbbrRegex(isStrict); 4816 } 4817 4818 function matchEraName(isStrict, locale) { 4819 return locale.erasNameRegex(isStrict); 4820 } 4821 4822 function matchEraNarrow(isStrict, locale) { 4823 return locale.erasNarrowRegex(isStrict); 4824 } 4825 4826 function matchEraYearOrdinal(isStrict, locale) { 4827 return locale._eraYearOrdinalRegex || matchUnsigned; 4828 } 4829 4830 function computeErasParse() { 4831 var abbrPieces = [], 4832 namePieces = [], 4833 narrowPieces = [], 4834 mixedPieces = [], 4835 i, 4836 l, 4837 erasName, 4838 erasAbbr, 4839 erasNarrow, 4840 eras = this.eras(); 4841 4842 for (i = 0, l = eras.length; i < l; ++i) { 4843 erasName = regexEscape(eras[i].name); 4844 erasAbbr = regexEscape(eras[i].abbr); 4845 erasNarrow = regexEscape(eras[i].narrow); 4846 4847 namePieces.push(erasName); 4848 abbrPieces.push(erasAbbr); 4849 narrowPieces.push(erasNarrow); 4850 mixedPieces.push(erasName); 4851 mixedPieces.push(erasAbbr); 4852 mixedPieces.push(erasNarrow); 4853 } 4854 4855 this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); 4856 this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i'); 4857 this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i'); 4858 this._erasNarrowRegex = new RegExp( 4859 '^(' + narrowPieces.join('|') + ')', 4860 'i' 4861 ); 4862 } 4863 4864 // FORMATTING 4865 4866 addFormatToken(0, ['gg', 2], 0, function () { 4867 return this.weekYear() % 100; 4868 }); 4869 4870 addFormatToken(0, ['GG', 2], 0, function () { 4871 return this.isoWeekYear() % 100; 4872 }); 4873 4874 function addWeekYearFormatToken(token, getter) { 4875 addFormatToken(0, [token, token.length], 0, getter); 4876 } 4877 4878 addWeekYearFormatToken('gggg', 'weekYear'); 4879 addWeekYearFormatToken('ggggg', 'weekYear'); 4880 addWeekYearFormatToken('GGGG', 'isoWeekYear'); 4881 addWeekYearFormatToken('GGGGG', 'isoWeekYear'); 4882 4883 // ALIASES 4884 4885 // PARSING 4886 4887 addRegexToken('G', matchSigned); 4888 addRegexToken('g', matchSigned); 4889 addRegexToken('GG', match1to2, match2); 4890 addRegexToken('gg', match1to2, match2); 4891 addRegexToken('GGGG', match1to4, match4); 4892 addRegexToken('gggg', match1to4, match4); 4893 addRegexToken('GGGGG', match1to6, match6); 4894 addRegexToken('ggggg', match1to6, match6); 4895 4896 addWeekParseToken( 4897 ['gggg', 'ggggg', 'GGGG', 'GGGGG'], 4898 function (input, week, config, token) { 4899 week[token.substr(0, 2)] = toInt(input); 4900 } 4901 ); 4902 4903 addWeekParseToken(['gg', 'GG'], function (input, week, config, token) { 4904 week[token] = hooks.parseTwoDigitYear(input); 4905 }); 4906 4907 // MOMENTS 4908 4909 function getSetWeekYear(input) { 4910 return getSetWeekYearHelper.call( 4911 this, 4912 input, 4913 this.week(), 4914 this.weekday() + this.localeData()._week.dow, 4915 this.localeData()._week.dow, 4916 this.localeData()._week.doy 4917 ); 4918 } 4919 4920 function getSetISOWeekYear(input) { 4921 return getSetWeekYearHelper.call( 4922 this, 4923 input, 4924 this.isoWeek(), 4925 this.isoWeekday(), 4926 1, 4927 4 4928 ); 4929 } 4930 4931 function getISOWeeksInYear() { 4932 return weeksInYear(this.year(), 1, 4); 4933 } 4934 4935 function getISOWeeksInISOWeekYear() { 4936 return weeksInYear(this.isoWeekYear(), 1, 4); 4937 } 4938 4939 function getWeeksInYear() { 4940 var weekInfo = this.localeData()._week; 4941 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy); 4942 } 4943 4944 function getWeeksInWeekYear() { 4945 var weekInfo = this.localeData()._week; 4946 return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy); 4947 } 4948 4949 function getSetWeekYearHelper(input, week, weekday, dow, doy) { 4950 var weeksTarget; 4951 if (input == null) { 4952 return weekOfYear(this, dow, doy).year; 4953 } else { 4954 weeksTarget = weeksInYear(input, dow, doy); 4955 if (week > weeksTarget) { 4956 week = weeksTarget; 4957 } 4958 return setWeekAll.call(this, input, week, weekday, dow, doy); 4959 } 4960 } 4961 4962 function setWeekAll(weekYear, week, weekday, dow, doy) { 4963 var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy), 4964 date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear); 4965 4966 this.year(date.getUTCFullYear()); 4967 this.month(date.getUTCMonth()); 4968 this.date(date.getUTCDate()); 4969 return this; 4970 } 4971 4972 // FORMATTING 4973 4974 addFormatToken('Q', 0, 'Qo', 'quarter'); 4975 4976 // PARSING 4977 4978 addRegexToken('Q', match1); 4979 addParseToken('Q', function (input, array) { 4980 array[MONTH] = (toInt(input) - 1) * 3; 4981 }); 4982 4983 // MOMENTS 4984 4985 function getSetQuarter(input) { 4986 return input == null 4987 ? Math.ceil((this.month() + 1) / 3) 4988 : this.month((input - 1) * 3 + (this.month() % 3)); 4989 } 4990 4991 // FORMATTING 4992 4993 addFormatToken('D', ['DD', 2], 'Do', 'date'); 4994 4995 // PARSING 4996 4997 addRegexToken('D', match1to2, match1to2NoLeadingZero); 4998 addRegexToken('DD', match1to2, match2); 4999 addRegexToken('Do', function (isStrict, locale) { 5000 // TODO: Remove "ordinalParse" fallback in next major release. 5001 return isStrict 5002 ? locale._dayOfMonthOrdinalParse || locale._ordinalParse 5003 : locale._dayOfMonthOrdinalParseLenient; 5004 }); 5005 5006 addParseToken(['D', 'DD'], DATE); 5007 addParseToken('Do', function (input, array) { 5008 array[DATE] = toInt(input.match(match1to2)[0]); 5009 }); 5010 5011 // MOMENTS 5012 5013 var getSetDayOfMonth = makeGetSet('Date', true); 5014 5015 // FORMATTING 5016 5017 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear'); 5018 5019 // PARSING 5020 5021 addRegexToken('DDD', match1to3); 5022 addRegexToken('DDDD', match3); 5023 addParseToken(['DDD', 'DDDD'], function (input, array, config) { 5024 config._dayOfYear = toInt(input); 5025 }); 5026 5027 // HELPERS 5028 5029 // MOMENTS 5030 5031 function getSetDayOfYear(input) { 5032 var dayOfYear = 5033 Math.round( 5034 (this.clone().startOf('day') - this.clone().startOf('year')) / 864e5 5035 ) + 1; 5036 return input == null ? dayOfYear : this.add(input - dayOfYear, 'd'); 5037 } 5038 5039 // FORMATTING 5040 5041 addFormatToken('m', ['mm', 2], 0, 'minute'); 5042 5043 // PARSING 5044 5045 addRegexToken('m', match1to2, match1to2HasZero); 5046 addRegexToken('mm', match1to2, match2); 5047 addParseToken(['m', 'mm'], MINUTE); 5048 5049 // MOMENTS 5050 5051 var getSetMinute = makeGetSet('Minutes', false); 5052 5053 // FORMATTING 5054 5055 addFormatToken('s', ['ss', 2], 0, 'second'); 5056 5057 // PARSING 5058 5059 addRegexToken('s', match1to2, match1to2HasZero); 5060 addRegexToken('ss', match1to2, match2); 5061 addParseToken(['s', 'ss'], SECOND); 5062 5063 // MOMENTS 5064 5065 var getSetSecond = makeGetSet('Seconds', false); 5066 5067 // FORMATTING 5068 5069 addFormatToken('S', 0, 0, function () { 5070 return ~~(this.millisecond() / 100); 5071 }); 5072 5073 addFormatToken(0, ['SS', 2], 0, function () { 5074 return ~~(this.millisecond() / 10); 5075 }); 5076 5077 addFormatToken(0, ['SSS', 3], 0, 'millisecond'); 5078 addFormatToken(0, ['SSSS', 4], 0, function () { 5079 return this.millisecond() * 10; 5080 }); 5081 addFormatToken(0, ['SSSSS', 5], 0, function () { 5082 return this.millisecond() * 100; 5083 }); 5084 addFormatToken(0, ['SSSSSS', 6], 0, function () { 5085 return this.millisecond() * 1000; 5086 }); 5087 addFormatToken(0, ['SSSSSSS', 7], 0, function () { 5088 return this.millisecond() * 10000; 5089 }); 5090 addFormatToken(0, ['SSSSSSSS', 8], 0, function () { 5091 return this.millisecond() * 100000; 5092 }); 5093 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () { 5094 return this.millisecond() * 1000000; 5095 }); 5096 5097 // PARSING 5098 5099 addRegexToken('S', match1to3, match1); 5100 addRegexToken('SS', match1to3, match2); 5101 addRegexToken('SSS', match1to3, match3); 5102 5103 var token, getSetMillisecond; 5104 for (token = 'SSSS'; token.length <= 9; token += 'S') { 5105 addRegexToken(token, matchUnsigned); 5106 } 5107 5108 function parseMs(input, array) { 5109 array[MILLISECOND] = toInt(('0.' + input) * 1000); 5110 } 5111 5112 for (token = 'S'; token.length <= 9; token += 'S') { 5113 addParseToken(token, parseMs); 5114 } 5115 5116 getSetMillisecond = makeGetSet('Milliseconds', false); 5117 5118 // FORMATTING 5119 5120 addFormatToken('z', 0, 0, 'zoneAbbr'); 5121 addFormatToken('zz', 0, 0, 'zoneName'); 5122 5123 // MOMENTS 5124 5125 function getZoneAbbr() { 5126 return this._isUTC ? 'UTC' : ''; 5127 } 5128 5129 function getZoneName() { 5130 return this._isUTC ? 'Coordinated Universal Time' : ''; 5131 } 5132 5133 var proto$2 = Moment.prototype; 5134 5135 proto$2.add = add$1; 5136 proto$2.calendar = calendar; 5137 proto$2.clone = clone$1; 5138 proto$2.diff = diff; 5139 proto$2.endOf = endOf; 5140 proto$2.format = format; 5141 proto$2.from = from; 5142 proto$2.fromNow = fromNow; 5143 proto$2.to = to; 5144 proto$2.toNow = toNow; 5145 proto$2.get = stringGet; 5146 proto$2.invalidAt = invalidAt; 5147 proto$2.isAfter = isAfter; 5148 proto$2.isBefore = isBefore; 5149 proto$2.isBetween = isBetween; 5150 proto$2.isSame = isSame; 5151 proto$2.isSameOrAfter = isSameOrAfter; 5152 proto$2.isSameOrBefore = isSameOrBefore; 5153 proto$2.isValid = isValid; 5154 proto$2.lang = lang; 5155 proto$2.locale = locale; 5156 proto$2.localeData = localeData; 5157 proto$2.max = prototypeMax; 5158 proto$2.min = prototypeMin; 5159 proto$2.parsingFlags = parsingFlags; 5160 proto$2.set = stringSet; 5161 proto$2.startOf = startOf; 5162 proto$2.subtract = subtract$1; 5163 proto$2.toArray = toArray; 5164 proto$2.toObject = toObject; 5165 proto$2.toDate = toDate; 5166 proto$2.toISOString = toISOString$1; 5167 proto$2.inspect = inspect; 5168 if (typeof Symbol !== 'undefined' && Symbol.for != null) { 5169 proto$2[Symbol.for('nodejs.util.inspect.custom')] = function () { 5170 return 'Moment<' + this.format() + '>'; 5171 }; 5172 } 5173 proto$2.toJSON = toJSON; 5174 proto$2.toString = toString; 5175 proto$2.unix = unix; 5176 proto$2.valueOf = valueOf$1; 5177 proto$2.creationData = creationData; 5178 proto$2.eraName = getEraName; 5179 proto$2.eraNarrow = getEraNarrow; 5180 proto$2.eraAbbr = getEraAbbr; 5181 proto$2.eraYear = getEraYear; 5182 proto$2.year = getSetYear; 5183 proto$2.isLeapYear = getIsLeapYear; 5184 proto$2.weekYear = getSetWeekYear; 5185 proto$2.isoWeekYear = getSetISOWeekYear; 5186 proto$2.quarter = proto$2.quarters = getSetQuarter; 5187 proto$2.month = getSetMonth; 5188 proto$2.daysInMonth = getDaysInMonth; 5189 proto$2.week = proto$2.weeks = getSetWeek; 5190 proto$2.isoWeek = proto$2.isoWeeks = getSetISOWeek; 5191 proto$2.weeksInYear = getWeeksInYear; 5192 proto$2.weeksInWeekYear = getWeeksInWeekYear; 5193 proto$2.isoWeeksInYear = getISOWeeksInYear; 5194 proto$2.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear; 5195 proto$2.date = getSetDayOfMonth; 5196 proto$2.day = proto$2.days = getSetDayOfWeek; 5197 proto$2.weekday = getSetLocaleDayOfWeek; 5198 proto$2.isoWeekday = getSetISODayOfWeek; 5199 proto$2.dayOfYear = getSetDayOfYear; 5200 proto$2.hour = proto$2.hours = getSetHour; 5201 proto$2.minute = proto$2.minutes = getSetMinute; 5202 proto$2.second = proto$2.seconds = getSetSecond; 5203 proto$2.millisecond = proto$2.milliseconds = getSetMillisecond; 5204 proto$2.utcOffset = getSetOffset; 5205 proto$2.utc = setOffsetToUTC; 5206 proto$2.local = setOffsetToLocal; 5207 proto$2.parseZone = setOffsetToParsedOffset; 5208 proto$2.hasAlignedHourOffset = hasAlignedHourOffset; 5209 proto$2.isDST = isDaylightSavingTime; 5210 proto$2.isLocal = isLocal; 5211 proto$2.isUtcOffset = isUtcOffset; 5212 proto$2.isUtc = isUtc; 5213 proto$2.isUTC = isUtc; 5214 proto$2.zoneAbbr = getZoneAbbr; 5215 proto$2.zoneName = getZoneName; 5216 proto$2.dates = deprecate( 5217 'dates accessor is deprecated. Use date instead.', 5218 getSetDayOfMonth 5219 ); 5220 proto$2.months = deprecate( 5221 'months accessor is deprecated. Use month instead', 5222 getSetMonth 5223 ); 5224 proto$2.years = deprecate( 5225 'years accessor is deprecated. Use year instead', 5226 getSetYear 5227 ); 5228 proto$2.zone = deprecate( 5229 'moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', 5230 getSetZone 5231 ); 5232 proto$2.isDSTShifted = deprecate( 5233 'isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', 5234 isDaylightSavingTimeShifted 5235 ); 5236 5237 function createUnix(input) { 5238 return createLocal(input * 1000); 5239 } 5240 5241 function createInZone() { 5242 return createLocal.apply(null, arguments).parseZone(); 5243 } 5244 5245 function preParsePostFormat(string) { 5246 return string; 5247 } 5248 5249 var proto$1 = Locale.prototype; 5250 5251 proto$1.calendar = calendar$1; 5252 proto$1.longDateFormat = longDateFormat; 5253 proto$1.invalidDate = invalidDate; 5254 proto$1.ordinal = ordinal; 5255 proto$1.preparse = preParsePostFormat; 5256 proto$1.postformat = preParsePostFormat; 5257 proto$1.relativeTime = relativeTime$1; 5258 proto$1.pastFuture = pastFuture; 5259 proto$1.set = set; 5260 proto$1.eras = localeEras; 5261 proto$1.erasParse = localeErasParse; 5262 proto$1.erasConvertYear = localeErasConvertYear; 5263 proto$1.erasAbbrRegex = erasAbbrRegex; 5264 proto$1.erasNameRegex = erasNameRegex; 5265 proto$1.erasNarrowRegex = erasNarrowRegex; 5266 5267 proto$1.months = localeMonths; 5268 proto$1.monthsShort = localeMonthsShort; 5269 proto$1.monthsParse = localeMonthsParse; 5270 proto$1.monthsRegex = monthsRegex; 5271 proto$1.monthsShortRegex = monthsShortRegex; 5272 proto$1.week = localeWeek; 5273 proto$1.firstDayOfYear = localeFirstDayOfYear; 5274 proto$1.firstDayOfWeek = localeFirstDayOfWeek; 5275 5276 proto$1.weekdays = localeWeekdays; 5277 proto$1.weekdaysMin = localeWeekdaysMin; 5278 proto$1.weekdaysShort = localeWeekdaysShort; 5279 proto$1.weekdaysParse = localeWeekdaysParse; 5280 5281 proto$1.weekdaysRegex = weekdaysRegex; 5282 proto$1.weekdaysShortRegex = weekdaysShortRegex; 5283 proto$1.weekdaysMinRegex = weekdaysMinRegex; 5284 5285 proto$1.isPM = localeIsPM; 5286 proto$1.meridiem = localeMeridiem; 5287 5288 function get$1(format, index, field, setter) { 5289 var locale = getLocale(), 5290 utc = createUTC().set(setter, index); 5291 return locale[field](utc, format); 5292 } 5293 5294 function listMonthsImpl(format, index, field) { 5295 if (isNumber(format)) { 5296 index = format; 5297 format = undefined; 5298 } 5299 5300 format = format || ''; 5301 5302 if (index != null) { 5303 return get$1(format, index, field, 'month'); 5304 } 5305 5306 var i, 5307 out = []; 5308 for (i = 0; i < 12; i++) { 5309 out[i] = get$1(format, i, field, 'month'); 5310 } 5311 return out; 5312 } 5313 5314 // () 5315 // (5) 5316 // (fmt, 5) 5317 // (fmt) 5318 // (true) 5319 // (true, 5) 5320 // (true, fmt, 5) 5321 // (true, fmt) 5322 function listWeekdaysImpl(localeSorted, format, index, field) { 5323 if (typeof localeSorted === 'boolean') { 5324 if (isNumber(format)) { 5325 index = format; 5326 format = undefined; 5327 } 5328 5329 format = format || ''; 5330 } else { 5331 format = localeSorted; 5332 index = format; 5333 localeSorted = false; 5334 5335 if (isNumber(format)) { 5336 index = format; 5337 format = undefined; 5338 } 5339 5340 format = format || ''; 5341 } 5342 5343 var locale = getLocale(), 5344 shift = localeSorted ? locale._week.dow : 0, 5345 i, 5346 out = []; 5347 5348 if (index != null) { 5349 return get$1(format, (index + shift) % 7, field, 'day'); 5350 } 5351 5352 for (i = 0; i < 7; i++) { 5353 out[i] = get$1(format, (i + shift) % 7, field, 'day'); 5354 } 5355 return out; 5356 } 5357 5358 function listMonths(format, index) { 5359 return listMonthsImpl(format, index, 'months'); 5360 } 5361 5362 function listMonthsShort(format, index) { 5363 return listMonthsImpl(format, index, 'monthsShort'); 5364 } 5365 5366 function listWeekdays(localeSorted, format, index) { 5367 return listWeekdaysImpl(localeSorted, format, index, 'weekdays'); 5368 } 5369 5370 function listWeekdaysShort(localeSorted, format, index) { 5371 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort'); 5372 } 5373 5374 function listWeekdaysMin(localeSorted, format, index) { 5375 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin'); 5376 } 5377 5378 getSetGlobalLocale('en', { 5379 eras: [ 5380 { 5381 since: '0001-01-01', 5382 until: +Infinity, 5383 offset: 1, 5384 name: 'Anno Domini', 5385 narrow: 'AD', 5386 abbr: 'AD', 5387 }, 5388 { 5389 since: '0000-12-31', 5390 until: -Infinity, 5391 offset: 1, 5392 name: 'Before Christ', 5393 narrow: 'BC', 5394 abbr: 'BC', 5395 }, 5396 ], 5397 dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, 5398 ordinal: function (number) { 5399 var b = number % 10, 5400 output = 5401 toInt((number % 100) / 10) === 1 5402 ? 'th' 5403 : b === 1 5404 ? 'st' 5405 : b === 2 5406 ? 'nd' 5407 : b === 3 5408 ? 'rd' 5409 : 'th'; 5410 return number + output; 5411 }, 5412 }); 5413 5414 // Side effect imports 5415 5416 hooks.lang = deprecate( 5417 'moment.lang is deprecated. Use moment.locale instead.', 5418 getSetGlobalLocale 5419 ); 5420 hooks.langData = deprecate( 5421 'moment.langData is deprecated. Use moment.localeData instead.', 5422 getLocale 5423 ); 5424 5425 var mathAbs = Math.abs; 5426 5427 function abs$1() { 5428 var data = this._data; 5429 5430 this._milliseconds = mathAbs(this._milliseconds); 5431 this._days = mathAbs(this._days); 5432 this._months = mathAbs(this._months); 5433 5434 data.milliseconds = mathAbs(data.milliseconds); 5435 data.seconds = mathAbs(data.seconds); 5436 data.minutes = mathAbs(data.minutes); 5437 data.hours = mathAbs(data.hours); 5438 data.months = mathAbs(data.months); 5439 data.years = mathAbs(data.years); 5440 5441 return this; 5442 } 5443 5444 function addSubtract(duration, input, value, direction) { 5445 var other = createDuration(input, value); 5446 5447 duration._milliseconds += direction * other._milliseconds; 5448 duration._days += direction * other._days; 5449 duration._months += direction * other._months; 5450 5451 return duration._bubble(); 5452 } 5453 5454 // supports only 2.0-style add(1, 's') or add(duration) 5455 function add(input, value) { 5456 return addSubtract(this, input, value, 1); 5457 } 5458 5459 // supports only 2.0-style subtract(1, 's') or subtract(duration) 5460 function subtract(input, value) { 5461 return addSubtract(this, input, value, -1); 5462 } 5463 5464 function absCeil(number) { 5465 if (number < 0) { 5466 return Math.floor(number); 5467 } else { 5468 return Math.ceil(number); 5469 } 5470 } 5471 5472 function bubble() { 5473 var milliseconds = this._milliseconds, 5474 days = this._days, 5475 months = this._months, 5476 data = this._data, 5477 seconds, 5478 minutes, 5479 hours, 5480 years, 5481 monthsFromDays; 5482 5483 // if we have a mix of positive and negative values, bubble down first 5484 // check: https://github.com/moment/moment/issues/2166 5485 if (!( 5486 (milliseconds >= 0 && days >= 0 && months >= 0) || 5487 (milliseconds <= 0 && days <= 0 && months <= 0) 5488 )) { 5489 milliseconds += absCeil(monthsToDays(months) + days) * 864e5; 5490 days = 0; 5491 months = 0; 5492 } 5493 5494 // The following code bubbles up values, see the tests for 5495 // examples of what that means. 5496 data.milliseconds = milliseconds % 1000; 5497 5498 seconds = absFloor(milliseconds / 1000); 5499 data.seconds = seconds % 60; 5500 5501 minutes = absFloor(seconds / 60); 5502 data.minutes = minutes % 60; 5503 5504 hours = absFloor(minutes / 60); 5505 data.hours = hours % 24; 5506 5507 days += absFloor(hours / 24); 5508 5509 // convert days to months 5510 monthsFromDays = absFloor(daysToMonths(days)); 5511 months += monthsFromDays; 5512 days -= absCeil(monthsToDays(monthsFromDays)); 5513 5514 // 12 months -> 1 year 5515 years = absFloor(months / 12); 5516 months %= 12; 5517 5518 data.days = days; 5519 data.months = months; 5520 data.years = years; 5521 5522 return this; 5523 } 5524 5525 function daysToMonths(days) { 5526 // 400 years have 146097 days (taking into account leap year rules) 5527 // 400 years have 12 months === 4800 5528 return (days * 4800) / 146097; 5529 } 5530 5531 function monthsToDays(months) { 5532 // the reverse of daysToMonths 5533 return (months * 146097) / 4800; 5534 } 5535 5536 function as(units) { 5537 if (!this.isValid()) { 5538 return NaN; 5539 } 5540 var days, 5541 months, 5542 milliseconds = this._milliseconds; 5543 5544 units = normalizeUnits(units); 5545 5546 if (units === 'month' || units === 'quarter' || units === 'year') { 5547 days = this._days + milliseconds / 864e5; 5548 months = this._months + daysToMonths(days); 5549 switch (units) { 5550 case 'month': 5551 return months; 5552 case 'quarter': 5553 return months / 3; 5554 case 'year': 5555 return months / 12; 5556 } 5557 } else { 5558 // handle milliseconds separately because of floating point math errors (issue #1867) 5559 days = this._days + Math.round(monthsToDays(this._months)); 5560 switch (units) { 5561 case 'week': 5562 return days / 7 + milliseconds / 6048e5; 5563 case 'day': 5564 return days + milliseconds / 864e5; 5565 case 'hour': 5566 return days * 24 + milliseconds / 36e5; 5567 case 'minute': 5568 return days * 1440 + milliseconds / 6e4; 5569 case 'second': 5570 return days * 86400 + milliseconds / 1000; 5571 // Math.floor prevents floating point math errors here 5572 case 'millisecond': 5573 return Math.floor(days * 864e5) + milliseconds; 5574 default: 5575 throw new Error('Unknown unit ' + units); 5576 } 5577 } 5578 } 5579 5580 function makeAs(alias) { 5581 return function () { 5582 return this.as(alias); 5583 }; 5584 } 5585 5586 var asMilliseconds = makeAs('ms'), 5587 asSeconds = makeAs('s'), 5588 asMinutes = makeAs('m'), 5589 asHours = makeAs('h'), 5590 asDays = makeAs('d'), 5591 asWeeks = makeAs('w'), 5592 asMonths = makeAs('M'), 5593 asQuarters = makeAs('Q'), 5594 asYears = makeAs('y'), 5595 valueOf = asMilliseconds; 5596 5597 function clone() { 5598 return createDuration(this); 5599 } 5600 5601 function get(units) { 5602 units = normalizeUnits(units); 5603 return this.isValid() ? this[units + 's']() : NaN; 5604 } 5605 5606 function makeGetter(name) { 5607 return function () { 5608 return this.isValid() ? this._data[name] : NaN; 5609 }; 5610 } 5611 5612 var milliseconds = makeGetter('milliseconds'), 5613 seconds = makeGetter('seconds'), 5614 minutes = makeGetter('minutes'), 5615 hours = makeGetter('hours'), 5616 days = makeGetter('days'), 5617 months = makeGetter('months'), 5618 years = makeGetter('years'); 5619 5620 function weeks() { 5621 return absFloor(this.days() / 7); 5622 } 5623 5624 var round = Math.round, 5625 thresholds = { 5626 ss: 44, // a few seconds to seconds 5627 s: 45, // seconds to minute 5628 m: 45, // minutes to hour 5629 h: 22, // hours to day 5630 d: 26, // days to month/week 5631 w: null, // weeks to month 5632 M: 11, // months to year 5633 }; 5634 5635 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize 5636 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) { 5637 return relativeTimeWithoutPostformat.call( 5638 locale, 5639 number || 1, 5640 !!withoutSuffix, 5641 string, 5642 isFuture 5643 ); 5644 } 5645 5646 function relativeTime(posNegDuration, withoutSuffix, thresholds, locale) { 5647 var duration = createDuration(posNegDuration).abs(), 5648 seconds = round(duration.as('s')), 5649 minutes = round(duration.as('m')), 5650 hours = round(duration.as('h')), 5651 days = round(duration.as('d')), 5652 months = round(duration.as('M')), 5653 weeks = round(duration.as('w')), 5654 years = round(duration.as('y')), 5655 a = 5656 (seconds <= thresholds.ss && ['s', seconds]) || 5657 (seconds < thresholds.s && ['ss', seconds]) || 5658 (minutes <= 1 && ['m']) || 5659 (minutes < thresholds.m && ['mm', minutes]) || 5660 (hours <= 1 && ['h']) || 5661 (hours < thresholds.h && ['hh', hours]) || 5662 (days <= 1 && ['d']) || 5663 (days < thresholds.d && ['dd', days]); 5664 5665 if (thresholds.w != null) { 5666 a = 5667 a || 5668 (weeks <= 1 && ['w']) || 5669 (weeks < thresholds.w && ['ww', weeks]); 5670 } 5671 a = a || 5672 (months <= 1 && ['M']) || 5673 (months < thresholds.M && ['MM', months]) || 5674 (years <= 1 && ['y']) || ['yy', years]; 5675 5676 a[2] = withoutSuffix; 5677 a[3] = +posNegDuration > 0; 5678 a[4] = locale; 5679 return substituteTimeAgo.apply(null, a); 5680 } 5681 5682 // This function allows you to set the rounding function for relative time strings 5683 function getSetRelativeTimeRounding(roundingFunction) { 5684 if (roundingFunction === undefined) { 5685 return round; 5686 } 5687 if (typeof roundingFunction === 'function') { 5688 round = roundingFunction; 5689 return true; 5690 } 5691 return false; 5692 } 5693 5694 // This function allows you to set a threshold for relative time strings 5695 function getSetRelativeTimeThreshold(threshold, limit) { 5696 if (thresholds[threshold] === undefined) { 5697 return false; 5698 } 5699 if (limit === undefined) { 5700 return thresholds[threshold]; 5701 } 5702 thresholds[threshold] = limit; 5703 if (threshold === 's') { 5704 thresholds.ss = limit - 1; 5705 } 5706 return true; 5707 } 5708 5709 function humanize(argWithSuffix, argThresholds) { 5710 if (!this.isValid()) { 5711 return this.localeData().invalidDate(); 5712 } 5713 5714 var withSuffix = false, 5715 th = thresholds, 5716 locale, 5717 output; 5718 5719 if (typeof argWithSuffix === 'object') { 5720 argThresholds = argWithSuffix; 5721 argWithSuffix = false; 5722 } 5723 if (typeof argWithSuffix === 'boolean') { 5724 withSuffix = argWithSuffix; 5725 } 5726 if (typeof argThresholds === 'object') { 5727 th = extend(extend({}, thresholds), argThresholds || {}); 5728 if (argThresholds.s != null && argThresholds.ss == null) { 5729 th.ss = argThresholds.s - 1; 5730 } 5731 } 5732 5733 locale = this.localeData(); 5734 output = relativeTime(this, !withSuffix, th, locale); 5735 5736 if (withSuffix) { 5737 output = pastFutureWithoutPostformat.call(locale, +this, output); 5738 } 5739 5740 return locale.postformat(output); 5741 } 5742 5743 var abs = Math.abs; 5744 5745 function sign(x) { 5746 return (x > 0) - (x < 0) || +x; 5747 } 5748 5749 function toISOString() { 5750 // for ISO strings we do not use the normal bubbling rules: 5751 // * milliseconds bubble up until they become hours 5752 // * days do not bubble at all 5753 // * months bubble up until they become years 5754 // This is because there is no context-free conversion between hours and days 5755 // (think of clock changes) 5756 // and also not between days and months (28-31 days per month) 5757 if (!this.isValid()) { 5758 return this.localeData().invalidDate(); 5759 } 5760 5761 var seconds = abs(this._milliseconds) / 1000, 5762 days = abs(this._days), 5763 months = abs(this._months), 5764 minutes, 5765 hours, 5766 years, 5767 s, 5768 total = this.asSeconds(), 5769 totalSign, 5770 ymSign, 5771 daysSign, 5772 hmsSign; 5773 5774 if (!total) { 5775 // this is the same as C#'s (Noda) and python (isodate)... 5776 // but not other JS (goog.date) 5777 return 'P0D'; 5778 } 5779 5780 // 3600 seconds -> 60 minutes -> 1 hour 5781 minutes = absFloor(seconds / 60); 5782 hours = absFloor(minutes / 60); 5783 seconds %= 60; 5784 minutes %= 60; 5785 5786 // 12 months -> 1 year 5787 years = absFloor(months / 12); 5788 months %= 12; 5789 5790 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js 5791 s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : ''; 5792 5793 totalSign = total < 0 ? '-' : ''; 5794 ymSign = sign(this._months) !== sign(total) ? '-' : ''; 5795 daysSign = sign(this._days) !== sign(total) ? '-' : ''; 5796 hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : ''; 5797 5798 return ( 5799 totalSign + 5800 'P' + 5801 (years ? ymSign + years + 'Y' : '') + 5802 (months ? ymSign + months + 'M' : '') + 5803 (days ? daysSign + days + 'D' : '') + 5804 (hours || minutes || seconds ? 'T' : '') + 5805 (hours ? hmsSign + hours + 'H' : '') + 5806 (minutes ? hmsSign + minutes + 'M' : '') + 5807 (seconds ? hmsSign + s + 'S' : '') 5808 ); 5809 } 5810 5811 var proto = Duration.prototype; 5812 5813 proto.isValid = isValid$1; 5814 proto.abs = abs$1; 5815 proto.add = add; 5816 proto.subtract = subtract; 5817 proto.as = as; 5818 proto.asMilliseconds = asMilliseconds; 5819 proto.asSeconds = asSeconds; 5820 proto.asMinutes = asMinutes; 5821 proto.asHours = asHours; 5822 proto.asDays = asDays; 5823 proto.asWeeks = asWeeks; 5824 proto.asMonths = asMonths; 5825 proto.asQuarters = asQuarters; 5826 proto.asYears = asYears; 5827 proto.valueOf = valueOf; 5828 proto._bubble = bubble; 5829 proto.clone = clone; 5830 proto.get = get; 5831 proto.milliseconds = milliseconds; 5832 proto.seconds = seconds; 5833 proto.minutes = minutes; 5834 proto.hours = hours; 5835 proto.days = days; 5836 proto.weeks = weeks; 5837 proto.months = months; 5838 proto.years = years; 5839 proto.humanize = humanize; 5840 proto.toISOString = toISOString; 5841 proto.toString = toISOString; 5842 proto.toJSON = toISOString; 5843 proto.locale = locale; 5844 proto.localeData = localeData; 5845 5846 proto.toIsoString = deprecate( 5847 'toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', 5848 toISOString 5849 ); 5850 proto.lang = lang; 5851 5852 // FORMATTING 5853 5854 addFormatToken('X', 0, 0, 'unix'); 5855 addFormatToken('x', 0, 0, 'valueOf'); 5856 5857 // PARSING 5858 5859 addRegexToken('x', matchSigned); 5860 addRegexToken('X', matchTimestamp); 5861 addParseToken('X', function (input, array, config) { 5862 config._d = new Date(parseFloat(input) * 1000); 5863 }); 5864 addParseToken('x', function (input, array, config) { 5865 config._d = new Date(toInt(input)); 5866 }); 5867 5868 //! moment.js 5869 5870 hooks.version = '2.31.0'; 5871 5872 setHookCallback(createLocal); 5873 5874 hooks.fn = proto$2; 5875 hooks.min = min; 5876 hooks.max = max; 5877 hooks.now = now; 5878 hooks.utc = createUTC; 5879 hooks.unix = createUnix; 5880 hooks.months = listMonths; 5881 hooks.isDate = isDate; 5882 hooks.locale = getSetGlobalLocale; 5883 hooks.invalid = createInvalid$1; 5884 hooks.duration = createDuration; 5885 hooks.isMoment = isMoment; 5886 hooks.weekdays = listWeekdays; 5887 hooks.parseZone = createInZone; 5888 hooks.localeData = getLocale; 5889 hooks.isDuration = isDuration; 5890 hooks.monthsShort = listMonthsShort; 5891 hooks.weekdaysMin = listWeekdaysMin; 5892 hooks.defineLocale = defineLocale; 5893 hooks.updateLocale = updateLocale; 5894 hooks.locales = listLocales; 5895 hooks.weekdaysShort = listWeekdaysShort; 5896 hooks.normalizeUnits = normalizeUnits; 5897 hooks.relativeTimeRounding = getSetRelativeTimeRounding; 5898 hooks.relativeTimeThreshold = getSetRelativeTimeThreshold; 5899 hooks.calendarFormat = getCalendarFormat; 5900 hooks.prototype = proto$2; 5901 5902 // currently HTML5 input type only supports 24-hour formats 5903 hooks.HTML5_FMT = { 5904 DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" /> 5905 DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" /> 5906 DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" /> 5907 DATE: 'YYYY-MM-DD', // <input type="date" /> 5908 TIME: 'HH:mm', // <input type="time" /> 5909 TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" /> 5910 TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" /> 5911 WEEK: 'GGGG-[W]WW', // <input type="week" /> 5912 MONTH: 'YYYY-MM', // <input type="month" /> 5913 }; 5914 5915 return hooks; 5916 5917 })));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Oct 29 08:20:35 2026 | Cross-referenced by PHPXref |