123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _index = _interopRequireDefault(require("../../../_lib/getUTCWeekYear/index.js"));
- var _index2 = _interopRequireDefault(require("../../../_lib/setUTCDay/index.js"));
- var _index3 = _interopRequireDefault(require("../../../_lib/setUTCISODay/index.js"));
- var _index4 = _interopRequireDefault(require("../../../_lib/setUTCISOWeek/index.js"));
- var _index5 = _interopRequireDefault(require("../../../_lib/setUTCWeek/index.js"));
- var _index6 = _interopRequireDefault(require("../../../_lib/startOfUTCISOWeek/index.js"));
- var _index7 = _interopRequireDefault(require("../../../_lib/startOfUTCWeek/index.js"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var MILLISECONDS_IN_HOUR = 3600000;
- var MILLISECONDS_IN_MINUTE = 60000;
- var MILLISECONDS_IN_SECOND = 1000;
- var numericPatterns = {
- month: /^(1[0-2]|0?\d)/,
- // 0 to 12
- date: /^(3[0-1]|[0-2]?\d)/,
- // 0 to 31
- dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
- // 0 to 366
- week: /^(5[0-3]|[0-4]?\d)/,
- // 0 to 53
- hour23h: /^(2[0-3]|[0-1]?\d)/,
- // 0 to 23
- hour24h: /^(2[0-4]|[0-1]?\d)/,
- // 0 to 24
- hour11h: /^(1[0-1]|0?\d)/,
- // 0 to 11
- hour12h: /^(1[0-2]|0?\d)/,
- // 0 to 12
- minute: /^[0-5]?\d/,
- // 0 to 59
- second: /^[0-5]?\d/,
- // 0 to 59
- singleDigit: /^\d/,
- // 0 to 9
- twoDigits: /^\d{1,2}/,
- // 0 to 99
- threeDigits: /^\d{1,3}/,
- // 0 to 999
- fourDigits: /^\d{1,4}/,
- // 0 to 9999
- anyDigitsSigned: /^-?\d+/,
- singleDigitSigned: /^-?\d/,
- // 0 to 9, -0 to -9
- twoDigitsSigned: /^-?\d{1,2}/,
- // 0 to 99, -0 to -99
- threeDigitsSigned: /^-?\d{1,3}/,
- // 0 to 999, -0 to -999
- fourDigitsSigned: /^-?\d{1,4}/ // 0 to 9999, -0 to -9999
- };
- var timezonePatterns = {
- basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
- basic: /^([+-])(\d{2})(\d{2})|Z/,
- basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
- extended: /^([+-])(\d{2}):(\d{2})|Z/,
- extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
- };
- function parseNumericPattern(pattern, string, valueCallback) {
- var matchResult = string.match(pattern);
- if (!matchResult) {
- return null;
- }
- var value = parseInt(matchResult[0], 10);
- return {
- value: valueCallback ? valueCallback(value) : value,
- rest: string.slice(matchResult[0].length)
- };
- }
- function parseTimezonePattern(pattern, string) {
- var matchResult = string.match(pattern);
- if (!matchResult) {
- return null;
- } // Input is 'Z'
- if (matchResult[0] === 'Z') {
- return {
- value: 0,
- rest: string.slice(1)
- };
- }
- var sign = matchResult[1] === '+' ? 1 : -1;
- var hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
- var minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
- var seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
- return {
- value: sign * (hours * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE + seconds * MILLISECONDS_IN_SECOND),
- rest: string.slice(matchResult[0].length)
- };
- }
- function parseAnyDigitsSigned(string, valueCallback) {
- return parseNumericPattern(numericPatterns.anyDigitsSigned, string, valueCallback);
- }
- function parseNDigits(n, string, valueCallback) {
- switch (n) {
- case 1:
- return parseNumericPattern(numericPatterns.singleDigit, string, valueCallback);
- case 2:
- return parseNumericPattern(numericPatterns.twoDigits, string, valueCallback);
- case 3:
- return parseNumericPattern(numericPatterns.threeDigits, string, valueCallback);
- case 4:
- return parseNumericPattern(numericPatterns.fourDigits, string, valueCallback);
- default:
- return parseNumericPattern(new RegExp('^\\d{1,' + n + '}'), string, valueCallback);
- }
- }
- function parseNDigitsSigned(n, string, valueCallback) {
- switch (n) {
- case 1:
- return parseNumericPattern(numericPatterns.singleDigitSigned, string, valueCallback);
- case 2:
- return parseNumericPattern(numericPatterns.twoDigitsSigned, string, valueCallback);
- case 3:
- return parseNumericPattern(numericPatterns.threeDigitsSigned, string, valueCallback);
- case 4:
- return parseNumericPattern(numericPatterns.fourDigitsSigned, string, valueCallback);
- default:
- return parseNumericPattern(new RegExp('^-?\\d{1,' + n + '}'), string, valueCallback);
- }
- }
- function dayPeriodEnumToHours(enumValue) {
- switch (enumValue) {
- case 'morning':
- return 4;
- case 'evening':
- return 17;
- case 'pm':
- case 'noon':
- case 'afternoon':
- return 12;
- case 'am':
- case 'midnight':
- case 'night':
- default:
- return 0;
- }
- }
- function normalizeTwoDigitYear(twoDigitYear, currentYear) {
- var isCommonEra = currentYear > 0; // Absolute number of the current year:
- // 1 -> 1 AC
- // 0 -> 1 BC
- // -1 -> 2 BC
- var absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
- var result;
- if (absCurrentYear <= 50) {
- result = twoDigitYear || 100;
- } else {
- var rangeEnd = absCurrentYear + 50;
- var rangeEndCentury = Math.floor(rangeEnd / 100) * 100;
- var isPreviousCentury = twoDigitYear >= rangeEnd % 100;
- result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
- }
- return isCommonEra ? result : 1 - result;
- }
- var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- var DAYS_IN_MONTH_LEAP_YEAR = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // User for validation
- function isLeapYearIndex(year) {
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
- }
- /*
- * | | Unit | | Unit |
- * |-----|--------------------------------|-----|--------------------------------|
- * | a | AM, PM | A* | Milliseconds in day |
- * | b | AM, PM, noon, midnight | B | Flexible day period |
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
- * | d | Day of month | D | Day of year |
- * | e | Local day of week | E | Day of week |
- * | f | | F* | Day of week in month |
- * | g* | Modified Julian day | G | Era |
- * | h | Hour [1-12] | H | Hour [0-23] |
- * | i! | ISO day of week | I! | ISO week of year |
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
- * | k | Hour [1-24] | K | Hour [0-11] |
- * | l* | (deprecated) | L | Stand-alone month |
- * | m | Minute | M | Month |
- * | n | | N | |
- * | o! | Ordinal number modifier | O* | Timezone (GMT) |
- * | p | | P | |
- * | q | Stand-alone quarter | Q | Quarter |
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
- * | s | Second | S | Fraction of second |
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
- * | u | Extended year | U* | Cyclic year |
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
- * | w | Local week of year | W* | Week of month |
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
- * | y | Year (abs) | Y | Local week-numbering year |
- * | z* | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
- *
- * Letters marked by * are not implemented but reserved by Unicode standard.
- *
- * Letters marked by ! are non-standard, but implemented by date-fns:
- * - `o` modifies the previous token to turn it into an ordinal (see `parse` docs)
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
- * i.e. 7 for Sunday, 1 for Monday, etc.
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
- * `R` is supposed to be used in conjunction with `I` and `i`
- * for universal ISO week-numbering date, whereas
- * `Y` is supposed to be used in conjunction with `w` and `e`
- * for week-numbering date specific to the locale.
- */
- var parsers = {
- // Era
- G: {
- priority: 140,
- parse: function (string, token, match, _options) {
- switch (token) {
- // AD, BC
- case 'G':
- case 'GG':
- case 'GGG':
- return match.era(string, {
- width: 'abbreviated'
- }) || match.era(string, {
- width: 'narrow'
- });
- // A, B
- case 'GGGGG':
- return match.era(string, {
- width: 'narrow'
- });
- // Anno Domini, Before Christ
- case 'GGGG':
- default:
- return match.era(string, {
- width: 'wide'
- }) || match.era(string, {
- width: 'abbreviated'
- }) || match.era(string, {
- width: 'narrow'
- });
- }
- },
- set: function (date, flags, value, _options) {
- flags.era = value;
- date.setUTCFullYear(value, 0, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['R', 'u', 't', 'T']
- },
- // Year
- y: {
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
- // | Year | y | yy | yyy | yyyy | yyyyy |
- // |----------|-------|----|-------|-------|-------|
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
- priority: 130,
- parse: function (string, token, match, _options) {
- var valueCallback = function (year) {
- return {
- year: year,
- isTwoDigitYear: token === 'yy'
- };
- };
- switch (token) {
- case 'y':
- return parseNDigits(4, string, valueCallback);
- case 'yo':
- return match.ordinalNumber(string, {
- unit: 'year',
- valueCallback: valueCallback
- });
- default:
- return parseNDigits(token.length, string, valueCallback);
- }
- },
- validate: function (_date, value, _options) {
- return value.isTwoDigitYear || value.year > 0;
- },
- set: function (date, flags, value, _options) {
- var currentYear = date.getUTCFullYear();
- if (value.isTwoDigitYear) {
- var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
- date.setUTCFullYear(normalizedTwoDigitYear, 0, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- }
- var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year;
- date.setUTCFullYear(year, 0, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'u', 'w', 'I', 'i', 'e', 'c', 't', 'T']
- },
- // Local week-numbering year
- Y: {
- priority: 130,
- parse: function (string, token, match, _options) {
- var valueCallback = function (year) {
- return {
- year: year,
- isTwoDigitYear: token === 'YY'
- };
- };
- switch (token) {
- case 'Y':
- return parseNDigits(4, string, valueCallback);
- case 'Yo':
- return match.ordinalNumber(string, {
- unit: 'year',
- valueCallback: valueCallback
- });
- default:
- return parseNDigits(token.length, string, valueCallback);
- }
- },
- validate: function (_date, value, _options) {
- return value.isTwoDigitYear || value.year > 0;
- },
- set: function (date, flags, value, options) {
- var currentYear = (0, _index.default)(date, options);
- if (value.isTwoDigitYear) {
- var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
- date.setUTCFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate);
- date.setUTCHours(0, 0, 0, 0);
- return (0, _index7.default)(date, options);
- }
- var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year;
- date.setUTCFullYear(year, 0, options.firstWeekContainsDate);
- date.setUTCHours(0, 0, 0, 0);
- return (0, _index7.default)(date, options);
- },
- incompatibleTokens: ['y', 'R', 'u', 'Q', 'q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T']
- },
- // ISO week-numbering year
- R: {
- priority: 130,
- parse: function (string, token, _match, _options) {
- if (token === 'R') {
- return parseNDigitsSigned(4, string);
- }
- return parseNDigitsSigned(token.length, string);
- },
- set: function (_date, _flags, value, _options) {
- var firstWeekOfYear = new Date(0);
- firstWeekOfYear.setUTCFullYear(value, 0, 4);
- firstWeekOfYear.setUTCHours(0, 0, 0, 0);
- return (0, _index6.default)(firstWeekOfYear);
- },
- incompatibleTokens: ['G', 'y', 'Y', 'u', 'Q', 'q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T']
- },
- // Extended year
- u: {
- priority: 130,
- parse: function (string, token, _match, _options) {
- if (token === 'u') {
- return parseNDigitsSigned(4, string);
- }
- return parseNDigitsSigned(token.length, string);
- },
- set: function (date, _flags, value, _options) {
- date.setUTCFullYear(value, 0, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['G', 'y', 'Y', 'R', 'w', 'I', 'i', 'e', 'c', 't', 'T']
- },
- // Quarter
- Q: {
- priority: 120,
- parse: function (string, token, match, _options) {
- switch (token) {
- // 1, 2, 3, 4
- case 'Q':
- case 'QQ':
- // 01, 02, 03, 04
- return parseNDigits(token.length, string);
- // 1st, 2nd, 3rd, 4th
- case 'Qo':
- return match.ordinalNumber(string, {
- unit: 'quarter'
- });
- // Q1, Q2, Q3, Q4
- case 'QQQ':
- return match.quarter(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.quarter(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
- case 'QQQQQ':
- return match.quarter(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // 1st quarter, 2nd quarter, ...
- case 'QQQQ':
- default:
- return match.quarter(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.quarter(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.quarter(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 4;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMonth((value - 1) * 3, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T']
- },
- // Stand-alone quarter
- q: {
- priority: 120,
- parse: function (string, token, match, _options) {
- switch (token) {
- // 1, 2, 3, 4
- case 'q':
- case 'qq':
- // 01, 02, 03, 04
- return parseNDigits(token.length, string);
- // 1st, 2nd, 3rd, 4th
- case 'qo':
- return match.ordinalNumber(string, {
- unit: 'quarter'
- });
- // Q1, Q2, Q3, Q4
- case 'qqq':
- return match.quarter(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.quarter(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
- case 'qqqqq':
- return match.quarter(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // 1st quarter, 2nd quarter, ...
- case 'qqqq':
- default:
- return match.quarter(string, {
- width: 'wide',
- context: 'standalone'
- }) || match.quarter(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.quarter(string, {
- width: 'narrow',
- context: 'standalone'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 4;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMonth((value - 1) * 3, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'Q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T']
- },
- // Month
- M: {
- priority: 110,
- parse: function (string, token, match, _options) {
- var valueCallback = function (value) {
- return value - 1;
- };
- switch (token) {
- // 1, 2, ..., 12
- case 'M':
- return parseNumericPattern(numericPatterns.month, string, valueCallback);
- // 01, 02, ..., 12
- case 'MM':
- return parseNDigits(2, string, valueCallback);
- // 1st, 2nd, ..., 12th
- case 'Mo':
- return match.ordinalNumber(string, {
- unit: 'month',
- valueCallback: valueCallback
- });
- // Jan, Feb, ..., Dec
- case 'MMM':
- return match.month(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.month(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // J, F, ..., D
- case 'MMMMM':
- return match.month(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // January, February, ..., December
- case 'MMMM':
- default:
- return match.month(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.month(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.month(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 11;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMonth(value, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'q', 'Q', 'L', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']
- },
- // Stand-alone month
- L: {
- priority: 110,
- parse: function (string, token, match, _options) {
- var valueCallback = function (value) {
- return value - 1;
- };
- switch (token) {
- // 1, 2, ..., 12
- case 'L':
- return parseNumericPattern(numericPatterns.month, string, valueCallback);
- // 01, 02, ..., 12
- case 'LL':
- return parseNDigits(2, string, valueCallback);
- // 1st, 2nd, ..., 12th
- case 'Lo':
- return match.ordinalNumber(string, {
- unit: 'month',
- valueCallback: valueCallback
- });
- // Jan, Feb, ..., Dec
- case 'LLL':
- return match.month(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.month(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // J, F, ..., D
- case 'LLLLL':
- return match.month(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // January, February, ..., December
- case 'LLLL':
- default:
- return match.month(string, {
- width: 'wide',
- context: 'standalone'
- }) || match.month(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.month(string, {
- width: 'narrow',
- context: 'standalone'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 11;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMonth(value, 1);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'q', 'Q', 'M', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']
- },
- // Local week of year
- w: {
- priority: 100,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'w':
- return parseNumericPattern(numericPatterns.week, string);
- case 'wo':
- return match.ordinalNumber(string, {
- unit: 'week'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 53;
- },
- set: function (date, _flags, value, options) {
- return (0, _index7.default)((0, _index5.default)(date, value, options), options);
- },
- incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T']
- },
- // ISO week of year
- I: {
- priority: 100,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'I':
- return parseNumericPattern(numericPatterns.week, string);
- case 'Io':
- return match.ordinalNumber(string, {
- unit: 'week'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 53;
- },
- set: function (date, _flags, value, options) {
- return (0, _index6.default)((0, _index4.default)(date, value, options), options);
- },
- incompatibleTokens: ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T']
- },
- // Day of the month
- d: {
- priority: 90,
- subPriority: 1,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'd':
- return parseNumericPattern(numericPatterns.date, string);
- case 'do':
- return match.ordinalNumber(string, {
- unit: 'date'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (date, value, _options) {
- var year = date.getUTCFullYear();
- var isLeapYear = isLeapYearIndex(year);
- var month = date.getUTCMonth();
- if (isLeapYear) {
- return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month];
- } else {
- return value >= 1 && value <= DAYS_IN_MONTH[month];
- }
- },
- set: function (date, _flags, value, _options) {
- date.setUTCDate(value);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'q', 'Q', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']
- },
- // Day of year
- D: {
- priority: 90,
- subPriority: 1,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'D':
- case 'DD':
- return parseNumericPattern(numericPatterns.dayOfYear, string);
- case 'Do':
- return match.ordinalNumber(string, {
- unit: 'date'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (date, value, _options) {
- var year = date.getUTCFullYear();
- var isLeapYear = isLeapYearIndex(year);
- if (isLeapYear) {
- return value >= 1 && value <= 366;
- } else {
- return value >= 1 && value <= 365;
- }
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMonth(0, value);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['Y', 'R', 'q', 'Q', 'M', 'L', 'w', 'I', 'd', 'E', 'i', 'e', 'c', 't', 'T']
- },
- // Day of week
- E: {
- priority: 90,
- parse: function (string, token, match, _options) {
- switch (token) {
- // Tue
- case 'E':
- case 'EE':
- case 'EEE':
- return match.day(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // T
- case 'EEEEE':
- return match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // Tu
- case 'EEEEEE':
- return match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // Tuesday
- case 'EEEE':
- default:
- return match.day(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.day(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 6;
- },
- set: function (date, _flags, value, options) {
- date = (0, _index2.default)(date, value, options);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['D', 'i', 'e', 'c', 't', 'T']
- },
- // Local day of week
- e: {
- priority: 90,
- parse: function (string, token, match, options) {
- var valueCallback = function (value) {
- var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
- return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
- };
- switch (token) {
- // 3
- case 'e':
- case 'ee':
- // 03
- return parseNDigits(token.length, string, valueCallback);
- // 3rd
- case 'eo':
- return match.ordinalNumber(string, {
- unit: 'day',
- valueCallback: valueCallback
- });
- // Tue
- case 'eee':
- return match.day(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // T
- case 'eeeee':
- return match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // Tu
- case 'eeeeee':
- return match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- // Tuesday
- case 'eeee':
- default:
- return match.day(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.day(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.day(string, {
- width: 'short',
- context: 'formatting'
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 6;
- },
- set: function (date, _flags, value, options) {
- date = (0, _index2.default)(date, value, options);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'c', 't', 'T']
- },
- // Stand-alone local day of week
- c: {
- priority: 90,
- parse: function (string, token, match, options) {
- var valueCallback = function (value) {
- var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
- return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
- };
- switch (token) {
- // 3
- case 'c':
- case 'cc':
- // 03
- return parseNDigits(token.length, string, valueCallback);
- // 3rd
- case 'co':
- return match.ordinalNumber(string, {
- unit: 'day',
- valueCallback: valueCallback
- });
- // Tue
- case 'ccc':
- return match.day(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.day(string, {
- width: 'short',
- context: 'standalone'
- }) || match.day(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // T
- case 'ccccc':
- return match.day(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // Tu
- case 'cccccc':
- return match.day(string, {
- width: 'short',
- context: 'standalone'
- }) || match.day(string, {
- width: 'narrow',
- context: 'standalone'
- });
- // Tuesday
- case 'cccc':
- default:
- return match.day(string, {
- width: 'wide',
- context: 'standalone'
- }) || match.day(string, {
- width: 'abbreviated',
- context: 'standalone'
- }) || match.day(string, {
- width: 'short',
- context: 'standalone'
- }) || match.day(string, {
- width: 'narrow',
- context: 'standalone'
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 6;
- },
- set: function (date, _flags, value, options) {
- date = (0, _index2.default)(date, value, options);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'e', 't', 'T']
- },
- // ISO day of week
- i: {
- priority: 90,
- parse: function (string, token, match, _options) {
- var valueCallback = function (value) {
- if (value === 0) {
- return 7;
- }
- return value;
- };
- switch (token) {
- // 2
- case 'i':
- case 'ii':
- // 02
- return parseNDigits(token.length, string);
- // 2nd
- case 'io':
- return match.ordinalNumber(string, {
- unit: 'day'
- });
- // Tue
- case 'iii':
- return match.day(string, {
- width: 'abbreviated',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'short',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting',
- valueCallback: valueCallback
- });
- // T
- case 'iiiii':
- return match.day(string, {
- width: 'narrow',
- context: 'formatting',
- valueCallback: valueCallback
- });
- // Tu
- case 'iiiiii':
- return match.day(string, {
- width: 'short',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting',
- valueCallback: valueCallback
- });
- // Tuesday
- case 'iiii':
- default:
- return match.day(string, {
- width: 'wide',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'abbreviated',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'short',
- context: 'formatting',
- valueCallback: valueCallback
- }) || match.day(string, {
- width: 'narrow',
- context: 'formatting',
- valueCallback: valueCallback
- });
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 7;
- },
- set: function (date, _flags, value, options) {
- date = (0, _index3.default)(date, value, options);
- date.setUTCHours(0, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'E', 'e', 'c', 't', 'T']
- },
- // AM or PM
- a: {
- priority: 80,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'a':
- case 'aa':
- case 'aaa':
- return match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'aaaaa':
- return match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'aaaa':
- default:
- return match.dayPeriod(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- set: function (date, _flags, value, _options) {
- date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['b', 'B', 'H', 'K', 'k', 't', 'T']
- },
- // AM, PM, midnight
- b: {
- priority: 80,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'b':
- case 'bb':
- case 'bbb':
- return match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'bbbbb':
- return match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'bbbb':
- default:
- return match.dayPeriod(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- set: function (date, _flags, value, _options) {
- date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['a', 'B', 'H', 'K', 'k', 't', 'T']
- },
- // in the morning, in the afternoon, in the evening, at night
- B: {
- priority: 80,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'B':
- case 'BB':
- case 'BBB':
- return match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'BBBBB':
- return match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- case 'BBBB':
- default:
- return match.dayPeriod(string, {
- width: 'wide',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'abbreviated',
- context: 'formatting'
- }) || match.dayPeriod(string, {
- width: 'narrow',
- context: 'formatting'
- });
- }
- },
- set: function (date, _flags, value, _options) {
- date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['a', 'b', 't', 'T']
- },
- // Hour [1-12]
- h: {
- priority: 70,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'h':
- return parseNumericPattern(numericPatterns.hour12h, string);
- case 'ho':
- return match.ordinalNumber(string, {
- unit: 'hour'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 12;
- },
- set: function (date, _flags, value, _options) {
- var isPM = date.getUTCHours() >= 12;
- if (isPM && value < 12) {
- date.setUTCHours(value + 12, 0, 0, 0);
- } else if (!isPM && value === 12) {
- date.setUTCHours(0, 0, 0, 0);
- } else {
- date.setUTCHours(value, 0, 0, 0);
- }
- return date;
- },
- incompatibleTokens: ['H', 'K', 'k', 't', 'T']
- },
- // Hour [0-23]
- H: {
- priority: 70,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'H':
- return parseNumericPattern(numericPatterns.hour23h, string);
- case 'Ho':
- return match.ordinalNumber(string, {
- unit: 'hour'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 23;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCHours(value, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['a', 'b', 'h', 'K', 'k', 't', 'T']
- },
- // Hour [0-11]
- K: {
- priority: 70,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'K':
- return parseNumericPattern(numericPatterns.hour11h, string);
- case 'Ko':
- return match.ordinalNumber(string, {
- unit: 'hour'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 11;
- },
- set: function (date, _flags, value, _options) {
- var isPM = date.getUTCHours() >= 12;
- if (isPM && value < 12) {
- date.setUTCHours(value + 12, 0, 0, 0);
- } else {
- date.setUTCHours(value, 0, 0, 0);
- }
- return date;
- },
- incompatibleTokens: ['a', 'b', 'h', 'H', 'k', 't', 'T']
- },
- // Hour [1-24]
- k: {
- priority: 70,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'k':
- return parseNumericPattern(numericPatterns.hour24h, string);
- case 'ko':
- return match.ordinalNumber(string, {
- unit: 'hour'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 1 && value <= 24;
- },
- set: function (date, _flags, value, _options) {
- var hours = value <= 24 ? value % 24 : value;
- date.setUTCHours(hours, 0, 0, 0);
- return date;
- },
- incompatibleTokens: ['a', 'b', 'h', 'H', 'K', 't', 'T']
- },
- // Minute
- m: {
- priority: 60,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 'm':
- return parseNumericPattern(numericPatterns.minute, string);
- case 'mo':
- return match.ordinalNumber(string, {
- unit: 'minute'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 59;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMinutes(value, 0, 0);
- return date;
- },
- incompatibleTokens: ['t', 'T']
- },
- // Second
- s: {
- priority: 50,
- parse: function (string, token, match, _options) {
- switch (token) {
- case 's':
- return parseNumericPattern(numericPatterns.second, string);
- case 'so':
- return match.ordinalNumber(string, {
- unit: 'second'
- });
- default:
- return parseNDigits(token.length, string);
- }
- },
- validate: function (_date, value, _options) {
- return value >= 0 && value <= 59;
- },
- set: function (date, _flags, value, _options) {
- date.setUTCSeconds(value, 0);
- return date;
- },
- incompatibleTokens: ['t', 'T']
- },
- // Fraction of second
- S: {
- priority: 30,
- parse: function (string, token, _match, _options) {
- var valueCallback = function (value) {
- return Math.floor(value * Math.pow(10, -token.length + 3));
- };
- return parseNDigits(token.length, string, valueCallback);
- },
- set: function (date, _flags, value, _options) {
- date.setUTCMilliseconds(value);
- return date;
- },
- incompatibleTokens: ['t', 'T']
- },
- // Timezone (ISO-8601. +00:00 is `'Z'`)
- X: {
- priority: 10,
- parse: function (string, token, _match, _options) {
- switch (token) {
- case 'X':
- return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, string);
- case 'XX':
- return parseTimezonePattern(timezonePatterns.basic, string);
- case 'XXXX':
- return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, string);
- case 'XXXXX':
- return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, string);
- case 'XXX':
- default:
- return parseTimezonePattern(timezonePatterns.extended, string);
- }
- },
- set: function (date, flags, value, _options) {
- if (flags.timestampIsSet) {
- return date;
- }
- return new Date(date.getTime() - value);
- },
- incompatibleTokens: ['t', 'T', 'x']
- },
- // Timezone (ISO-8601)
- x: {
- priority: 10,
- parse: function (string, token, _match, _options) {
- switch (token) {
- case 'x':
- return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, string);
- case 'xx':
- return parseTimezonePattern(timezonePatterns.basic, string);
- case 'xxxx':
- return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, string);
- case 'xxxxx':
- return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, string);
- case 'xxx':
- default:
- return parseTimezonePattern(timezonePatterns.extended, string);
- }
- },
- set: function (date, flags, value, _options) {
- if (flags.timestampIsSet) {
- return date;
- }
- return new Date(date.getTime() - value);
- },
- incompatibleTokens: ['t', 'T', 'X']
- },
- // Seconds timestamp
- t: {
- priority: 40,
- parse: function (string, _token, _match, _options) {
- return parseAnyDigitsSigned(string);
- },
- set: function (_date, _flags, value, _options) {
- return [new Date(value * 1000), {
- timestampIsSet: true
- }];
- },
- incompatibleTokens: '*'
- },
- // Milliseconds timestamp
- T: {
- priority: 20,
- parse: function (string, _token, _match, _options) {
- return parseAnyDigitsSigned(string);
- },
- set: function (_date, _flags, value, _options) {
- return [new Date(value), {
- timestampIsSet: true
- }];
- },
- incompatibleTokens: '*'
- }
- };
- var _default = parsers;
- exports.default = _default;
- module.exports = exports.default;
|