60p82u21t54k 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,3911 +55,6 @@ const config = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
55
55
  getConfig,
56
56
  setConfig
57
57
  }, Symbol.toStringTag, { value: "Module" }));
58
- const millisecondsInWeek = 6048e5;
59
- const millisecondsInDay = 864e5;
60
- const millisecondsInMinute = 6e4;
61
- const millisecondsInHour = 36e5;
62
- const millisecondsInSecond = 1e3;
63
- const constructFromSymbol = Symbol.for("constructDateFrom");
64
- function constructFrom(date, value) {
65
- if (typeof date === "function") return date(value);
66
- if (date && typeof date === "object" && constructFromSymbol in date)
67
- return date[constructFromSymbol](value);
68
- if (date instanceof Date) return new date.constructor(value);
69
- return new Date(value);
70
- }
71
- function toDate$1(argument, context) {
72
- return constructFrom(context || argument, argument);
73
- }
74
- function addDays(date, amount, options) {
75
- const _date = toDate$1(date, options == null ? void 0 : options.in);
76
- if (isNaN(amount)) return constructFrom((options == null ? void 0 : options.in) || date, NaN);
77
- if (!amount) return _date;
78
- _date.setDate(_date.getDate() + amount);
79
- return _date;
80
- }
81
- let defaultOptions = {};
82
- function getDefaultOptions$1() {
83
- return defaultOptions;
84
- }
85
- function startOfWeek(date, options) {
86
- var _a, _b, _c, _d, _e, _f, _g, _h;
87
- const defaultOptions2 = getDefaultOptions$1();
88
- const weekStartsOn = (_h = (_g = (_d = (_c = options == null ? void 0 : options.weekStartsOn) != null ? _c : (_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.weekStartsOn) != null ? _d : defaultOptions2.weekStartsOn) != null ? _g : (_f = (_e = defaultOptions2.locale) == null ? void 0 : _e.options) == null ? void 0 : _f.weekStartsOn) != null ? _h : 0;
89
- const _date = toDate$1(date, options == null ? void 0 : options.in);
90
- const day = _date.getDay();
91
- const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
92
- _date.setDate(_date.getDate() - diff);
93
- _date.setHours(0, 0, 0, 0);
94
- return _date;
95
- }
96
- function startOfISOWeek(date, options) {
97
- return startOfWeek(date, __spreadProps(__spreadValues({}, options), { weekStartsOn: 1 }));
98
- }
99
- function getISOWeekYear(date, options) {
100
- const _date = toDate$1(date, options == null ? void 0 : options.in);
101
- const year = _date.getFullYear();
102
- const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
103
- fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
104
- fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
105
- const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
106
- const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
107
- fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
108
- fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
109
- const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
110
- if (_date.getTime() >= startOfNextYear.getTime()) {
111
- return year + 1;
112
- } else if (_date.getTime() >= startOfThisYear.getTime()) {
113
- return year;
114
- } else {
115
- return year - 1;
116
- }
117
- }
118
- function getTimezoneOffsetInMilliseconds$1(date) {
119
- const _date = toDate$1(date);
120
- const utcDate = new Date(
121
- Date.UTC(
122
- _date.getFullYear(),
123
- _date.getMonth(),
124
- _date.getDate(),
125
- _date.getHours(),
126
- _date.getMinutes(),
127
- _date.getSeconds(),
128
- _date.getMilliseconds()
129
- )
130
- );
131
- utcDate.setUTCFullYear(_date.getFullYear());
132
- return +date - +utcDate;
133
- }
134
- function normalizeDates(context, ...dates) {
135
- const normalize = constructFrom.bind(
136
- null,
137
- dates.find((date) => typeof date === "object")
138
- );
139
- return dates.map(normalize);
140
- }
141
- function startOfDay(date, options) {
142
- const _date = toDate$1(date, options == null ? void 0 : options.in);
143
- _date.setHours(0, 0, 0, 0);
144
- return _date;
145
- }
146
- function differenceInCalendarDays(laterDate, earlierDate, options) {
147
- const [laterDate_, earlierDate_] = normalizeDates(
148
- options == null ? void 0 : options.in,
149
- laterDate,
150
- earlierDate
151
- );
152
- const laterStartOfDay = startOfDay(laterDate_);
153
- const earlierStartOfDay = startOfDay(earlierDate_);
154
- const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds$1(laterStartOfDay);
155
- const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds$1(earlierStartOfDay);
156
- return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
157
- }
158
- function startOfISOWeekYear(date, options) {
159
- const year = getISOWeekYear(date, options);
160
- const fourthOfJanuary = constructFrom(date, 0);
161
- fourthOfJanuary.setFullYear(year, 0, 4);
162
- fourthOfJanuary.setHours(0, 0, 0, 0);
163
- return startOfISOWeek(fourthOfJanuary);
164
- }
165
- function isDate(value) {
166
- return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
167
- }
168
- function isValid(date) {
169
- return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate$1(date)));
170
- }
171
- function startOfYear(date, options) {
172
- const date_ = toDate$1(date, options == null ? void 0 : options.in);
173
- date_.setFullYear(date_.getFullYear(), 0, 1);
174
- date_.setHours(0, 0, 0, 0);
175
- return date_;
176
- }
177
- const formatDistanceLocale = {
178
- lessThanXSeconds: {
179
- one: "less than a second",
180
- other: "less than {{count}} seconds"
181
- },
182
- xSeconds: {
183
- one: "1 second",
184
- other: "{{count}} seconds"
185
- },
186
- halfAMinute: "half a minute",
187
- lessThanXMinutes: {
188
- one: "less than a minute",
189
- other: "less than {{count}} minutes"
190
- },
191
- xMinutes: {
192
- one: "1 minute",
193
- other: "{{count}} minutes"
194
- },
195
- aboutXHours: {
196
- one: "about 1 hour",
197
- other: "about {{count}} hours"
198
- },
199
- xHours: {
200
- one: "1 hour",
201
- other: "{{count}} hours"
202
- },
203
- xDays: {
204
- one: "1 day",
205
- other: "{{count}} days"
206
- },
207
- aboutXWeeks: {
208
- one: "about 1 week",
209
- other: "about {{count}} weeks"
210
- },
211
- xWeeks: {
212
- one: "1 week",
213
- other: "{{count}} weeks"
214
- },
215
- aboutXMonths: {
216
- one: "about 1 month",
217
- other: "about {{count}} months"
218
- },
219
- xMonths: {
220
- one: "1 month",
221
- other: "{{count}} months"
222
- },
223
- aboutXYears: {
224
- one: "about 1 year",
225
- other: "about {{count}} years"
226
- },
227
- xYears: {
228
- one: "1 year",
229
- other: "{{count}} years"
230
- },
231
- overXYears: {
232
- one: "over 1 year",
233
- other: "over {{count}} years"
234
- },
235
- almostXYears: {
236
- one: "almost 1 year",
237
- other: "almost {{count}} years"
238
- }
239
- };
240
- const formatDistance = (token, count, options) => {
241
- let result;
242
- const tokenValue = formatDistanceLocale[token];
243
- if (typeof tokenValue === "string") {
244
- result = tokenValue;
245
- } else if (count === 1) {
246
- result = tokenValue.one;
247
- } else {
248
- result = tokenValue.other.replace("{{count}}", count.toString());
249
- }
250
- if (options == null ? void 0 : options.addSuffix) {
251
- if (options.comparison && options.comparison > 0) {
252
- return "in " + result;
253
- } else {
254
- return result + " ago";
255
- }
256
- }
257
- return result;
258
- };
259
- function buildFormatLongFn(args) {
260
- return (options = {}) => {
261
- const width = options.width ? String(options.width) : args.defaultWidth;
262
- const format2 = args.formats[width] || args.formats[args.defaultWidth];
263
- return format2;
264
- };
265
- }
266
- const dateFormats = {
267
- full: "EEEE, MMMM do, y",
268
- long: "MMMM do, y",
269
- medium: "MMM d, y",
270
- short: "MM/dd/yyyy"
271
- };
272
- const timeFormats = {
273
- full: "h:mm:ss a zzzz",
274
- long: "h:mm:ss a z",
275
- medium: "h:mm:ss a",
276
- short: "h:mm a"
277
- };
278
- const dateTimeFormats = {
279
- full: "{{date}} 'at' {{time}}",
280
- long: "{{date}} 'at' {{time}}",
281
- medium: "{{date}}, {{time}}",
282
- short: "{{date}}, {{time}}"
283
- };
284
- const formatLong = {
285
- date: buildFormatLongFn({
286
- formats: dateFormats,
287
- defaultWidth: "full"
288
- }),
289
- time: buildFormatLongFn({
290
- formats: timeFormats,
291
- defaultWidth: "full"
292
- }),
293
- dateTime: buildFormatLongFn({
294
- formats: dateTimeFormats,
295
- defaultWidth: "full"
296
- })
297
- };
298
- const formatRelativeLocale = {
299
- lastWeek: "'last' eeee 'at' p",
300
- yesterday: "'yesterday at' p",
301
- today: "'today at' p",
302
- tomorrow: "'tomorrow at' p",
303
- nextWeek: "eeee 'at' p",
304
- other: "P"
305
- };
306
- const formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
307
- function buildLocalizeFn(args) {
308
- return (value, options) => {
309
- const context = (options == null ? void 0 : options.context) ? String(options.context) : "standalone";
310
- let valuesArray;
311
- if (context === "formatting" && args.formattingValues) {
312
- const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
313
- const width = (options == null ? void 0 : options.width) ? String(options.width) : defaultWidth;
314
- valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
315
- } else {
316
- const defaultWidth = args.defaultWidth;
317
- const width = (options == null ? void 0 : options.width) ? String(options.width) : args.defaultWidth;
318
- valuesArray = args.values[width] || args.values[defaultWidth];
319
- }
320
- const index = args.argumentCallback ? args.argumentCallback(value) : value;
321
- return valuesArray[index];
322
- };
323
- }
324
- const eraValues = {
325
- narrow: ["B", "A"],
326
- abbreviated: ["BC", "AD"],
327
- wide: ["Before Christ", "Anno Domini"]
328
- };
329
- const quarterValues = {
330
- narrow: ["1", "2", "3", "4"],
331
- abbreviated: ["Q1", "Q2", "Q3", "Q4"],
332
- wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
333
- };
334
- const monthValues = {
335
- narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
336
- abbreviated: [
337
- "Jan",
338
- "Feb",
339
- "Mar",
340
- "Apr",
341
- "May",
342
- "Jun",
343
- "Jul",
344
- "Aug",
345
- "Sep",
346
- "Oct",
347
- "Nov",
348
- "Dec"
349
- ],
350
- wide: [
351
- "January",
352
- "February",
353
- "March",
354
- "April",
355
- "May",
356
- "June",
357
- "July",
358
- "August",
359
- "September",
360
- "October",
361
- "November",
362
- "December"
363
- ]
364
- };
365
- const dayValues = {
366
- narrow: ["S", "M", "T", "W", "T", "F", "S"],
367
- short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
368
- abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
369
- wide: [
370
- "Sunday",
371
- "Monday",
372
- "Tuesday",
373
- "Wednesday",
374
- "Thursday",
375
- "Friday",
376
- "Saturday"
377
- ]
378
- };
379
- const dayPeriodValues = {
380
- narrow: {
381
- am: "a",
382
- pm: "p",
383
- midnight: "mi",
384
- noon: "n",
385
- morning: "morning",
386
- afternoon: "afternoon",
387
- evening: "evening",
388
- night: "night"
389
- },
390
- abbreviated: {
391
- am: "AM",
392
- pm: "PM",
393
- midnight: "midnight",
394
- noon: "noon",
395
- morning: "morning",
396
- afternoon: "afternoon",
397
- evening: "evening",
398
- night: "night"
399
- },
400
- wide: {
401
- am: "a.m.",
402
- pm: "p.m.",
403
- midnight: "midnight",
404
- noon: "noon",
405
- morning: "morning",
406
- afternoon: "afternoon",
407
- evening: "evening",
408
- night: "night"
409
- }
410
- };
411
- const formattingDayPeriodValues = {
412
- narrow: {
413
- am: "a",
414
- pm: "p",
415
- midnight: "mi",
416
- noon: "n",
417
- morning: "in the morning",
418
- afternoon: "in the afternoon",
419
- evening: "in the evening",
420
- night: "at night"
421
- },
422
- abbreviated: {
423
- am: "AM",
424
- pm: "PM",
425
- midnight: "midnight",
426
- noon: "noon",
427
- morning: "in the morning",
428
- afternoon: "in the afternoon",
429
- evening: "in the evening",
430
- night: "at night"
431
- },
432
- wide: {
433
- am: "a.m.",
434
- pm: "p.m.",
435
- midnight: "midnight",
436
- noon: "noon",
437
- morning: "in the morning",
438
- afternoon: "in the afternoon",
439
- evening: "in the evening",
440
- night: "at night"
441
- }
442
- };
443
- const ordinalNumber = (dirtyNumber, _options) => {
444
- const number = Number(dirtyNumber);
445
- const rem100 = number % 100;
446
- if (rem100 > 20 || rem100 < 10) {
447
- switch (rem100 % 10) {
448
- case 1:
449
- return number + "st";
450
- case 2:
451
- return number + "nd";
452
- case 3:
453
- return number + "rd";
454
- }
455
- }
456
- return number + "th";
457
- };
458
- const localize = {
459
- ordinalNumber,
460
- era: buildLocalizeFn({
461
- values: eraValues,
462
- defaultWidth: "wide"
463
- }),
464
- quarter: buildLocalizeFn({
465
- values: quarterValues,
466
- defaultWidth: "wide",
467
- argumentCallback: (quarter) => quarter - 1
468
- }),
469
- month: buildLocalizeFn({
470
- values: monthValues,
471
- defaultWidth: "wide"
472
- }),
473
- day: buildLocalizeFn({
474
- values: dayValues,
475
- defaultWidth: "wide"
476
- }),
477
- dayPeriod: buildLocalizeFn({
478
- values: dayPeriodValues,
479
- defaultWidth: "wide",
480
- formattingValues: formattingDayPeriodValues,
481
- defaultFormattingWidth: "wide"
482
- })
483
- };
484
- function buildMatchFn(args) {
485
- return (string, options = {}) => {
486
- const width = options.width;
487
- const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
488
- const matchResult = string.match(matchPattern);
489
- if (!matchResult) {
490
- return null;
491
- }
492
- const matchedString = matchResult[0];
493
- const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
494
- const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
495
- // [TODO] -- I challenge you to fix the type
496
- findKey(parsePatterns, (pattern) => pattern.test(matchedString))
497
- );
498
- let value;
499
- value = args.valueCallback ? args.valueCallback(key) : key;
500
- value = options.valueCallback ? (
501
- // [TODO] -- I challenge you to fix the type
502
- options.valueCallback(value)
503
- ) : value;
504
- const rest = string.slice(matchedString.length);
505
- return { value, rest };
506
- };
507
- }
508
- function findKey(object, predicate) {
509
- for (const key in object) {
510
- if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
511
- return key;
512
- }
513
- }
514
- return void 0;
515
- }
516
- function findIndex(array, predicate) {
517
- for (let key = 0; key < array.length; key++) {
518
- if (predicate(array[key])) {
519
- return key;
520
- }
521
- }
522
- return void 0;
523
- }
524
- function buildMatchPatternFn(args) {
525
- return (string, options = {}) => {
526
- const matchResult = string.match(args.matchPattern);
527
- if (!matchResult) return null;
528
- const matchedString = matchResult[0];
529
- const parseResult = string.match(args.parsePattern);
530
- if (!parseResult) return null;
531
- let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
532
- value = options.valueCallback ? options.valueCallback(value) : value;
533
- const rest = string.slice(matchedString.length);
534
- return { value, rest };
535
- };
536
- }
537
- const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
538
- const parseOrdinalNumberPattern = /\d+/i;
539
- const matchEraPatterns = {
540
- narrow: /^(b|a)/i,
541
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
542
- wide: /^(before christ|before common era|anno domini|common era)/i
543
- };
544
- const parseEraPatterns = {
545
- any: [/^b/i, /^(a|c)/i]
546
- };
547
- const matchQuarterPatterns = {
548
- narrow: /^[1234]/i,
549
- abbreviated: /^q[1234]/i,
550
- wide: /^[1234](th|st|nd|rd)? quarter/i
551
- };
552
- const parseQuarterPatterns = {
553
- any: [/1/i, /2/i, /3/i, /4/i]
554
- };
555
- const matchMonthPatterns = {
556
- narrow: /^[jfmasond]/i,
557
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
558
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
559
- };
560
- const parseMonthPatterns = {
561
- narrow: [
562
- /^j/i,
563
- /^f/i,
564
- /^m/i,
565
- /^a/i,
566
- /^m/i,
567
- /^j/i,
568
- /^j/i,
569
- /^a/i,
570
- /^s/i,
571
- /^o/i,
572
- /^n/i,
573
- /^d/i
574
- ],
575
- any: [
576
- /^ja/i,
577
- /^f/i,
578
- /^mar/i,
579
- /^ap/i,
580
- /^may/i,
581
- /^jun/i,
582
- /^jul/i,
583
- /^au/i,
584
- /^s/i,
585
- /^o/i,
586
- /^n/i,
587
- /^d/i
588
- ]
589
- };
590
- const matchDayPatterns = {
591
- narrow: /^[smtwf]/i,
592
- short: /^(su|mo|tu|we|th|fr|sa)/i,
593
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
594
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
595
- };
596
- const parseDayPatterns = {
597
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
598
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
599
- };
600
- const matchDayPeriodPatterns = {
601
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
602
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
603
- };
604
- const parseDayPeriodPatterns = {
605
- any: {
606
- am: /^a/i,
607
- pm: /^p/i,
608
- midnight: /^mi/i,
609
- noon: /^no/i,
610
- morning: /morning/i,
611
- afternoon: /afternoon/i,
612
- evening: /evening/i,
613
- night: /night/i
614
- }
615
- };
616
- const match = {
617
- ordinalNumber: buildMatchPatternFn({
618
- matchPattern: matchOrdinalNumberPattern,
619
- parsePattern: parseOrdinalNumberPattern,
620
- valueCallback: (value) => parseInt(value, 10)
621
- }),
622
- era: buildMatchFn({
623
- matchPatterns: matchEraPatterns,
624
- defaultMatchWidth: "wide",
625
- parsePatterns: parseEraPatterns,
626
- defaultParseWidth: "any"
627
- }),
628
- quarter: buildMatchFn({
629
- matchPatterns: matchQuarterPatterns,
630
- defaultMatchWidth: "wide",
631
- parsePatterns: parseQuarterPatterns,
632
- defaultParseWidth: "any",
633
- valueCallback: (index) => index + 1
634
- }),
635
- month: buildMatchFn({
636
- matchPatterns: matchMonthPatterns,
637
- defaultMatchWidth: "wide",
638
- parsePatterns: parseMonthPatterns,
639
- defaultParseWidth: "any"
640
- }),
641
- day: buildMatchFn({
642
- matchPatterns: matchDayPatterns,
643
- defaultMatchWidth: "wide",
644
- parsePatterns: parseDayPatterns,
645
- defaultParseWidth: "any"
646
- }),
647
- dayPeriod: buildMatchFn({
648
- matchPatterns: matchDayPeriodPatterns,
649
- defaultMatchWidth: "any",
650
- parsePatterns: parseDayPeriodPatterns,
651
- defaultParseWidth: "any"
652
- })
653
- };
654
- const enUS = {
655
- code: "en-US",
656
- formatDistance,
657
- formatLong,
658
- formatRelative,
659
- localize,
660
- match,
661
- options: {
662
- weekStartsOn: 0,
663
- firstWeekContainsDate: 1
664
- }
665
- };
666
- function getDayOfYear(date, options) {
667
- const _date = toDate$1(date, options == null ? void 0 : options.in);
668
- const diff = differenceInCalendarDays(_date, startOfYear(_date));
669
- const dayOfYear = diff + 1;
670
- return dayOfYear;
671
- }
672
- function getISOWeek(date, options) {
673
- const _date = toDate$1(date, options == null ? void 0 : options.in);
674
- const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
675
- return Math.round(diff / millisecondsInWeek) + 1;
676
- }
677
- function getWeekYear(date, options) {
678
- var _a, _b, _c, _d, _e, _f, _g, _h;
679
- const _date = toDate$1(date, options == null ? void 0 : options.in);
680
- const year = _date.getFullYear();
681
- const defaultOptions2 = getDefaultOptions$1();
682
- const firstWeekContainsDate = (_h = (_g = (_d = (_c = options == null ? void 0 : options.firstWeekContainsDate) != null ? _c : (_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) != null ? _d : defaultOptions2.firstWeekContainsDate) != null ? _g : (_f = (_e = defaultOptions2.locale) == null ? void 0 : _e.options) == null ? void 0 : _f.firstWeekContainsDate) != null ? _h : 1;
683
- const firstWeekOfNextYear = constructFrom((options == null ? void 0 : options.in) || date, 0);
684
- firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
685
- firstWeekOfNextYear.setHours(0, 0, 0, 0);
686
- const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
687
- const firstWeekOfThisYear = constructFrom((options == null ? void 0 : options.in) || date, 0);
688
- firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
689
- firstWeekOfThisYear.setHours(0, 0, 0, 0);
690
- const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
691
- if (+_date >= +startOfNextYear) {
692
- return year + 1;
693
- } else if (+_date >= +startOfThisYear) {
694
- return year;
695
- } else {
696
- return year - 1;
697
- }
698
- }
699
- function startOfWeekYear(date, options) {
700
- var _a, _b, _c, _d, _e, _f, _g, _h;
701
- const defaultOptions2 = getDefaultOptions$1();
702
- const firstWeekContainsDate = (_h = (_g = (_d = (_c = options == null ? void 0 : options.firstWeekContainsDate) != null ? _c : (_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) != null ? _d : defaultOptions2.firstWeekContainsDate) != null ? _g : (_f = (_e = defaultOptions2.locale) == null ? void 0 : _e.options) == null ? void 0 : _f.firstWeekContainsDate) != null ? _h : 1;
703
- const year = getWeekYear(date, options);
704
- const firstWeek = constructFrom((options == null ? void 0 : options.in) || date, 0);
705
- firstWeek.setFullYear(year, 0, firstWeekContainsDate);
706
- firstWeek.setHours(0, 0, 0, 0);
707
- const _date = startOfWeek(firstWeek, options);
708
- return _date;
709
- }
710
- function getWeek(date, options) {
711
- const _date = toDate$1(date, options == null ? void 0 : options.in);
712
- const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
713
- return Math.round(diff / millisecondsInWeek) + 1;
714
- }
715
- function addLeadingZeros$1(number, targetLength) {
716
- const sign = number < 0 ? "-" : "";
717
- const output = Math.abs(number).toString().padStart(targetLength, "0");
718
- return sign + output;
719
- }
720
- const lightFormatters = {
721
- // Year
722
- y(date, token) {
723
- const signedYear = date.getFullYear();
724
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
725
- return addLeadingZeros$1(token === "yy" ? year % 100 : year, token.length);
726
- },
727
- // Month
728
- M(date, token) {
729
- const month = date.getMonth();
730
- return token === "M" ? String(month + 1) : addLeadingZeros$1(month + 1, 2);
731
- },
732
- // Day of the month
733
- d(date, token) {
734
- return addLeadingZeros$1(date.getDate(), token.length);
735
- },
736
- // AM or PM
737
- a(date, token) {
738
- const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
739
- switch (token) {
740
- case "a":
741
- case "aa":
742
- return dayPeriodEnumValue.toUpperCase();
743
- case "aaa":
744
- return dayPeriodEnumValue;
745
- case "aaaaa":
746
- return dayPeriodEnumValue[0];
747
- case "aaaa":
748
- default:
749
- return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
750
- }
751
- },
752
- // Hour [1-12]
753
- h(date, token) {
754
- return addLeadingZeros$1(date.getHours() % 12 || 12, token.length);
755
- },
756
- // Hour [0-23]
757
- H(date, token) {
758
- return addLeadingZeros$1(date.getHours(), token.length);
759
- },
760
- // Minute
761
- m(date, token) {
762
- return addLeadingZeros$1(date.getMinutes(), token.length);
763
- },
764
- // Second
765
- s(date, token) {
766
- return addLeadingZeros$1(date.getSeconds(), token.length);
767
- },
768
- // Fraction of second
769
- S(date, token) {
770
- const numberOfDigits = token.length;
771
- const milliseconds = date.getMilliseconds();
772
- const fractionalSeconds = Math.trunc(
773
- milliseconds * Math.pow(10, numberOfDigits - 3)
774
- );
775
- return addLeadingZeros$1(fractionalSeconds, token.length);
776
- }
777
- };
778
- const dayPeriodEnum = {
779
- midnight: "midnight",
780
- noon: "noon",
781
- morning: "morning",
782
- afternoon: "afternoon",
783
- evening: "evening",
784
- night: "night"
785
- };
786
- const formatters$1 = {
787
- // Era
788
- G: function(date, token, localize2) {
789
- const era = date.getFullYear() > 0 ? 1 : 0;
790
- switch (token) {
791
- // AD, BC
792
- case "G":
793
- case "GG":
794
- case "GGG":
795
- return localize2.era(era, { width: "abbreviated" });
796
- // A, B
797
- case "GGGGG":
798
- return localize2.era(era, { width: "narrow" });
799
- // Anno Domini, Before Christ
800
- case "GGGG":
801
- default:
802
- return localize2.era(era, { width: "wide" });
803
- }
804
- },
805
- // Year
806
- y: function(date, token, localize2) {
807
- if (token === "yo") {
808
- const signedYear = date.getFullYear();
809
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
810
- return localize2.ordinalNumber(year, { unit: "year" });
811
- }
812
- return lightFormatters.y(date, token);
813
- },
814
- // Local week-numbering year
815
- Y: function(date, token, localize2, options) {
816
- const signedWeekYear = getWeekYear(date, options);
817
- const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
818
- if (token === "YY") {
819
- const twoDigitYear = weekYear % 100;
820
- return addLeadingZeros$1(twoDigitYear, 2);
821
- }
822
- if (token === "Yo") {
823
- return localize2.ordinalNumber(weekYear, { unit: "year" });
824
- }
825
- return addLeadingZeros$1(weekYear, token.length);
826
- },
827
- // ISO week-numbering year
828
- R: function(date, token) {
829
- const isoWeekYear = getISOWeekYear(date);
830
- return addLeadingZeros$1(isoWeekYear, token.length);
831
- },
832
- // Extended year. This is a single number designating the year of this calendar system.
833
- // The main difference between `y` and `u` localizers are B.C. years:
834
- // | Year | `y` | `u` |
835
- // |------|-----|-----|
836
- // | AC 1 | 1 | 1 |
837
- // | BC 1 | 1 | 0 |
838
- // | BC 2 | 2 | -1 |
839
- // Also `yy` always returns the last two digits of a year,
840
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
841
- u: function(date, token) {
842
- const year = date.getFullYear();
843
- return addLeadingZeros$1(year, token.length);
844
- },
845
- // Quarter
846
- Q: function(date, token, localize2) {
847
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
848
- switch (token) {
849
- // 1, 2, 3, 4
850
- case "Q":
851
- return String(quarter);
852
- // 01, 02, 03, 04
853
- case "QQ":
854
- return addLeadingZeros$1(quarter, 2);
855
- // 1st, 2nd, 3rd, 4th
856
- case "Qo":
857
- return localize2.ordinalNumber(quarter, { unit: "quarter" });
858
- // Q1, Q2, Q3, Q4
859
- case "QQQ":
860
- return localize2.quarter(quarter, {
861
- width: "abbreviated",
862
- context: "formatting"
863
- });
864
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
865
- case "QQQQQ":
866
- return localize2.quarter(quarter, {
867
- width: "narrow",
868
- context: "formatting"
869
- });
870
- // 1st quarter, 2nd quarter, ...
871
- case "QQQQ":
872
- default:
873
- return localize2.quarter(quarter, {
874
- width: "wide",
875
- context: "formatting"
876
- });
877
- }
878
- },
879
- // Stand-alone quarter
880
- q: function(date, token, localize2) {
881
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
882
- switch (token) {
883
- // 1, 2, 3, 4
884
- case "q":
885
- return String(quarter);
886
- // 01, 02, 03, 04
887
- case "qq":
888
- return addLeadingZeros$1(quarter, 2);
889
- // 1st, 2nd, 3rd, 4th
890
- case "qo":
891
- return localize2.ordinalNumber(quarter, { unit: "quarter" });
892
- // Q1, Q2, Q3, Q4
893
- case "qqq":
894
- return localize2.quarter(quarter, {
895
- width: "abbreviated",
896
- context: "standalone"
897
- });
898
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
899
- case "qqqqq":
900
- return localize2.quarter(quarter, {
901
- width: "narrow",
902
- context: "standalone"
903
- });
904
- // 1st quarter, 2nd quarter, ...
905
- case "qqqq":
906
- default:
907
- return localize2.quarter(quarter, {
908
- width: "wide",
909
- context: "standalone"
910
- });
911
- }
912
- },
913
- // Month
914
- M: function(date, token, localize2) {
915
- const month = date.getMonth();
916
- switch (token) {
917
- case "M":
918
- case "MM":
919
- return lightFormatters.M(date, token);
920
- // 1st, 2nd, ..., 12th
921
- case "Mo":
922
- return localize2.ordinalNumber(month + 1, { unit: "month" });
923
- // Jan, Feb, ..., Dec
924
- case "MMM":
925
- return localize2.month(month, {
926
- width: "abbreviated",
927
- context: "formatting"
928
- });
929
- // J, F, ..., D
930
- case "MMMMM":
931
- return localize2.month(month, {
932
- width: "narrow",
933
- context: "formatting"
934
- });
935
- // January, February, ..., December
936
- case "MMMM":
937
- default:
938
- return localize2.month(month, { width: "wide", context: "formatting" });
939
- }
940
- },
941
- // Stand-alone month
942
- L: function(date, token, localize2) {
943
- const month = date.getMonth();
944
- switch (token) {
945
- // 1, 2, ..., 12
946
- case "L":
947
- return String(month + 1);
948
- // 01, 02, ..., 12
949
- case "LL":
950
- return addLeadingZeros$1(month + 1, 2);
951
- // 1st, 2nd, ..., 12th
952
- case "Lo":
953
- return localize2.ordinalNumber(month + 1, { unit: "month" });
954
- // Jan, Feb, ..., Dec
955
- case "LLL":
956
- return localize2.month(month, {
957
- width: "abbreviated",
958
- context: "standalone"
959
- });
960
- // J, F, ..., D
961
- case "LLLLL":
962
- return localize2.month(month, {
963
- width: "narrow",
964
- context: "standalone"
965
- });
966
- // January, February, ..., December
967
- case "LLLL":
968
- default:
969
- return localize2.month(month, { width: "wide", context: "standalone" });
970
- }
971
- },
972
- // Local week of year
973
- w: function(date, token, localize2, options) {
974
- const week = getWeek(date, options);
975
- if (token === "wo") {
976
- return localize2.ordinalNumber(week, { unit: "week" });
977
- }
978
- return addLeadingZeros$1(week, token.length);
979
- },
980
- // ISO week of year
981
- I: function(date, token, localize2) {
982
- const isoWeek = getISOWeek(date);
983
- if (token === "Io") {
984
- return localize2.ordinalNumber(isoWeek, { unit: "week" });
985
- }
986
- return addLeadingZeros$1(isoWeek, token.length);
987
- },
988
- // Day of the month
989
- d: function(date, token, localize2) {
990
- if (token === "do") {
991
- return localize2.ordinalNumber(date.getDate(), { unit: "date" });
992
- }
993
- return lightFormatters.d(date, token);
994
- },
995
- // Day of year
996
- D: function(date, token, localize2) {
997
- const dayOfYear = getDayOfYear(date);
998
- if (token === "Do") {
999
- return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
1000
- }
1001
- return addLeadingZeros$1(dayOfYear, token.length);
1002
- },
1003
- // Day of week
1004
- E: function(date, token, localize2) {
1005
- const dayOfWeek = date.getDay();
1006
- switch (token) {
1007
- // Tue
1008
- case "E":
1009
- case "EE":
1010
- case "EEE":
1011
- return localize2.day(dayOfWeek, {
1012
- width: "abbreviated",
1013
- context: "formatting"
1014
- });
1015
- // T
1016
- case "EEEEE":
1017
- return localize2.day(dayOfWeek, {
1018
- width: "narrow",
1019
- context: "formatting"
1020
- });
1021
- // Tu
1022
- case "EEEEEE":
1023
- return localize2.day(dayOfWeek, {
1024
- width: "short",
1025
- context: "formatting"
1026
- });
1027
- // Tuesday
1028
- case "EEEE":
1029
- default:
1030
- return localize2.day(dayOfWeek, {
1031
- width: "wide",
1032
- context: "formatting"
1033
- });
1034
- }
1035
- },
1036
- // Local day of week
1037
- e: function(date, token, localize2, options) {
1038
- const dayOfWeek = date.getDay();
1039
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1040
- switch (token) {
1041
- // Numerical value (Nth day of week with current locale or weekStartsOn)
1042
- case "e":
1043
- return String(localDayOfWeek);
1044
- // Padded numerical value
1045
- case "ee":
1046
- return addLeadingZeros$1(localDayOfWeek, 2);
1047
- // 1st, 2nd, ..., 7th
1048
- case "eo":
1049
- return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
1050
- case "eee":
1051
- return localize2.day(dayOfWeek, {
1052
- width: "abbreviated",
1053
- context: "formatting"
1054
- });
1055
- // T
1056
- case "eeeee":
1057
- return localize2.day(dayOfWeek, {
1058
- width: "narrow",
1059
- context: "formatting"
1060
- });
1061
- // Tu
1062
- case "eeeeee":
1063
- return localize2.day(dayOfWeek, {
1064
- width: "short",
1065
- context: "formatting"
1066
- });
1067
- // Tuesday
1068
- case "eeee":
1069
- default:
1070
- return localize2.day(dayOfWeek, {
1071
- width: "wide",
1072
- context: "formatting"
1073
- });
1074
- }
1075
- },
1076
- // Stand-alone local day of week
1077
- c: function(date, token, localize2, options) {
1078
- const dayOfWeek = date.getDay();
1079
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1080
- switch (token) {
1081
- // Numerical value (same as in `e`)
1082
- case "c":
1083
- return String(localDayOfWeek);
1084
- // Padded numerical value
1085
- case "cc":
1086
- return addLeadingZeros$1(localDayOfWeek, token.length);
1087
- // 1st, 2nd, ..., 7th
1088
- case "co":
1089
- return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
1090
- case "ccc":
1091
- return localize2.day(dayOfWeek, {
1092
- width: "abbreviated",
1093
- context: "standalone"
1094
- });
1095
- // T
1096
- case "ccccc":
1097
- return localize2.day(dayOfWeek, {
1098
- width: "narrow",
1099
- context: "standalone"
1100
- });
1101
- // Tu
1102
- case "cccccc":
1103
- return localize2.day(dayOfWeek, {
1104
- width: "short",
1105
- context: "standalone"
1106
- });
1107
- // Tuesday
1108
- case "cccc":
1109
- default:
1110
- return localize2.day(dayOfWeek, {
1111
- width: "wide",
1112
- context: "standalone"
1113
- });
1114
- }
1115
- },
1116
- // ISO day of week
1117
- i: function(date, token, localize2) {
1118
- const dayOfWeek = date.getDay();
1119
- const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1120
- switch (token) {
1121
- // 2
1122
- case "i":
1123
- return String(isoDayOfWeek);
1124
- // 02
1125
- case "ii":
1126
- return addLeadingZeros$1(isoDayOfWeek, token.length);
1127
- // 2nd
1128
- case "io":
1129
- return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
1130
- // Tue
1131
- case "iii":
1132
- return localize2.day(dayOfWeek, {
1133
- width: "abbreviated",
1134
- context: "formatting"
1135
- });
1136
- // T
1137
- case "iiiii":
1138
- return localize2.day(dayOfWeek, {
1139
- width: "narrow",
1140
- context: "formatting"
1141
- });
1142
- // Tu
1143
- case "iiiiii":
1144
- return localize2.day(dayOfWeek, {
1145
- width: "short",
1146
- context: "formatting"
1147
- });
1148
- // Tuesday
1149
- case "iiii":
1150
- default:
1151
- return localize2.day(dayOfWeek, {
1152
- width: "wide",
1153
- context: "formatting"
1154
- });
1155
- }
1156
- },
1157
- // AM or PM
1158
- a: function(date, token, localize2) {
1159
- const hours = date.getHours();
1160
- const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
1161
- switch (token) {
1162
- case "a":
1163
- case "aa":
1164
- return localize2.dayPeriod(dayPeriodEnumValue, {
1165
- width: "abbreviated",
1166
- context: "formatting"
1167
- });
1168
- case "aaa":
1169
- return localize2.dayPeriod(dayPeriodEnumValue, {
1170
- width: "abbreviated",
1171
- context: "formatting"
1172
- }).toLowerCase();
1173
- case "aaaaa":
1174
- return localize2.dayPeriod(dayPeriodEnumValue, {
1175
- width: "narrow",
1176
- context: "formatting"
1177
- });
1178
- case "aaaa":
1179
- default:
1180
- return localize2.dayPeriod(dayPeriodEnumValue, {
1181
- width: "wide",
1182
- context: "formatting"
1183
- });
1184
- }
1185
- },
1186
- // AM, PM, midnight, noon
1187
- b: function(date, token, localize2) {
1188
- const hours = date.getHours();
1189
- let dayPeriodEnumValue;
1190
- if (hours === 12) {
1191
- dayPeriodEnumValue = dayPeriodEnum.noon;
1192
- } else if (hours === 0) {
1193
- dayPeriodEnumValue = dayPeriodEnum.midnight;
1194
- } else {
1195
- dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
1196
- }
1197
- switch (token) {
1198
- case "b":
1199
- case "bb":
1200
- return localize2.dayPeriod(dayPeriodEnumValue, {
1201
- width: "abbreviated",
1202
- context: "formatting"
1203
- });
1204
- case "bbb":
1205
- return localize2.dayPeriod(dayPeriodEnumValue, {
1206
- width: "abbreviated",
1207
- context: "formatting"
1208
- }).toLowerCase();
1209
- case "bbbbb":
1210
- return localize2.dayPeriod(dayPeriodEnumValue, {
1211
- width: "narrow",
1212
- context: "formatting"
1213
- });
1214
- case "bbbb":
1215
- default:
1216
- return localize2.dayPeriod(dayPeriodEnumValue, {
1217
- width: "wide",
1218
- context: "formatting"
1219
- });
1220
- }
1221
- },
1222
- // in the morning, in the afternoon, in the evening, at night
1223
- B: function(date, token, localize2) {
1224
- const hours = date.getHours();
1225
- let dayPeriodEnumValue;
1226
- if (hours >= 17) {
1227
- dayPeriodEnumValue = dayPeriodEnum.evening;
1228
- } else if (hours >= 12) {
1229
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
1230
- } else if (hours >= 4) {
1231
- dayPeriodEnumValue = dayPeriodEnum.morning;
1232
- } else {
1233
- dayPeriodEnumValue = dayPeriodEnum.night;
1234
- }
1235
- switch (token) {
1236
- case "B":
1237
- case "BB":
1238
- case "BBB":
1239
- return localize2.dayPeriod(dayPeriodEnumValue, {
1240
- width: "abbreviated",
1241
- context: "formatting"
1242
- });
1243
- case "BBBBB":
1244
- return localize2.dayPeriod(dayPeriodEnumValue, {
1245
- width: "narrow",
1246
- context: "formatting"
1247
- });
1248
- case "BBBB":
1249
- default:
1250
- return localize2.dayPeriod(dayPeriodEnumValue, {
1251
- width: "wide",
1252
- context: "formatting"
1253
- });
1254
- }
1255
- },
1256
- // Hour [1-12]
1257
- h: function(date, token, localize2) {
1258
- if (token === "ho") {
1259
- let hours = date.getHours() % 12;
1260
- if (hours === 0) hours = 12;
1261
- return localize2.ordinalNumber(hours, { unit: "hour" });
1262
- }
1263
- return lightFormatters.h(date, token);
1264
- },
1265
- // Hour [0-23]
1266
- H: function(date, token, localize2) {
1267
- if (token === "Ho") {
1268
- return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
1269
- }
1270
- return lightFormatters.H(date, token);
1271
- },
1272
- // Hour [0-11]
1273
- K: function(date, token, localize2) {
1274
- const hours = date.getHours() % 12;
1275
- if (token === "Ko") {
1276
- return localize2.ordinalNumber(hours, { unit: "hour" });
1277
- }
1278
- return addLeadingZeros$1(hours, token.length);
1279
- },
1280
- // Hour [1-24]
1281
- k: function(date, token, localize2) {
1282
- let hours = date.getHours();
1283
- if (hours === 0) hours = 24;
1284
- if (token === "ko") {
1285
- return localize2.ordinalNumber(hours, { unit: "hour" });
1286
- }
1287
- return addLeadingZeros$1(hours, token.length);
1288
- },
1289
- // Minute
1290
- m: function(date, token, localize2) {
1291
- if (token === "mo") {
1292
- return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
1293
- }
1294
- return lightFormatters.m(date, token);
1295
- },
1296
- // Second
1297
- s: function(date, token, localize2) {
1298
- if (token === "so") {
1299
- return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
1300
- }
1301
- return lightFormatters.s(date, token);
1302
- },
1303
- // Fraction of second
1304
- S: function(date, token) {
1305
- return lightFormatters.S(date, token);
1306
- },
1307
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1308
- X: function(date, token, _localize) {
1309
- const timezoneOffset = date.getTimezoneOffset();
1310
- if (timezoneOffset === 0) {
1311
- return "Z";
1312
- }
1313
- switch (token) {
1314
- // Hours and optional minutes
1315
- case "X":
1316
- return formatTimezoneWithOptionalMinutes$1(timezoneOffset);
1317
- // Hours, minutes and optional seconds without `:` delimiter
1318
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1319
- // so this token always has the same output as `XX`
1320
- case "XXXX":
1321
- case "XX":
1322
- return formatTimezone$1(timezoneOffset);
1323
- // Hours, minutes and optional seconds with `:` delimiter
1324
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1325
- // so this token always has the same output as `XXX`
1326
- case "XXXXX":
1327
- case "XXX":
1328
- // Hours and minutes with `:` delimiter
1329
- default:
1330
- return formatTimezone$1(timezoneOffset, ":");
1331
- }
1332
- },
1333
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1334
- x: function(date, token, _localize) {
1335
- const timezoneOffset = date.getTimezoneOffset();
1336
- switch (token) {
1337
- // Hours and optional minutes
1338
- case "x":
1339
- return formatTimezoneWithOptionalMinutes$1(timezoneOffset);
1340
- // Hours, minutes and optional seconds without `:` delimiter
1341
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1342
- // so this token always has the same output as `xx`
1343
- case "xxxx":
1344
- case "xx":
1345
- return formatTimezone$1(timezoneOffset);
1346
- // Hours, minutes and optional seconds with `:` delimiter
1347
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1348
- // so this token always has the same output as `xxx`
1349
- case "xxxxx":
1350
- case "xxx":
1351
- // Hours and minutes with `:` delimiter
1352
- default:
1353
- return formatTimezone$1(timezoneOffset, ":");
1354
- }
1355
- },
1356
- // Timezone (GMT)
1357
- O: function(date, token, _localize) {
1358
- const timezoneOffset = date.getTimezoneOffset();
1359
- switch (token) {
1360
- // Short
1361
- case "O":
1362
- case "OO":
1363
- case "OOO":
1364
- return "GMT" + formatTimezoneShort$1(timezoneOffset, ":");
1365
- // Long
1366
- case "OOOO":
1367
- default:
1368
- return "GMT" + formatTimezone$1(timezoneOffset, ":");
1369
- }
1370
- },
1371
- // Timezone (specific non-location)
1372
- z: function(date, token, _localize) {
1373
- const timezoneOffset = date.getTimezoneOffset();
1374
- switch (token) {
1375
- // Short
1376
- case "z":
1377
- case "zz":
1378
- case "zzz":
1379
- return "GMT" + formatTimezoneShort$1(timezoneOffset, ":");
1380
- // Long
1381
- case "zzzz":
1382
- default:
1383
- return "GMT" + formatTimezone$1(timezoneOffset, ":");
1384
- }
1385
- },
1386
- // Seconds timestamp
1387
- t: function(date, token, _localize) {
1388
- const timestamp = Math.trunc(+date / 1e3);
1389
- return addLeadingZeros$1(timestamp, token.length);
1390
- },
1391
- // Milliseconds timestamp
1392
- T: function(date, token, _localize) {
1393
- return addLeadingZeros$1(+date, token.length);
1394
- }
1395
- };
1396
- function formatTimezoneShort$1(offset, delimiter = "") {
1397
- const sign = offset > 0 ? "-" : "+";
1398
- const absOffset = Math.abs(offset);
1399
- const hours = Math.trunc(absOffset / 60);
1400
- const minutes = absOffset % 60;
1401
- if (minutes === 0) {
1402
- return sign + String(hours);
1403
- }
1404
- return sign + String(hours) + delimiter + addLeadingZeros$1(minutes, 2);
1405
- }
1406
- function formatTimezoneWithOptionalMinutes$1(offset, delimiter) {
1407
- if (offset % 60 === 0) {
1408
- const sign = offset > 0 ? "-" : "+";
1409
- return sign + addLeadingZeros$1(Math.abs(offset) / 60, 2);
1410
- }
1411
- return formatTimezone$1(offset, delimiter);
1412
- }
1413
- function formatTimezone$1(offset, delimiter = "") {
1414
- const sign = offset > 0 ? "-" : "+";
1415
- const absOffset = Math.abs(offset);
1416
- const hours = addLeadingZeros$1(Math.trunc(absOffset / 60), 2);
1417
- const minutes = addLeadingZeros$1(absOffset % 60, 2);
1418
- return sign + hours + delimiter + minutes;
1419
- }
1420
- const dateLongFormatter = (pattern, formatLong2) => {
1421
- switch (pattern) {
1422
- case "P":
1423
- return formatLong2.date({ width: "short" });
1424
- case "PP":
1425
- return formatLong2.date({ width: "medium" });
1426
- case "PPP":
1427
- return formatLong2.date({ width: "long" });
1428
- case "PPPP":
1429
- default:
1430
- return formatLong2.date({ width: "full" });
1431
- }
1432
- };
1433
- const timeLongFormatter = (pattern, formatLong2) => {
1434
- switch (pattern) {
1435
- case "p":
1436
- return formatLong2.time({ width: "short" });
1437
- case "pp":
1438
- return formatLong2.time({ width: "medium" });
1439
- case "ppp":
1440
- return formatLong2.time({ width: "long" });
1441
- case "pppp":
1442
- default:
1443
- return formatLong2.time({ width: "full" });
1444
- }
1445
- };
1446
- const dateTimeLongFormatter = (pattern, formatLong2) => {
1447
- const matchResult = pattern.match(/(P+)(p+)?/) || [];
1448
- const datePattern = matchResult[1];
1449
- const timePattern = matchResult[2];
1450
- if (!timePattern) {
1451
- return dateLongFormatter(pattern, formatLong2);
1452
- }
1453
- let dateTimeFormat;
1454
- switch (datePattern) {
1455
- case "P":
1456
- dateTimeFormat = formatLong2.dateTime({ width: "short" });
1457
- break;
1458
- case "PP":
1459
- dateTimeFormat = formatLong2.dateTime({ width: "medium" });
1460
- break;
1461
- case "PPP":
1462
- dateTimeFormat = formatLong2.dateTime({ width: "long" });
1463
- break;
1464
- case "PPPP":
1465
- default:
1466
- dateTimeFormat = formatLong2.dateTime({ width: "full" });
1467
- break;
1468
- }
1469
- return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
1470
- };
1471
- const longFormatters = {
1472
- p: timeLongFormatter,
1473
- P: dateTimeLongFormatter
1474
- };
1475
- const dayOfYearTokenRE = /^D+$/;
1476
- const weekYearTokenRE = /^Y+$/;
1477
- const throwTokens = ["D", "DD", "YY", "YYYY"];
1478
- function isProtectedDayOfYearToken(token) {
1479
- return dayOfYearTokenRE.test(token);
1480
- }
1481
- function isProtectedWeekYearToken(token) {
1482
- return weekYearTokenRE.test(token);
1483
- }
1484
- function warnOrThrowProtectedError(token, format2, input) {
1485
- const _message = message(token, format2, input);
1486
- console.warn(_message);
1487
- if (throwTokens.includes(token)) throw new RangeError(_message);
1488
- }
1489
- function message(token, format2, input) {
1490
- const subject = token[0] === "Y" ? "years" : "days of the month";
1491
- return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format2}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
1492
- }
1493
- const formattingTokensRegExp$1 = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
1494
- const longFormattingTokensRegExp$1 = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
1495
- const escapedStringRegExp$1 = /^'([^]*?)'?$/;
1496
- const doubleQuoteRegExp$1 = /''/g;
1497
- const unescapedLatinCharacterRegExp$1 = /[a-zA-Z]/;
1498
- function format$1(date, formatStr, options) {
1499
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1500
- const defaultOptions2 = getDefaultOptions$1();
1501
- const locale = (_b = (_a = options == null ? void 0 : options.locale) != null ? _a : defaultOptions2.locale) != null ? _b : enUS;
1502
- const firstWeekContainsDate = (_j = (_i = (_f = (_e = options == null ? void 0 : options.firstWeekContainsDate) != null ? _e : (_d = (_c = options == null ? void 0 : options.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.firstWeekContainsDate) != null ? _f : defaultOptions2.firstWeekContainsDate) != null ? _i : (_h = (_g = defaultOptions2.locale) == null ? void 0 : _g.options) == null ? void 0 : _h.firstWeekContainsDate) != null ? _j : 1;
1503
- const weekStartsOn = (_r = (_q = (_n = (_m = options == null ? void 0 : options.weekStartsOn) != null ? _m : (_l = (_k = options == null ? void 0 : options.locale) == null ? void 0 : _k.options) == null ? void 0 : _l.weekStartsOn) != null ? _n : defaultOptions2.weekStartsOn) != null ? _q : (_p = (_o = defaultOptions2.locale) == null ? void 0 : _o.options) == null ? void 0 : _p.weekStartsOn) != null ? _r : 0;
1504
- const originalDate = toDate$1(date, options == null ? void 0 : options.in);
1505
- if (!isValid(originalDate)) {
1506
- throw new RangeError("Invalid time value");
1507
- }
1508
- let parts = formatStr.match(longFormattingTokensRegExp$1).map((substring) => {
1509
- const firstCharacter = substring[0];
1510
- if (firstCharacter === "p" || firstCharacter === "P") {
1511
- const longFormatter = longFormatters[firstCharacter];
1512
- return longFormatter(substring, locale.formatLong);
1513
- }
1514
- return substring;
1515
- }).join("").match(formattingTokensRegExp$1).map((substring) => {
1516
- if (substring === "''") {
1517
- return { isToken: false, value: "'" };
1518
- }
1519
- const firstCharacter = substring[0];
1520
- if (firstCharacter === "'") {
1521
- return { isToken: false, value: cleanEscapedString$1(substring) };
1522
- }
1523
- if (formatters$1[firstCharacter]) {
1524
- return { isToken: true, value: substring };
1525
- }
1526
- if (firstCharacter.match(unescapedLatinCharacterRegExp$1)) {
1527
- throw new RangeError(
1528
- "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
1529
- );
1530
- }
1531
- return { isToken: false, value: substring };
1532
- });
1533
- if (locale.localize.preprocessor) {
1534
- parts = locale.localize.preprocessor(originalDate, parts);
1535
- }
1536
- const formatterOptions = {
1537
- firstWeekContainsDate,
1538
- weekStartsOn,
1539
- locale
1540
- };
1541
- return parts.map((part) => {
1542
- if (!part.isToken) return part.value;
1543
- const token = part.value;
1544
- if (!(options == null ? void 0 : options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(token) || !(options == null ? void 0 : options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(token)) {
1545
- warnOrThrowProtectedError(token, formatStr, String(date));
1546
- }
1547
- const formatter = formatters$1[token[0]];
1548
- return formatter(originalDate, token, locale.localize, formatterOptions);
1549
- }).join("");
1550
- }
1551
- function cleanEscapedString$1(input) {
1552
- const matched = input.match(escapedStringRegExp$1);
1553
- if (!matched) {
1554
- return input;
1555
- }
1556
- return matched[1].replace(doubleQuoteRegExp$1, "'");
1557
- }
1558
- function getDefaultOptions() {
1559
- return Object.assign({}, getDefaultOptions$1());
1560
- }
1561
- function getISODay(date, options) {
1562
- const day = toDate$1(date, options == null ? void 0 : options.in).getDay();
1563
- return day === 0 ? 7 : day;
1564
- }
1565
- function transpose(date, constructor) {
1566
- const date_ = isConstructor(constructor) ? new constructor(0) : constructFrom(constructor, 0);
1567
- date_.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
1568
- date_.setHours(
1569
- date.getHours(),
1570
- date.getMinutes(),
1571
- date.getSeconds(),
1572
- date.getMilliseconds()
1573
- );
1574
- return date_;
1575
- }
1576
- function isConstructor(constructor) {
1577
- var _a;
1578
- return typeof constructor === "function" && ((_a = constructor.prototype) == null ? void 0 : _a.constructor) === constructor;
1579
- }
1580
- const TIMEZONE_UNIT_PRIORITY = 10;
1581
- class Setter {
1582
- constructor() {
1583
- __publicField(this, "subPriority", 0);
1584
- }
1585
- validate(_utcDate, _options) {
1586
- return true;
1587
- }
1588
- }
1589
- class ValueSetter extends Setter {
1590
- constructor(value, validateValue, setValue, priority, subPriority) {
1591
- super();
1592
- this.value = value;
1593
- this.validateValue = validateValue;
1594
- this.setValue = setValue;
1595
- this.priority = priority;
1596
- if (subPriority) {
1597
- this.subPriority = subPriority;
1598
- }
1599
- }
1600
- validate(date, options) {
1601
- return this.validateValue(date, this.value, options);
1602
- }
1603
- set(date, flags, options) {
1604
- return this.setValue(date, flags, this.value, options);
1605
- }
1606
- }
1607
- class DateTimezoneSetter extends Setter {
1608
- constructor(context, reference) {
1609
- super();
1610
- __publicField(this, "priority", TIMEZONE_UNIT_PRIORITY);
1611
- __publicField(this, "subPriority", -1);
1612
- this.context = context || ((date) => constructFrom(reference, date));
1613
- }
1614
- set(date, flags) {
1615
- if (flags.timestampIsSet) return date;
1616
- return constructFrom(date, transpose(date, this.context));
1617
- }
1618
- }
1619
- class Parser {
1620
- run(dateString, token, match2, options) {
1621
- const result = this.parse(dateString, token, match2, options);
1622
- if (!result) {
1623
- return null;
1624
- }
1625
- return {
1626
- setter: new ValueSetter(
1627
- result.value,
1628
- this.validate,
1629
- this.set,
1630
- this.priority,
1631
- this.subPriority
1632
- ),
1633
- rest: result.rest
1634
- };
1635
- }
1636
- validate(_utcDate, _value, _options) {
1637
- return true;
1638
- }
1639
- }
1640
- class EraParser extends Parser {
1641
- constructor() {
1642
- super(...arguments);
1643
- __publicField(this, "priority", 140);
1644
- __publicField(this, "incompatibleTokens", ["R", "u", "t", "T"]);
1645
- }
1646
- parse(dateString, token, match2) {
1647
- switch (token) {
1648
- // AD, BC
1649
- case "G":
1650
- case "GG":
1651
- case "GGG":
1652
- return match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
1653
- // A, B
1654
- case "GGGGG":
1655
- return match2.era(dateString, { width: "narrow" });
1656
- // Anno Domini, Before Christ
1657
- case "GGGG":
1658
- default:
1659
- return match2.era(dateString, { width: "wide" }) || match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
1660
- }
1661
- }
1662
- set(date, flags, value) {
1663
- flags.era = value;
1664
- date.setFullYear(value, 0, 1);
1665
- date.setHours(0, 0, 0, 0);
1666
- return date;
1667
- }
1668
- }
1669
- const numericPatterns = {
1670
- month: /^(1[0-2]|0?\d)/,
1671
- // 0 to 12
1672
- date: /^(3[0-1]|[0-2]?\d)/,
1673
- // 0 to 31
1674
- dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
1675
- // 0 to 366
1676
- week: /^(5[0-3]|[0-4]?\d)/,
1677
- // 0 to 53
1678
- hour23h: /^(2[0-3]|[0-1]?\d)/,
1679
- // 0 to 23
1680
- hour24h: /^(2[0-4]|[0-1]?\d)/,
1681
- // 0 to 24
1682
- hour11h: /^(1[0-1]|0?\d)/,
1683
- // 0 to 11
1684
- hour12h: /^(1[0-2]|0?\d)/,
1685
- // 0 to 12
1686
- minute: /^[0-5]?\d/,
1687
- // 0 to 59
1688
- second: /^[0-5]?\d/,
1689
- // 0 to 59
1690
- singleDigit: /^\d/,
1691
- // 0 to 9
1692
- twoDigits: /^\d{1,2}/,
1693
- // 0 to 99
1694
- threeDigits: /^\d{1,3}/,
1695
- // 0 to 999
1696
- fourDigits: /^\d{1,4}/,
1697
- // 0 to 9999
1698
- anyDigitsSigned: /^-?\d+/,
1699
- singleDigitSigned: /^-?\d/,
1700
- // 0 to 9, -0 to -9
1701
- twoDigitsSigned: /^-?\d{1,2}/,
1702
- // 0 to 99, -0 to -99
1703
- threeDigitsSigned: /^-?\d{1,3}/,
1704
- // 0 to 999, -0 to -999
1705
- fourDigitsSigned: /^-?\d{1,4}/
1706
- // 0 to 9999, -0 to -9999
1707
- };
1708
- const timezonePatterns = {
1709
- basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
1710
- basic: /^([+-])(\d{2})(\d{2})|Z/,
1711
- basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
1712
- extended: /^([+-])(\d{2}):(\d{2})|Z/,
1713
- extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
1714
- };
1715
- function mapValue(parseFnResult, mapFn) {
1716
- if (!parseFnResult) {
1717
- return parseFnResult;
1718
- }
1719
- return {
1720
- value: mapFn(parseFnResult.value),
1721
- rest: parseFnResult.rest
1722
- };
1723
- }
1724
- function parseNumericPattern(pattern, dateString) {
1725
- const matchResult = dateString.match(pattern);
1726
- if (!matchResult) {
1727
- return null;
1728
- }
1729
- return {
1730
- value: parseInt(matchResult[0], 10),
1731
- rest: dateString.slice(matchResult[0].length)
1732
- };
1733
- }
1734
- function parseTimezonePattern(pattern, dateString) {
1735
- const matchResult = dateString.match(pattern);
1736
- if (!matchResult) {
1737
- return null;
1738
- }
1739
- if (matchResult[0] === "Z") {
1740
- return {
1741
- value: 0,
1742
- rest: dateString.slice(1)
1743
- };
1744
- }
1745
- const sign = matchResult[1] === "+" ? 1 : -1;
1746
- const hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
1747
- const minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
1748
- const seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
1749
- return {
1750
- value: sign * (hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * millisecondsInSecond),
1751
- rest: dateString.slice(matchResult[0].length)
1752
- };
1753
- }
1754
- function parseAnyDigitsSigned(dateString) {
1755
- return parseNumericPattern(numericPatterns.anyDigitsSigned, dateString);
1756
- }
1757
- function parseNDigits(n, dateString) {
1758
- switch (n) {
1759
- case 1:
1760
- return parseNumericPattern(numericPatterns.singleDigit, dateString);
1761
- case 2:
1762
- return parseNumericPattern(numericPatterns.twoDigits, dateString);
1763
- case 3:
1764
- return parseNumericPattern(numericPatterns.threeDigits, dateString);
1765
- case 4:
1766
- return parseNumericPattern(numericPatterns.fourDigits, dateString);
1767
- default:
1768
- return parseNumericPattern(new RegExp("^\\d{1," + n + "}"), dateString);
1769
- }
1770
- }
1771
- function parseNDigitsSigned(n, dateString) {
1772
- switch (n) {
1773
- case 1:
1774
- return parseNumericPattern(numericPatterns.singleDigitSigned, dateString);
1775
- case 2:
1776
- return parseNumericPattern(numericPatterns.twoDigitsSigned, dateString);
1777
- case 3:
1778
- return parseNumericPattern(numericPatterns.threeDigitsSigned, dateString);
1779
- case 4:
1780
- return parseNumericPattern(numericPatterns.fourDigitsSigned, dateString);
1781
- default:
1782
- return parseNumericPattern(new RegExp("^-?\\d{1," + n + "}"), dateString);
1783
- }
1784
- }
1785
- function dayPeriodEnumToHours(dayPeriod) {
1786
- switch (dayPeriod) {
1787
- case "morning":
1788
- return 4;
1789
- case "evening":
1790
- return 17;
1791
- case "pm":
1792
- case "noon":
1793
- case "afternoon":
1794
- return 12;
1795
- case "am":
1796
- case "midnight":
1797
- case "night":
1798
- default:
1799
- return 0;
1800
- }
1801
- }
1802
- function normalizeTwoDigitYear(twoDigitYear, currentYear) {
1803
- const isCommonEra = currentYear > 0;
1804
- const absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
1805
- let result;
1806
- if (absCurrentYear <= 50) {
1807
- result = twoDigitYear || 100;
1808
- } else {
1809
- const rangeEnd = absCurrentYear + 50;
1810
- const rangeEndCentury = Math.trunc(rangeEnd / 100) * 100;
1811
- const isPreviousCentury = twoDigitYear >= rangeEnd % 100;
1812
- result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
1813
- }
1814
- return isCommonEra ? result : 1 - result;
1815
- }
1816
- function isLeapYearIndex$1(year) {
1817
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
1818
- }
1819
- class YearParser extends Parser {
1820
- constructor() {
1821
- super(...arguments);
1822
- __publicField(this, "priority", 130);
1823
- __publicField(this, "incompatibleTokens", ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"]);
1824
- }
1825
- parse(dateString, token, match2) {
1826
- const valueCallback = (year) => ({
1827
- year,
1828
- isTwoDigitYear: token === "yy"
1829
- });
1830
- switch (token) {
1831
- case "y":
1832
- return mapValue(parseNDigits(4, dateString), valueCallback);
1833
- case "yo":
1834
- return mapValue(
1835
- match2.ordinalNumber(dateString, {
1836
- unit: "year"
1837
- }),
1838
- valueCallback
1839
- );
1840
- default:
1841
- return mapValue(parseNDigits(token.length, dateString), valueCallback);
1842
- }
1843
- }
1844
- validate(_date, value) {
1845
- return value.isTwoDigitYear || value.year > 0;
1846
- }
1847
- set(date, flags, value) {
1848
- const currentYear = date.getFullYear();
1849
- if (value.isTwoDigitYear) {
1850
- const normalizedTwoDigitYear = normalizeTwoDigitYear(
1851
- value.year,
1852
- currentYear
1853
- );
1854
- date.setFullYear(normalizedTwoDigitYear, 0, 1);
1855
- date.setHours(0, 0, 0, 0);
1856
- return date;
1857
- }
1858
- const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
1859
- date.setFullYear(year, 0, 1);
1860
- date.setHours(0, 0, 0, 0);
1861
- return date;
1862
- }
1863
- }
1864
- class LocalWeekYearParser extends Parser {
1865
- constructor() {
1866
- super(...arguments);
1867
- __publicField(this, "priority", 130);
1868
- __publicField(this, "incompatibleTokens", [
1869
- "y",
1870
- "R",
1871
- "u",
1872
- "Q",
1873
- "q",
1874
- "M",
1875
- "L",
1876
- "I",
1877
- "d",
1878
- "D",
1879
- "i",
1880
- "t",
1881
- "T"
1882
- ]);
1883
- }
1884
- parse(dateString, token, match2) {
1885
- const valueCallback = (year) => ({
1886
- year,
1887
- isTwoDigitYear: token === "YY"
1888
- });
1889
- switch (token) {
1890
- case "Y":
1891
- return mapValue(parseNDigits(4, dateString), valueCallback);
1892
- case "Yo":
1893
- return mapValue(
1894
- match2.ordinalNumber(dateString, {
1895
- unit: "year"
1896
- }),
1897
- valueCallback
1898
- );
1899
- default:
1900
- return mapValue(parseNDigits(token.length, dateString), valueCallback);
1901
- }
1902
- }
1903
- validate(_date, value) {
1904
- return value.isTwoDigitYear || value.year > 0;
1905
- }
1906
- set(date, flags, value, options) {
1907
- const currentYear = getWeekYear(date, options);
1908
- if (value.isTwoDigitYear) {
1909
- const normalizedTwoDigitYear = normalizeTwoDigitYear(
1910
- value.year,
1911
- currentYear
1912
- );
1913
- date.setFullYear(
1914
- normalizedTwoDigitYear,
1915
- 0,
1916
- options.firstWeekContainsDate
1917
- );
1918
- date.setHours(0, 0, 0, 0);
1919
- return startOfWeek(date, options);
1920
- }
1921
- const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
1922
- date.setFullYear(year, 0, options.firstWeekContainsDate);
1923
- date.setHours(0, 0, 0, 0);
1924
- return startOfWeek(date, options);
1925
- }
1926
- }
1927
- class ISOWeekYearParser extends Parser {
1928
- constructor() {
1929
- super(...arguments);
1930
- __publicField(this, "priority", 130);
1931
- __publicField(this, "incompatibleTokens", [
1932
- "G",
1933
- "y",
1934
- "Y",
1935
- "u",
1936
- "Q",
1937
- "q",
1938
- "M",
1939
- "L",
1940
- "w",
1941
- "d",
1942
- "D",
1943
- "e",
1944
- "c",
1945
- "t",
1946
- "T"
1947
- ]);
1948
- }
1949
- parse(dateString, token) {
1950
- if (token === "R") {
1951
- return parseNDigitsSigned(4, dateString);
1952
- }
1953
- return parseNDigitsSigned(token.length, dateString);
1954
- }
1955
- set(date, _flags, value) {
1956
- const firstWeekOfYear = constructFrom(date, 0);
1957
- firstWeekOfYear.setFullYear(value, 0, 4);
1958
- firstWeekOfYear.setHours(0, 0, 0, 0);
1959
- return startOfISOWeek(firstWeekOfYear);
1960
- }
1961
- }
1962
- class ExtendedYearParser extends Parser {
1963
- constructor() {
1964
- super(...arguments);
1965
- __publicField(this, "priority", 130);
1966
- __publicField(this, "incompatibleTokens", ["G", "y", "Y", "R", "w", "I", "i", "e", "c", "t", "T"]);
1967
- }
1968
- parse(dateString, token) {
1969
- if (token === "u") {
1970
- return parseNDigitsSigned(4, dateString);
1971
- }
1972
- return parseNDigitsSigned(token.length, dateString);
1973
- }
1974
- set(date, _flags, value) {
1975
- date.setFullYear(value, 0, 1);
1976
- date.setHours(0, 0, 0, 0);
1977
- return date;
1978
- }
1979
- }
1980
- class QuarterParser extends Parser {
1981
- constructor() {
1982
- super(...arguments);
1983
- __publicField(this, "priority", 120);
1984
- __publicField(this, "incompatibleTokens", [
1985
- "Y",
1986
- "R",
1987
- "q",
1988
- "M",
1989
- "L",
1990
- "w",
1991
- "I",
1992
- "d",
1993
- "D",
1994
- "i",
1995
- "e",
1996
- "c",
1997
- "t",
1998
- "T"
1999
- ]);
2000
- }
2001
- parse(dateString, token, match2) {
2002
- switch (token) {
2003
- // 1, 2, 3, 4
2004
- case "Q":
2005
- case "QQ":
2006
- return parseNDigits(token.length, dateString);
2007
- // 1st, 2nd, 3rd, 4th
2008
- case "Qo":
2009
- return match2.ordinalNumber(dateString, { unit: "quarter" });
2010
- // Q1, Q2, Q3, Q4
2011
- case "QQQ":
2012
- return match2.quarter(dateString, {
2013
- width: "abbreviated",
2014
- context: "formatting"
2015
- }) || match2.quarter(dateString, {
2016
- width: "narrow",
2017
- context: "formatting"
2018
- });
2019
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2020
- case "QQQQQ":
2021
- return match2.quarter(dateString, {
2022
- width: "narrow",
2023
- context: "formatting"
2024
- });
2025
- // 1st quarter, 2nd quarter, ...
2026
- case "QQQQ":
2027
- default:
2028
- return match2.quarter(dateString, {
2029
- width: "wide",
2030
- context: "formatting"
2031
- }) || match2.quarter(dateString, {
2032
- width: "abbreviated",
2033
- context: "formatting"
2034
- }) || match2.quarter(dateString, {
2035
- width: "narrow",
2036
- context: "formatting"
2037
- });
2038
- }
2039
- }
2040
- validate(_date, value) {
2041
- return value >= 1 && value <= 4;
2042
- }
2043
- set(date, _flags, value) {
2044
- date.setMonth((value - 1) * 3, 1);
2045
- date.setHours(0, 0, 0, 0);
2046
- return date;
2047
- }
2048
- }
2049
- class StandAloneQuarterParser extends Parser {
2050
- constructor() {
2051
- super(...arguments);
2052
- __publicField(this, "priority", 120);
2053
- __publicField(this, "incompatibleTokens", [
2054
- "Y",
2055
- "R",
2056
- "Q",
2057
- "M",
2058
- "L",
2059
- "w",
2060
- "I",
2061
- "d",
2062
- "D",
2063
- "i",
2064
- "e",
2065
- "c",
2066
- "t",
2067
- "T"
2068
- ]);
2069
- }
2070
- parse(dateString, token, match2) {
2071
- switch (token) {
2072
- // 1, 2, 3, 4
2073
- case "q":
2074
- case "qq":
2075
- return parseNDigits(token.length, dateString);
2076
- // 1st, 2nd, 3rd, 4th
2077
- case "qo":
2078
- return match2.ordinalNumber(dateString, { unit: "quarter" });
2079
- // Q1, Q2, Q3, Q4
2080
- case "qqq":
2081
- return match2.quarter(dateString, {
2082
- width: "abbreviated",
2083
- context: "standalone"
2084
- }) || match2.quarter(dateString, {
2085
- width: "narrow",
2086
- context: "standalone"
2087
- });
2088
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2089
- case "qqqqq":
2090
- return match2.quarter(dateString, {
2091
- width: "narrow",
2092
- context: "standalone"
2093
- });
2094
- // 1st quarter, 2nd quarter, ...
2095
- case "qqqq":
2096
- default:
2097
- return match2.quarter(dateString, {
2098
- width: "wide",
2099
- context: "standalone"
2100
- }) || match2.quarter(dateString, {
2101
- width: "abbreviated",
2102
- context: "standalone"
2103
- }) || match2.quarter(dateString, {
2104
- width: "narrow",
2105
- context: "standalone"
2106
- });
2107
- }
2108
- }
2109
- validate(_date, value) {
2110
- return value >= 1 && value <= 4;
2111
- }
2112
- set(date, _flags, value) {
2113
- date.setMonth((value - 1) * 3, 1);
2114
- date.setHours(0, 0, 0, 0);
2115
- return date;
2116
- }
2117
- }
2118
- class MonthParser extends Parser {
2119
- constructor() {
2120
- super(...arguments);
2121
- __publicField(this, "incompatibleTokens", [
2122
- "Y",
2123
- "R",
2124
- "q",
2125
- "Q",
2126
- "L",
2127
- "w",
2128
- "I",
2129
- "D",
2130
- "i",
2131
- "e",
2132
- "c",
2133
- "t",
2134
- "T"
2135
- ]);
2136
- __publicField(this, "priority", 110);
2137
- }
2138
- parse(dateString, token, match2) {
2139
- const valueCallback = (value) => value - 1;
2140
- switch (token) {
2141
- // 1, 2, ..., 12
2142
- case "M":
2143
- return mapValue(
2144
- parseNumericPattern(numericPatterns.month, dateString),
2145
- valueCallback
2146
- );
2147
- // 01, 02, ..., 12
2148
- case "MM":
2149
- return mapValue(parseNDigits(2, dateString), valueCallback);
2150
- // 1st, 2nd, ..., 12th
2151
- case "Mo":
2152
- return mapValue(
2153
- match2.ordinalNumber(dateString, {
2154
- unit: "month"
2155
- }),
2156
- valueCallback
2157
- );
2158
- // Jan, Feb, ..., Dec
2159
- case "MMM":
2160
- return match2.month(dateString, {
2161
- width: "abbreviated",
2162
- context: "formatting"
2163
- }) || match2.month(dateString, { width: "narrow", context: "formatting" });
2164
- // J, F, ..., D
2165
- case "MMMMM":
2166
- return match2.month(dateString, {
2167
- width: "narrow",
2168
- context: "formatting"
2169
- });
2170
- // January, February, ..., December
2171
- case "MMMM":
2172
- default:
2173
- return match2.month(dateString, { width: "wide", context: "formatting" }) || match2.month(dateString, {
2174
- width: "abbreviated",
2175
- context: "formatting"
2176
- }) || match2.month(dateString, { width: "narrow", context: "formatting" });
2177
- }
2178
- }
2179
- validate(_date, value) {
2180
- return value >= 0 && value <= 11;
2181
- }
2182
- set(date, _flags, value) {
2183
- date.setMonth(value, 1);
2184
- date.setHours(0, 0, 0, 0);
2185
- return date;
2186
- }
2187
- }
2188
- class StandAloneMonthParser extends Parser {
2189
- constructor() {
2190
- super(...arguments);
2191
- __publicField(this, "priority", 110);
2192
- __publicField(this, "incompatibleTokens", [
2193
- "Y",
2194
- "R",
2195
- "q",
2196
- "Q",
2197
- "M",
2198
- "w",
2199
- "I",
2200
- "D",
2201
- "i",
2202
- "e",
2203
- "c",
2204
- "t",
2205
- "T"
2206
- ]);
2207
- }
2208
- parse(dateString, token, match2) {
2209
- const valueCallback = (value) => value - 1;
2210
- switch (token) {
2211
- // 1, 2, ..., 12
2212
- case "L":
2213
- return mapValue(
2214
- parseNumericPattern(numericPatterns.month, dateString),
2215
- valueCallback
2216
- );
2217
- // 01, 02, ..., 12
2218
- case "LL":
2219
- return mapValue(parseNDigits(2, dateString), valueCallback);
2220
- // 1st, 2nd, ..., 12th
2221
- case "Lo":
2222
- return mapValue(
2223
- match2.ordinalNumber(dateString, {
2224
- unit: "month"
2225
- }),
2226
- valueCallback
2227
- );
2228
- // Jan, Feb, ..., Dec
2229
- case "LLL":
2230
- return match2.month(dateString, {
2231
- width: "abbreviated",
2232
- context: "standalone"
2233
- }) || match2.month(dateString, { width: "narrow", context: "standalone" });
2234
- // J, F, ..., D
2235
- case "LLLLL":
2236
- return match2.month(dateString, {
2237
- width: "narrow",
2238
- context: "standalone"
2239
- });
2240
- // January, February, ..., December
2241
- case "LLLL":
2242
- default:
2243
- return match2.month(dateString, { width: "wide", context: "standalone" }) || match2.month(dateString, {
2244
- width: "abbreviated",
2245
- context: "standalone"
2246
- }) || match2.month(dateString, { width: "narrow", context: "standalone" });
2247
- }
2248
- }
2249
- validate(_date, value) {
2250
- return value >= 0 && value <= 11;
2251
- }
2252
- set(date, _flags, value) {
2253
- date.setMonth(value, 1);
2254
- date.setHours(0, 0, 0, 0);
2255
- return date;
2256
- }
2257
- }
2258
- function setWeek(date, week, options) {
2259
- const date_ = toDate$1(date, options == null ? void 0 : options.in);
2260
- const diff = getWeek(date_, options) - week;
2261
- date_.setDate(date_.getDate() - diff * 7);
2262
- return toDate$1(date_, options == null ? void 0 : options.in);
2263
- }
2264
- class LocalWeekParser extends Parser {
2265
- constructor() {
2266
- super(...arguments);
2267
- __publicField(this, "priority", 100);
2268
- __publicField(this, "incompatibleTokens", [
2269
- "y",
2270
- "R",
2271
- "u",
2272
- "q",
2273
- "Q",
2274
- "M",
2275
- "L",
2276
- "I",
2277
- "d",
2278
- "D",
2279
- "i",
2280
- "t",
2281
- "T"
2282
- ]);
2283
- }
2284
- parse(dateString, token, match2) {
2285
- switch (token) {
2286
- case "w":
2287
- return parseNumericPattern(numericPatterns.week, dateString);
2288
- case "wo":
2289
- return match2.ordinalNumber(dateString, { unit: "week" });
2290
- default:
2291
- return parseNDigits(token.length, dateString);
2292
- }
2293
- }
2294
- validate(_date, value) {
2295
- return value >= 1 && value <= 53;
2296
- }
2297
- set(date, _flags, value, options) {
2298
- return startOfWeek(setWeek(date, value, options), options);
2299
- }
2300
- }
2301
- function setISOWeek(date, week, options) {
2302
- const _date = toDate$1(date, options == null ? void 0 : options.in);
2303
- const diff = getISOWeek(_date, options) - week;
2304
- _date.setDate(_date.getDate() - diff * 7);
2305
- return _date;
2306
- }
2307
- class ISOWeekParser extends Parser {
2308
- constructor() {
2309
- super(...arguments);
2310
- __publicField(this, "priority", 100);
2311
- __publicField(this, "incompatibleTokens", [
2312
- "y",
2313
- "Y",
2314
- "u",
2315
- "q",
2316
- "Q",
2317
- "M",
2318
- "L",
2319
- "w",
2320
- "d",
2321
- "D",
2322
- "e",
2323
- "c",
2324
- "t",
2325
- "T"
2326
- ]);
2327
- }
2328
- parse(dateString, token, match2) {
2329
- switch (token) {
2330
- case "I":
2331
- return parseNumericPattern(numericPatterns.week, dateString);
2332
- case "Io":
2333
- return match2.ordinalNumber(dateString, { unit: "week" });
2334
- default:
2335
- return parseNDigits(token.length, dateString);
2336
- }
2337
- }
2338
- validate(_date, value) {
2339
- return value >= 1 && value <= 53;
2340
- }
2341
- set(date, _flags, value) {
2342
- return startOfISOWeek(setISOWeek(date, value));
2343
- }
2344
- }
2345
- const DAYS_IN_MONTH$1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2346
- const DAYS_IN_MONTH_LEAP_YEAR$1 = [
2347
- 31,
2348
- 29,
2349
- 31,
2350
- 30,
2351
- 31,
2352
- 30,
2353
- 31,
2354
- 31,
2355
- 30,
2356
- 31,
2357
- 30,
2358
- 31
2359
- ];
2360
- class DateParser extends Parser {
2361
- constructor() {
2362
- super(...arguments);
2363
- __publicField(this, "priority", 90);
2364
- __publicField(this, "subPriority", 1);
2365
- __publicField(this, "incompatibleTokens", [
2366
- "Y",
2367
- "R",
2368
- "q",
2369
- "Q",
2370
- "w",
2371
- "I",
2372
- "D",
2373
- "i",
2374
- "e",
2375
- "c",
2376
- "t",
2377
- "T"
2378
- ]);
2379
- }
2380
- parse(dateString, token, match2) {
2381
- switch (token) {
2382
- case "d":
2383
- return parseNumericPattern(numericPatterns.date, dateString);
2384
- case "do":
2385
- return match2.ordinalNumber(dateString, { unit: "date" });
2386
- default:
2387
- return parseNDigits(token.length, dateString);
2388
- }
2389
- }
2390
- validate(date, value) {
2391
- const year = date.getFullYear();
2392
- const isLeapYear = isLeapYearIndex$1(year);
2393
- const month = date.getMonth();
2394
- if (isLeapYear) {
2395
- return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR$1[month];
2396
- } else {
2397
- return value >= 1 && value <= DAYS_IN_MONTH$1[month];
2398
- }
2399
- }
2400
- set(date, _flags, value) {
2401
- date.setDate(value);
2402
- date.setHours(0, 0, 0, 0);
2403
- return date;
2404
- }
2405
- }
2406
- class DayOfYearParser extends Parser {
2407
- constructor() {
2408
- super(...arguments);
2409
- __publicField(this, "priority", 90);
2410
- __publicField(this, "subpriority", 1);
2411
- __publicField(this, "incompatibleTokens", [
2412
- "Y",
2413
- "R",
2414
- "q",
2415
- "Q",
2416
- "M",
2417
- "L",
2418
- "w",
2419
- "I",
2420
- "d",
2421
- "E",
2422
- "i",
2423
- "e",
2424
- "c",
2425
- "t",
2426
- "T"
2427
- ]);
2428
- }
2429
- parse(dateString, token, match2) {
2430
- switch (token) {
2431
- case "D":
2432
- case "DD":
2433
- return parseNumericPattern(numericPatterns.dayOfYear, dateString);
2434
- case "Do":
2435
- return match2.ordinalNumber(dateString, { unit: "date" });
2436
- default:
2437
- return parseNDigits(token.length, dateString);
2438
- }
2439
- }
2440
- validate(date, value) {
2441
- const year = date.getFullYear();
2442
- const isLeapYear = isLeapYearIndex$1(year);
2443
- if (isLeapYear) {
2444
- return value >= 1 && value <= 366;
2445
- } else {
2446
- return value >= 1 && value <= 365;
2447
- }
2448
- }
2449
- set(date, _flags, value) {
2450
- date.setMonth(0, value);
2451
- date.setHours(0, 0, 0, 0);
2452
- return date;
2453
- }
2454
- }
2455
- function setDay(date, day, options) {
2456
- var _a, _b, _c, _d, _e, _f, _g, _h;
2457
- const defaultOptions2 = getDefaultOptions$1();
2458
- const weekStartsOn = (_h = (_g = (_d = (_c = options == null ? void 0 : options.weekStartsOn) != null ? _c : (_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.weekStartsOn) != null ? _d : defaultOptions2.weekStartsOn) != null ? _g : (_f = (_e = defaultOptions2.locale) == null ? void 0 : _e.options) == null ? void 0 : _f.weekStartsOn) != null ? _h : 0;
2459
- const date_ = toDate$1(date, options == null ? void 0 : options.in);
2460
- const currentDay = date_.getDay();
2461
- const remainder = day % 7;
2462
- const dayIndex = (remainder + 7) % 7;
2463
- const delta = 7 - weekStartsOn;
2464
- const diff = day < 0 || day > 6 ? day - (currentDay + delta) % 7 : (dayIndex + delta) % 7 - (currentDay + delta) % 7;
2465
- return addDays(date_, diff, options);
2466
- }
2467
- class DayParser extends Parser {
2468
- constructor() {
2469
- super(...arguments);
2470
- __publicField(this, "priority", 90);
2471
- __publicField(this, "incompatibleTokens", ["D", "i", "e", "c", "t", "T"]);
2472
- }
2473
- parse(dateString, token, match2) {
2474
- switch (token) {
2475
- // Tue
2476
- case "E":
2477
- case "EE":
2478
- case "EEE":
2479
- return match2.day(dateString, {
2480
- width: "abbreviated",
2481
- context: "formatting"
2482
- }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2483
- // T
2484
- case "EEEEE":
2485
- return match2.day(dateString, {
2486
- width: "narrow",
2487
- context: "formatting"
2488
- });
2489
- // Tu
2490
- case "EEEEEE":
2491
- return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2492
- // Tuesday
2493
- case "EEEE":
2494
- default:
2495
- return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
2496
- width: "abbreviated",
2497
- context: "formatting"
2498
- }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2499
- }
2500
- }
2501
- validate(_date, value) {
2502
- return value >= 0 && value <= 6;
2503
- }
2504
- set(date, _flags, value, options) {
2505
- date = setDay(date, value, options);
2506
- date.setHours(0, 0, 0, 0);
2507
- return date;
2508
- }
2509
- }
2510
- class LocalDayParser extends Parser {
2511
- constructor() {
2512
- super(...arguments);
2513
- __publicField(this, "priority", 90);
2514
- __publicField(this, "incompatibleTokens", [
2515
- "y",
2516
- "R",
2517
- "u",
2518
- "q",
2519
- "Q",
2520
- "M",
2521
- "L",
2522
- "I",
2523
- "d",
2524
- "D",
2525
- "E",
2526
- "i",
2527
- "c",
2528
- "t",
2529
- "T"
2530
- ]);
2531
- }
2532
- parse(dateString, token, match2, options) {
2533
- const valueCallback = (value) => {
2534
- const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
2535
- return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
2536
- };
2537
- switch (token) {
2538
- // 3
2539
- case "e":
2540
- case "ee":
2541
- return mapValue(parseNDigits(token.length, dateString), valueCallback);
2542
- // 3rd
2543
- case "eo":
2544
- return mapValue(
2545
- match2.ordinalNumber(dateString, {
2546
- unit: "day"
2547
- }),
2548
- valueCallback
2549
- );
2550
- // Tue
2551
- case "eee":
2552
- return match2.day(dateString, {
2553
- width: "abbreviated",
2554
- context: "formatting"
2555
- }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2556
- // T
2557
- case "eeeee":
2558
- return match2.day(dateString, {
2559
- width: "narrow",
2560
- context: "formatting"
2561
- });
2562
- // Tu
2563
- case "eeeeee":
2564
- return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2565
- // Tuesday
2566
- case "eeee":
2567
- default:
2568
- return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
2569
- width: "abbreviated",
2570
- context: "formatting"
2571
- }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
2572
- }
2573
- }
2574
- validate(_date, value) {
2575
- return value >= 0 && value <= 6;
2576
- }
2577
- set(date, _flags, value, options) {
2578
- date = setDay(date, value, options);
2579
- date.setHours(0, 0, 0, 0);
2580
- return date;
2581
- }
2582
- }
2583
- class StandAloneLocalDayParser extends Parser {
2584
- constructor() {
2585
- super(...arguments);
2586
- __publicField(this, "priority", 90);
2587
- __publicField(this, "incompatibleTokens", [
2588
- "y",
2589
- "R",
2590
- "u",
2591
- "q",
2592
- "Q",
2593
- "M",
2594
- "L",
2595
- "I",
2596
- "d",
2597
- "D",
2598
- "E",
2599
- "i",
2600
- "e",
2601
- "t",
2602
- "T"
2603
- ]);
2604
- }
2605
- parse(dateString, token, match2, options) {
2606
- const valueCallback = (value) => {
2607
- const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
2608
- return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
2609
- };
2610
- switch (token) {
2611
- // 3
2612
- case "c":
2613
- case "cc":
2614
- return mapValue(parseNDigits(token.length, dateString), valueCallback);
2615
- // 3rd
2616
- case "co":
2617
- return mapValue(
2618
- match2.ordinalNumber(dateString, {
2619
- unit: "day"
2620
- }),
2621
- valueCallback
2622
- );
2623
- // Tue
2624
- case "ccc":
2625
- return match2.day(dateString, {
2626
- width: "abbreviated",
2627
- context: "standalone"
2628
- }) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
2629
- // T
2630
- case "ccccc":
2631
- return match2.day(dateString, {
2632
- width: "narrow",
2633
- context: "standalone"
2634
- });
2635
- // Tu
2636
- case "cccccc":
2637
- return match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
2638
- // Tuesday
2639
- case "cccc":
2640
- default:
2641
- return match2.day(dateString, { width: "wide", context: "standalone" }) || match2.day(dateString, {
2642
- width: "abbreviated",
2643
- context: "standalone"
2644
- }) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
2645
- }
2646
- }
2647
- validate(_date, value) {
2648
- return value >= 0 && value <= 6;
2649
- }
2650
- set(date, _flags, value, options) {
2651
- date = setDay(date, value, options);
2652
- date.setHours(0, 0, 0, 0);
2653
- return date;
2654
- }
2655
- }
2656
- function setISODay(date, day, options) {
2657
- const date_ = toDate$1(date, options == null ? void 0 : options.in);
2658
- const currentDay = getISODay(date_, options);
2659
- const diff = day - currentDay;
2660
- return addDays(date_, diff, options);
2661
- }
2662
- class ISODayParser extends Parser {
2663
- constructor() {
2664
- super(...arguments);
2665
- __publicField(this, "priority", 90);
2666
- __publicField(this, "incompatibleTokens", [
2667
- "y",
2668
- "Y",
2669
- "u",
2670
- "q",
2671
- "Q",
2672
- "M",
2673
- "L",
2674
- "w",
2675
- "d",
2676
- "D",
2677
- "E",
2678
- "e",
2679
- "c",
2680
- "t",
2681
- "T"
2682
- ]);
2683
- }
2684
- parse(dateString, token, match2) {
2685
- const valueCallback = (value) => {
2686
- if (value === 0) {
2687
- return 7;
2688
- }
2689
- return value;
2690
- };
2691
- switch (token) {
2692
- // 2
2693
- case "i":
2694
- case "ii":
2695
- return parseNDigits(token.length, dateString);
2696
- // 2nd
2697
- case "io":
2698
- return match2.ordinalNumber(dateString, { unit: "day" });
2699
- // Tue
2700
- case "iii":
2701
- return mapValue(
2702
- match2.day(dateString, {
2703
- width: "abbreviated",
2704
- context: "formatting"
2705
- }) || match2.day(dateString, {
2706
- width: "short",
2707
- context: "formatting"
2708
- }) || match2.day(dateString, {
2709
- width: "narrow",
2710
- context: "formatting"
2711
- }),
2712
- valueCallback
2713
- );
2714
- // T
2715
- case "iiiii":
2716
- return mapValue(
2717
- match2.day(dateString, {
2718
- width: "narrow",
2719
- context: "formatting"
2720
- }),
2721
- valueCallback
2722
- );
2723
- // Tu
2724
- case "iiiiii":
2725
- return mapValue(
2726
- match2.day(dateString, {
2727
- width: "short",
2728
- context: "formatting"
2729
- }) || match2.day(dateString, {
2730
- width: "narrow",
2731
- context: "formatting"
2732
- }),
2733
- valueCallback
2734
- );
2735
- // Tuesday
2736
- case "iiii":
2737
- default:
2738
- return mapValue(
2739
- match2.day(dateString, {
2740
- width: "wide",
2741
- context: "formatting"
2742
- }) || match2.day(dateString, {
2743
- width: "abbreviated",
2744
- context: "formatting"
2745
- }) || match2.day(dateString, {
2746
- width: "short",
2747
- context: "formatting"
2748
- }) || match2.day(dateString, {
2749
- width: "narrow",
2750
- context: "formatting"
2751
- }),
2752
- valueCallback
2753
- );
2754
- }
2755
- }
2756
- validate(_date, value) {
2757
- return value >= 1 && value <= 7;
2758
- }
2759
- set(date, _flags, value) {
2760
- date = setISODay(date, value);
2761
- date.setHours(0, 0, 0, 0);
2762
- return date;
2763
- }
2764
- }
2765
- class AMPMParser extends Parser {
2766
- constructor() {
2767
- super(...arguments);
2768
- __publicField(this, "priority", 80);
2769
- __publicField(this, "incompatibleTokens", ["b", "B", "H", "k", "t", "T"]);
2770
- }
2771
- parse(dateString, token, match2) {
2772
- switch (token) {
2773
- case "a":
2774
- case "aa":
2775
- case "aaa":
2776
- return match2.dayPeriod(dateString, {
2777
- width: "abbreviated",
2778
- context: "formatting"
2779
- }) || match2.dayPeriod(dateString, {
2780
- width: "narrow",
2781
- context: "formatting"
2782
- });
2783
- case "aaaaa":
2784
- return match2.dayPeriod(dateString, {
2785
- width: "narrow",
2786
- context: "formatting"
2787
- });
2788
- case "aaaa":
2789
- default:
2790
- return match2.dayPeriod(dateString, {
2791
- width: "wide",
2792
- context: "formatting"
2793
- }) || match2.dayPeriod(dateString, {
2794
- width: "abbreviated",
2795
- context: "formatting"
2796
- }) || match2.dayPeriod(dateString, {
2797
- width: "narrow",
2798
- context: "formatting"
2799
- });
2800
- }
2801
- }
2802
- set(date, _flags, value) {
2803
- date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
2804
- return date;
2805
- }
2806
- }
2807
- class AMPMMidnightParser extends Parser {
2808
- constructor() {
2809
- super(...arguments);
2810
- __publicField(this, "priority", 80);
2811
- __publicField(this, "incompatibleTokens", ["a", "B", "H", "k", "t", "T"]);
2812
- }
2813
- parse(dateString, token, match2) {
2814
- switch (token) {
2815
- case "b":
2816
- case "bb":
2817
- case "bbb":
2818
- return match2.dayPeriod(dateString, {
2819
- width: "abbreviated",
2820
- context: "formatting"
2821
- }) || match2.dayPeriod(dateString, {
2822
- width: "narrow",
2823
- context: "formatting"
2824
- });
2825
- case "bbbbb":
2826
- return match2.dayPeriod(dateString, {
2827
- width: "narrow",
2828
- context: "formatting"
2829
- });
2830
- case "bbbb":
2831
- default:
2832
- return match2.dayPeriod(dateString, {
2833
- width: "wide",
2834
- context: "formatting"
2835
- }) || match2.dayPeriod(dateString, {
2836
- width: "abbreviated",
2837
- context: "formatting"
2838
- }) || match2.dayPeriod(dateString, {
2839
- width: "narrow",
2840
- context: "formatting"
2841
- });
2842
- }
2843
- }
2844
- set(date, _flags, value) {
2845
- date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
2846
- return date;
2847
- }
2848
- }
2849
- class DayPeriodParser extends Parser {
2850
- constructor() {
2851
- super(...arguments);
2852
- __publicField(this, "priority", 80);
2853
- __publicField(this, "incompatibleTokens", ["a", "b", "t", "T"]);
2854
- }
2855
- parse(dateString, token, match2) {
2856
- switch (token) {
2857
- case "B":
2858
- case "BB":
2859
- case "BBB":
2860
- return match2.dayPeriod(dateString, {
2861
- width: "abbreviated",
2862
- context: "formatting"
2863
- }) || match2.dayPeriod(dateString, {
2864
- width: "narrow",
2865
- context: "formatting"
2866
- });
2867
- case "BBBBB":
2868
- return match2.dayPeriod(dateString, {
2869
- width: "narrow",
2870
- context: "formatting"
2871
- });
2872
- case "BBBB":
2873
- default:
2874
- return match2.dayPeriod(dateString, {
2875
- width: "wide",
2876
- context: "formatting"
2877
- }) || match2.dayPeriod(dateString, {
2878
- width: "abbreviated",
2879
- context: "formatting"
2880
- }) || match2.dayPeriod(dateString, {
2881
- width: "narrow",
2882
- context: "formatting"
2883
- });
2884
- }
2885
- }
2886
- set(date, _flags, value) {
2887
- date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
2888
- return date;
2889
- }
2890
- }
2891
- class Hour1to12Parser extends Parser {
2892
- constructor() {
2893
- super(...arguments);
2894
- __publicField(this, "priority", 70);
2895
- __publicField(this, "incompatibleTokens", ["H", "K", "k", "t", "T"]);
2896
- }
2897
- parse(dateString, token, match2) {
2898
- switch (token) {
2899
- case "h":
2900
- return parseNumericPattern(numericPatterns.hour12h, dateString);
2901
- case "ho":
2902
- return match2.ordinalNumber(dateString, { unit: "hour" });
2903
- default:
2904
- return parseNDigits(token.length, dateString);
2905
- }
2906
- }
2907
- validate(_date, value) {
2908
- return value >= 1 && value <= 12;
2909
- }
2910
- set(date, _flags, value) {
2911
- const isPM = date.getHours() >= 12;
2912
- if (isPM && value < 12) {
2913
- date.setHours(value + 12, 0, 0, 0);
2914
- } else if (!isPM && value === 12) {
2915
- date.setHours(0, 0, 0, 0);
2916
- } else {
2917
- date.setHours(value, 0, 0, 0);
2918
- }
2919
- return date;
2920
- }
2921
- }
2922
- class Hour0to23Parser extends Parser {
2923
- constructor() {
2924
- super(...arguments);
2925
- __publicField(this, "priority", 70);
2926
- __publicField(this, "incompatibleTokens", ["a", "b", "h", "K", "k", "t", "T"]);
2927
- }
2928
- parse(dateString, token, match2) {
2929
- switch (token) {
2930
- case "H":
2931
- return parseNumericPattern(numericPatterns.hour23h, dateString);
2932
- case "Ho":
2933
- return match2.ordinalNumber(dateString, { unit: "hour" });
2934
- default:
2935
- return parseNDigits(token.length, dateString);
2936
- }
2937
- }
2938
- validate(_date, value) {
2939
- return value >= 0 && value <= 23;
2940
- }
2941
- set(date, _flags, value) {
2942
- date.setHours(value, 0, 0, 0);
2943
- return date;
2944
- }
2945
- }
2946
- class Hour0To11Parser extends Parser {
2947
- constructor() {
2948
- super(...arguments);
2949
- __publicField(this, "priority", 70);
2950
- __publicField(this, "incompatibleTokens", ["h", "H", "k", "t", "T"]);
2951
- }
2952
- parse(dateString, token, match2) {
2953
- switch (token) {
2954
- case "K":
2955
- return parseNumericPattern(numericPatterns.hour11h, dateString);
2956
- case "Ko":
2957
- return match2.ordinalNumber(dateString, { unit: "hour" });
2958
- default:
2959
- return parseNDigits(token.length, dateString);
2960
- }
2961
- }
2962
- validate(_date, value) {
2963
- return value >= 0 && value <= 11;
2964
- }
2965
- set(date, _flags, value) {
2966
- const isPM = date.getHours() >= 12;
2967
- if (isPM && value < 12) {
2968
- date.setHours(value + 12, 0, 0, 0);
2969
- } else {
2970
- date.setHours(value, 0, 0, 0);
2971
- }
2972
- return date;
2973
- }
2974
- }
2975
- class Hour1To24Parser extends Parser {
2976
- constructor() {
2977
- super(...arguments);
2978
- __publicField(this, "priority", 70);
2979
- __publicField(this, "incompatibleTokens", ["a", "b", "h", "H", "K", "t", "T"]);
2980
- }
2981
- parse(dateString, token, match2) {
2982
- switch (token) {
2983
- case "k":
2984
- return parseNumericPattern(numericPatterns.hour24h, dateString);
2985
- case "ko":
2986
- return match2.ordinalNumber(dateString, { unit: "hour" });
2987
- default:
2988
- return parseNDigits(token.length, dateString);
2989
- }
2990
- }
2991
- validate(_date, value) {
2992
- return value >= 1 && value <= 24;
2993
- }
2994
- set(date, _flags, value) {
2995
- const hours = value <= 24 ? value % 24 : value;
2996
- date.setHours(hours, 0, 0, 0);
2997
- return date;
2998
- }
2999
- }
3000
- class MinuteParser extends Parser {
3001
- constructor() {
3002
- super(...arguments);
3003
- __publicField(this, "priority", 60);
3004
- __publicField(this, "incompatibleTokens", ["t", "T"]);
3005
- }
3006
- parse(dateString, token, match2) {
3007
- switch (token) {
3008
- case "m":
3009
- return parseNumericPattern(numericPatterns.minute, dateString);
3010
- case "mo":
3011
- return match2.ordinalNumber(dateString, { unit: "minute" });
3012
- default:
3013
- return parseNDigits(token.length, dateString);
3014
- }
3015
- }
3016
- validate(_date, value) {
3017
- return value >= 0 && value <= 59;
3018
- }
3019
- set(date, _flags, value) {
3020
- date.setMinutes(value, 0, 0);
3021
- return date;
3022
- }
3023
- }
3024
- class SecondParser extends Parser {
3025
- constructor() {
3026
- super(...arguments);
3027
- __publicField(this, "priority", 50);
3028
- __publicField(this, "incompatibleTokens", ["t", "T"]);
3029
- }
3030
- parse(dateString, token, match2) {
3031
- switch (token) {
3032
- case "s":
3033
- return parseNumericPattern(numericPatterns.second, dateString);
3034
- case "so":
3035
- return match2.ordinalNumber(dateString, { unit: "second" });
3036
- default:
3037
- return parseNDigits(token.length, dateString);
3038
- }
3039
- }
3040
- validate(_date, value) {
3041
- return value >= 0 && value <= 59;
3042
- }
3043
- set(date, _flags, value) {
3044
- date.setSeconds(value, 0);
3045
- return date;
3046
- }
3047
- }
3048
- class FractionOfSecondParser extends Parser {
3049
- constructor() {
3050
- super(...arguments);
3051
- __publicField(this, "priority", 30);
3052
- __publicField(this, "incompatibleTokens", ["t", "T"]);
3053
- }
3054
- parse(dateString, token) {
3055
- const valueCallback = (value) => Math.trunc(value * Math.pow(10, -token.length + 3));
3056
- return mapValue(parseNDigits(token.length, dateString), valueCallback);
3057
- }
3058
- set(date, _flags, value) {
3059
- date.setMilliseconds(value);
3060
- return date;
3061
- }
3062
- }
3063
- class ISOTimezoneWithZParser extends Parser {
3064
- constructor() {
3065
- super(...arguments);
3066
- __publicField(this, "priority", 10);
3067
- __publicField(this, "incompatibleTokens", ["t", "T", "x"]);
3068
- }
3069
- parse(dateString, token) {
3070
- switch (token) {
3071
- case "X":
3072
- return parseTimezonePattern(
3073
- timezonePatterns.basicOptionalMinutes,
3074
- dateString
3075
- );
3076
- case "XX":
3077
- return parseTimezonePattern(timezonePatterns.basic, dateString);
3078
- case "XXXX":
3079
- return parseTimezonePattern(
3080
- timezonePatterns.basicOptionalSeconds,
3081
- dateString
3082
- );
3083
- case "XXXXX":
3084
- return parseTimezonePattern(
3085
- timezonePatterns.extendedOptionalSeconds,
3086
- dateString
3087
- );
3088
- case "XXX":
3089
- default:
3090
- return parseTimezonePattern(timezonePatterns.extended, dateString);
3091
- }
3092
- }
3093
- set(date, flags, value) {
3094
- if (flags.timestampIsSet) return date;
3095
- return constructFrom(
3096
- date,
3097
- date.getTime() - getTimezoneOffsetInMilliseconds$1(date) - value
3098
- );
3099
- }
3100
- }
3101
- class ISOTimezoneParser extends Parser {
3102
- constructor() {
3103
- super(...arguments);
3104
- __publicField(this, "priority", 10);
3105
- __publicField(this, "incompatibleTokens", ["t", "T", "X"]);
3106
- }
3107
- parse(dateString, token) {
3108
- switch (token) {
3109
- case "x":
3110
- return parseTimezonePattern(
3111
- timezonePatterns.basicOptionalMinutes,
3112
- dateString
3113
- );
3114
- case "xx":
3115
- return parseTimezonePattern(timezonePatterns.basic, dateString);
3116
- case "xxxx":
3117
- return parseTimezonePattern(
3118
- timezonePatterns.basicOptionalSeconds,
3119
- dateString
3120
- );
3121
- case "xxxxx":
3122
- return parseTimezonePattern(
3123
- timezonePatterns.extendedOptionalSeconds,
3124
- dateString
3125
- );
3126
- case "xxx":
3127
- default:
3128
- return parseTimezonePattern(timezonePatterns.extended, dateString);
3129
- }
3130
- }
3131
- set(date, flags, value) {
3132
- if (flags.timestampIsSet) return date;
3133
- return constructFrom(
3134
- date,
3135
- date.getTime() - getTimezoneOffsetInMilliseconds$1(date) - value
3136
- );
3137
- }
3138
- }
3139
- class TimestampSecondsParser extends Parser {
3140
- constructor() {
3141
- super(...arguments);
3142
- __publicField(this, "priority", 40);
3143
- __publicField(this, "incompatibleTokens", "*");
3144
- }
3145
- parse(dateString) {
3146
- return parseAnyDigitsSigned(dateString);
3147
- }
3148
- set(date, _flags, value) {
3149
- return [constructFrom(date, value * 1e3), { timestampIsSet: true }];
3150
- }
3151
- }
3152
- class TimestampMillisecondsParser extends Parser {
3153
- constructor() {
3154
- super(...arguments);
3155
- __publicField(this, "priority", 20);
3156
- __publicField(this, "incompatibleTokens", "*");
3157
- }
3158
- parse(dateString) {
3159
- return parseAnyDigitsSigned(dateString);
3160
- }
3161
- set(date, _flags, value) {
3162
- return [constructFrom(date, value), { timestampIsSet: true }];
3163
- }
3164
- }
3165
- const parsers = {
3166
- G: new EraParser(),
3167
- y: new YearParser(),
3168
- Y: new LocalWeekYearParser(),
3169
- R: new ISOWeekYearParser(),
3170
- u: new ExtendedYearParser(),
3171
- Q: new QuarterParser(),
3172
- q: new StandAloneQuarterParser(),
3173
- M: new MonthParser(),
3174
- L: new StandAloneMonthParser(),
3175
- w: new LocalWeekParser(),
3176
- I: new ISOWeekParser(),
3177
- d: new DateParser(),
3178
- D: new DayOfYearParser(),
3179
- E: new DayParser(),
3180
- e: new LocalDayParser(),
3181
- c: new StandAloneLocalDayParser(),
3182
- i: new ISODayParser(),
3183
- a: new AMPMParser(),
3184
- b: new AMPMMidnightParser(),
3185
- B: new DayPeriodParser(),
3186
- h: new Hour1to12Parser(),
3187
- H: new Hour0to23Parser(),
3188
- K: new Hour0To11Parser(),
3189
- k: new Hour1To24Parser(),
3190
- m: new MinuteParser(),
3191
- s: new SecondParser(),
3192
- S: new FractionOfSecondParser(),
3193
- X: new ISOTimezoneWithZParser(),
3194
- x: new ISOTimezoneParser(),
3195
- t: new TimestampSecondsParser(),
3196
- T: new TimestampMillisecondsParser()
3197
- };
3198
- const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
3199
- const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
3200
- const escapedStringRegExp = /^'([^]*?)'?$/;
3201
- const doubleQuoteRegExp = /''/g;
3202
- const notWhitespaceRegExp = /\S/;
3203
- const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
3204
- function parse(dateStr, formatStr, referenceDate, options) {
3205
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3206
- const invalidDate = () => constructFrom(referenceDate, NaN);
3207
- const defaultOptions2 = getDefaultOptions();
3208
- const locale = (_a = defaultOptions2.locale) != null ? _a : enUS;
3209
- const firstWeekContainsDate = (_e = (_d = defaultOptions2.firstWeekContainsDate) != null ? _d : (_c = (_b = defaultOptions2.locale) == null ? void 0 : _b.options) == null ? void 0 : _c.firstWeekContainsDate) != null ? _e : 1;
3210
- const weekStartsOn = (_i = (_h = defaultOptions2.weekStartsOn) != null ? _h : (_g = (_f = defaultOptions2.locale) == null ? void 0 : _f.options) == null ? void 0 : _g.weekStartsOn) != null ? _i : 0;
3211
- const subFnOptions = {
3212
- firstWeekContainsDate,
3213
- weekStartsOn,
3214
- locale
3215
- };
3216
- const setters = [new DateTimezoneSetter(options == null ? void 0 : options.in, referenceDate)];
3217
- const tokens = formatStr.match(longFormattingTokensRegExp).map((substring) => {
3218
- const firstCharacter = substring[0];
3219
- if (firstCharacter in longFormatters) {
3220
- const longFormatter = longFormatters[firstCharacter];
3221
- return longFormatter(substring, locale.formatLong);
3222
- }
3223
- return substring;
3224
- }).join("").match(formattingTokensRegExp);
3225
- const usedTokens = [];
3226
- for (let token of tokens) {
3227
- if (isProtectedWeekYearToken(token)) {
3228
- warnOrThrowProtectedError(token, formatStr, dateStr);
3229
- }
3230
- if (isProtectedDayOfYearToken(token)) {
3231
- warnOrThrowProtectedError(token, formatStr, dateStr);
3232
- }
3233
- const firstCharacter = token[0];
3234
- const parser = parsers[firstCharacter];
3235
- if (parser) {
3236
- const { incompatibleTokens } = parser;
3237
- if (Array.isArray(incompatibleTokens)) {
3238
- const incompatibleToken = usedTokens.find(
3239
- (usedToken) => incompatibleTokens.includes(usedToken.token) || usedToken.token === firstCharacter
3240
- );
3241
- if (incompatibleToken) {
3242
- throw new RangeError(
3243
- `The format string mustn't contain \`${incompatibleToken.fullToken}\` and \`${token}\` at the same time`
3244
- );
3245
- }
3246
- } else if (parser.incompatibleTokens === "*" && usedTokens.length > 0) {
3247
- throw new RangeError(
3248
- `The format string mustn't contain \`${token}\` and any other token at the same time`
3249
- );
3250
- }
3251
- usedTokens.push({ token: firstCharacter, fullToken: token });
3252
- const parseResult = parser.run(
3253
- dateStr,
3254
- token,
3255
- locale.match,
3256
- subFnOptions
3257
- );
3258
- if (!parseResult) {
3259
- return invalidDate();
3260
- }
3261
- setters.push(parseResult.setter);
3262
- dateStr = parseResult.rest;
3263
- } else {
3264
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
3265
- throw new RangeError(
3266
- "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
3267
- );
3268
- }
3269
- if (token === "''") {
3270
- token = "'";
3271
- } else if (firstCharacter === "'") {
3272
- token = cleanEscapedString(token);
3273
- }
3274
- if (dateStr.indexOf(token) === 0) {
3275
- dateStr = dateStr.slice(token.length);
3276
- } else {
3277
- return invalidDate();
3278
- }
3279
- }
3280
- }
3281
- if (dateStr.length > 0 && notWhitespaceRegExp.test(dateStr)) {
3282
- return invalidDate();
3283
- }
3284
- const uniquePrioritySetters = setters.map((setter) => setter.priority).sort((a, b) => b - a).filter((priority, index, array) => array.indexOf(priority) === index).map(
3285
- (priority) => setters.filter((setter) => setter.priority === priority).sort((a, b) => b.subPriority - a.subPriority)
3286
- ).map((setterArray) => setterArray[0]);
3287
- let date = toDate$1(referenceDate, options == null ? void 0 : options.in);
3288
- if (isNaN(+date)) return invalidDate();
3289
- const flags = {};
3290
- for (const setter of uniquePrioritySetters) {
3291
- if (!setter.validate(date, subFnOptions)) {
3292
- return invalidDate();
3293
- }
3294
- const result = setter.set(date, flags, subFnOptions);
3295
- if (Array.isArray(result)) {
3296
- date = result[0];
3297
- Object.assign(flags, result[1]);
3298
- } else {
3299
- date = result;
3300
- }
3301
- }
3302
- return date;
3303
- }
3304
- function cleanEscapedString(input) {
3305
- return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
3306
- }
3307
- function tzIntlTimeZoneName(length, date, options) {
3308
- var _a;
3309
- const defaultOptions2 = getDefaultOptions();
3310
- const dtf = getDTF(length, options.timeZone, (_a = options.locale) != null ? _a : defaultOptions2.locale);
3311
- return "formatToParts" in dtf ? partsTimeZone(dtf, date) : hackyTimeZone(dtf, date);
3312
- }
3313
- function partsTimeZone(dtf, date) {
3314
- const formatted = dtf.formatToParts(date);
3315
- for (let i = formatted.length - 1; i >= 0; --i) {
3316
- if (formatted[i].type === "timeZoneName") {
3317
- return formatted[i].value;
3318
- }
3319
- }
3320
- return void 0;
3321
- }
3322
- function hackyTimeZone(dtf, date) {
3323
- const formatted = dtf.format(date).replace(/\u200E/g, "");
3324
- const tzNameMatch = / [\w-+ ]+$/.exec(formatted);
3325
- return tzNameMatch ? tzNameMatch[0].substr(1) : "";
3326
- }
3327
- function getDTF(length, timeZone, locale) {
3328
- return new Intl.DateTimeFormat(locale ? [locale.code, "en-US"] : void 0, {
3329
- timeZone,
3330
- timeZoneName: length
3331
- });
3332
- }
3333
- function tzTokenizeDate(date, timeZone) {
3334
- const dtf = getDateTimeFormat(timeZone);
3335
- return "formatToParts" in dtf ? partsOffset(dtf, date) : hackyOffset(dtf, date);
3336
- }
3337
- const typeToPos = {
3338
- year: 0,
3339
- month: 1,
3340
- day: 2,
3341
- hour: 3,
3342
- minute: 4,
3343
- second: 5
3344
- };
3345
- function partsOffset(dtf, date) {
3346
- try {
3347
- const formatted = dtf.formatToParts(date);
3348
- const filled = [];
3349
- for (let i = 0; i < formatted.length; i++) {
3350
- const pos = typeToPos[formatted[i].type];
3351
- if (pos !== void 0) {
3352
- filled[pos] = parseInt(formatted[i].value, 10);
3353
- }
3354
- }
3355
- return filled;
3356
- } catch (error) {
3357
- if (error instanceof RangeError) {
3358
- return [NaN];
3359
- }
3360
- throw error;
3361
- }
3362
- }
3363
- function hackyOffset(dtf, date) {
3364
- const formatted = dtf.format(date);
3365
- const parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted);
3366
- return [
3367
- parseInt(parsed[3], 10),
3368
- parseInt(parsed[1], 10),
3369
- parseInt(parsed[2], 10),
3370
- parseInt(parsed[4], 10),
3371
- parseInt(parsed[5], 10),
3372
- parseInt(parsed[6], 10)
3373
- ];
3374
- }
3375
- const dtfCache = {};
3376
- const testDateFormatted = new Intl.DateTimeFormat("en-US", {
3377
- hourCycle: "h23",
3378
- timeZone: "America/New_York",
3379
- year: "numeric",
3380
- month: "2-digit",
3381
- day: "2-digit",
3382
- hour: "2-digit",
3383
- minute: "2-digit",
3384
- second: "2-digit"
3385
- }).format(/* @__PURE__ */ new Date("2014-06-25T04:00:00.123Z"));
3386
- const hourCycleSupported = testDateFormatted === "06/25/2014, 00:00:00" || testDateFormatted === "‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00";
3387
- function getDateTimeFormat(timeZone) {
3388
- if (!dtfCache[timeZone]) {
3389
- dtfCache[timeZone] = hourCycleSupported ? new Intl.DateTimeFormat("en-US", {
3390
- hourCycle: "h23",
3391
- timeZone,
3392
- year: "numeric",
3393
- month: "numeric",
3394
- day: "2-digit",
3395
- hour: "2-digit",
3396
- minute: "2-digit",
3397
- second: "2-digit"
3398
- }) : new Intl.DateTimeFormat("en-US", {
3399
- hour12: false,
3400
- timeZone,
3401
- year: "numeric",
3402
- month: "numeric",
3403
- day: "2-digit",
3404
- hour: "2-digit",
3405
- minute: "2-digit",
3406
- second: "2-digit"
3407
- });
3408
- }
3409
- return dtfCache[timeZone];
3410
- }
3411
- function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) {
3412
- const utcDate = /* @__PURE__ */ new Date(0);
3413
- utcDate.setUTCFullYear(fullYear, month, day);
3414
- utcDate.setUTCHours(hour, minute, second, millisecond);
3415
- return utcDate;
3416
- }
3417
- const MILLISECONDS_IN_HOUR$1 = 36e5;
3418
- const MILLISECONDS_IN_MINUTE$2 = 6e4;
3419
- const patterns$1 = {
3420
- timezoneZ: /^(Z)$/,
3421
- timezoneHH: /^([+-]\d{2})$/,
3422
- timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/
3423
- };
3424
- function tzParseTimezone(timezoneString, date, isUtcDate) {
3425
- if (!timezoneString) {
3426
- return 0;
3427
- }
3428
- let token = patterns$1.timezoneZ.exec(timezoneString);
3429
- if (token) {
3430
- return 0;
3431
- }
3432
- let hours;
3433
- let absoluteOffset;
3434
- token = patterns$1.timezoneHH.exec(timezoneString);
3435
- if (token) {
3436
- hours = parseInt(token[1], 10);
3437
- if (!validateTimezone(hours)) {
3438
- return NaN;
3439
- }
3440
- return -(hours * MILLISECONDS_IN_HOUR$1);
3441
- }
3442
- token = patterns$1.timezoneHHMM.exec(timezoneString);
3443
- if (token) {
3444
- hours = parseInt(token[2], 10);
3445
- const minutes = parseInt(token[3], 10);
3446
- if (!validateTimezone(hours, minutes)) {
3447
- return NaN;
3448
- }
3449
- absoluteOffset = Math.abs(hours) * MILLISECONDS_IN_HOUR$1 + minutes * MILLISECONDS_IN_MINUTE$2;
3450
- return token[1] === "+" ? -absoluteOffset : absoluteOffset;
3451
- }
3452
- if (isValidTimezoneIANAString(timezoneString)) {
3453
- date = new Date(date || Date.now());
3454
- const utcDate = isUtcDate ? date : toUtcDate(date);
3455
- const offset = calcOffset(utcDate, timezoneString);
3456
- const fixedOffset = isUtcDate ? offset : fixOffset(date, offset, timezoneString);
3457
- return -fixedOffset;
3458
- }
3459
- return NaN;
3460
- }
3461
- function toUtcDate(date) {
3462
- return newDateUTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
3463
- }
3464
- function calcOffset(date, timezoneString) {
3465
- const tokens = tzTokenizeDate(date, timezoneString);
3466
- const asUTC = newDateUTC(tokens[0], tokens[1] - 1, tokens[2], tokens[3] % 24, tokens[4], tokens[5], 0).getTime();
3467
- let asTS = date.getTime();
3468
- const over = asTS % 1e3;
3469
- asTS -= over >= 0 ? over : 1e3 + over;
3470
- return asUTC - asTS;
3471
- }
3472
- function fixOffset(date, offset, timezoneString) {
3473
- const localTS = date.getTime();
3474
- let utcGuess = localTS - offset;
3475
- const o2 = calcOffset(new Date(utcGuess), timezoneString);
3476
- if (offset === o2) {
3477
- return offset;
3478
- }
3479
- utcGuess -= o2 - offset;
3480
- const o3 = calcOffset(new Date(utcGuess), timezoneString);
3481
- if (o2 === o3) {
3482
- return o2;
3483
- }
3484
- return Math.max(o2, o3);
3485
- }
3486
- function validateTimezone(hours, minutes) {
3487
- return -23 <= hours && hours <= 23 && (minutes == null || 0 <= minutes && minutes <= 59);
3488
- }
3489
- const validIANATimezoneCache = {};
3490
- function isValidTimezoneIANAString(timeZoneString) {
3491
- if (validIANATimezoneCache[timeZoneString])
3492
- return true;
3493
- try {
3494
- new Intl.DateTimeFormat(void 0, { timeZone: timeZoneString });
3495
- validIANATimezoneCache[timeZoneString] = true;
3496
- return true;
3497
- } catch (error) {
3498
- return false;
3499
- }
3500
- }
3501
- const MILLISECONDS_IN_MINUTE$1 = 60 * 1e3;
3502
- const formatters = {
3503
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
3504
- X: function(date, token, options) {
3505
- const timezoneOffset = getTimeZoneOffset(options.timeZone, date);
3506
- if (timezoneOffset === 0) {
3507
- return "Z";
3508
- }
3509
- switch (token) {
3510
- // Hours and optional minutes
3511
- case "X":
3512
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
3513
- // Hours, minutes and optional seconds without `:` delimeter
3514
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
3515
- // so this token always has the same output as `XX`
3516
- case "XXXX":
3517
- case "XX":
3518
- return formatTimezone(timezoneOffset);
3519
- // Hours, minutes and optional seconds with `:` delimeter
3520
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
3521
- // so this token always has the same output as `XXX`
3522
- case "XXXXX":
3523
- case "XXX":
3524
- // Hours and minutes with `:` delimeter
3525
- default:
3526
- return formatTimezone(timezoneOffset, ":");
3527
- }
3528
- },
3529
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
3530
- x: function(date, token, options) {
3531
- const timezoneOffset = getTimeZoneOffset(options.timeZone, date);
3532
- switch (token) {
3533
- // Hours and optional minutes
3534
- case "x":
3535
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
3536
- // Hours, minutes and optional seconds without `:` delimeter
3537
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
3538
- // so this token always has the same output as `xx`
3539
- case "xxxx":
3540
- case "xx":
3541
- return formatTimezone(timezoneOffset);
3542
- // Hours, minutes and optional seconds with `:` delimeter
3543
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
3544
- // so this token always has the same output as `xxx`
3545
- case "xxxxx":
3546
- case "xxx":
3547
- // Hours and minutes with `:` delimeter
3548
- default:
3549
- return formatTimezone(timezoneOffset, ":");
3550
- }
3551
- },
3552
- // Timezone (GMT)
3553
- O: function(date, token, options) {
3554
- const timezoneOffset = getTimeZoneOffset(options.timeZone, date);
3555
- switch (token) {
3556
- // Short
3557
- case "O":
3558
- case "OO":
3559
- case "OOO":
3560
- return "GMT" + formatTimezoneShort(timezoneOffset, ":");
3561
- // Long
3562
- case "OOOO":
3563
- default:
3564
- return "GMT" + formatTimezone(timezoneOffset, ":");
3565
- }
3566
- },
3567
- // Timezone (specific non-location)
3568
- z: function(date, token, options) {
3569
- switch (token) {
3570
- // Short
3571
- case "z":
3572
- case "zz":
3573
- case "zzz":
3574
- return tzIntlTimeZoneName("short", date, options);
3575
- // Long
3576
- case "zzzz":
3577
- default:
3578
- return tzIntlTimeZoneName("long", date, options);
3579
- }
3580
- }
3581
- };
3582
- function getTimeZoneOffset(timeZone, originalDate) {
3583
- var _a;
3584
- const timeZoneOffset = timeZone ? tzParseTimezone(timeZone, originalDate, true) / MILLISECONDS_IN_MINUTE$1 : (_a = originalDate == null ? void 0 : originalDate.getTimezoneOffset()) != null ? _a : 0;
3585
- if (Number.isNaN(timeZoneOffset)) {
3586
- throw new RangeError("Invalid time zone specified: " + timeZone);
3587
- }
3588
- return timeZoneOffset;
3589
- }
3590
- function addLeadingZeros(number, targetLength) {
3591
- const sign = number < 0 ? "-" : "";
3592
- let output = Math.abs(number).toString();
3593
- while (output.length < targetLength) {
3594
- output = "0" + output;
3595
- }
3596
- return sign + output;
3597
- }
3598
- function formatTimezone(offset, delimiter = "") {
3599
- const sign = offset > 0 ? "-" : "+";
3600
- const absOffset = Math.abs(offset);
3601
- const hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
3602
- const minutes = addLeadingZeros(Math.floor(absOffset % 60), 2);
3603
- return sign + hours + delimiter + minutes;
3604
- }
3605
- function formatTimezoneWithOptionalMinutes(offset, delimiter) {
3606
- if (offset % 60 === 0) {
3607
- const sign = offset > 0 ? "-" : "+";
3608
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
3609
- }
3610
- return formatTimezone(offset, delimiter);
3611
- }
3612
- function formatTimezoneShort(offset, delimiter = "") {
3613
- const sign = offset > 0 ? "-" : "+";
3614
- const absOffset = Math.abs(offset);
3615
- const hours = Math.floor(absOffset / 60);
3616
- const minutes = absOffset % 60;
3617
- if (minutes === 0) {
3618
- return sign + String(hours);
3619
- }
3620
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
3621
- }
3622
- function getTimezoneOffsetInMilliseconds(date) {
3623
- const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
3624
- utcDate.setUTCFullYear(date.getFullYear());
3625
- return +date - +utcDate;
3626
- }
3627
- const tzPattern = /(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/;
3628
- const MILLISECONDS_IN_HOUR = 36e5;
3629
- const MILLISECONDS_IN_MINUTE = 6e4;
3630
- const DEFAULT_ADDITIONAL_DIGITS = 2;
3631
- const patterns = {
3632
- dateTimePattern: /^([0-9W+-]+)(T| )(.*)/,
3633
- datePattern: /^([0-9W+-]+)(.*)/,
3634
- // year tokens
3635
- YY: /^(\d{2})$/,
3636
- YYY: [
3637
- /^([+-]\d{2})$/,
3638
- // 0 additional digits
3639
- /^([+-]\d{3})$/,
3640
- // 1 additional digit
3641
- /^([+-]\d{4})$/
3642
- // 2 additional digits
3643
- ],
3644
- YYYY: /^(\d{4})/,
3645
- YYYYY: [
3646
- /^([+-]\d{4})/,
3647
- // 0 additional digits
3648
- /^([+-]\d{5})/,
3649
- // 1 additional digit
3650
- /^([+-]\d{6})/
3651
- // 2 additional digits
3652
- ],
3653
- // date tokens
3654
- MM: /^-(\d{2})$/,
3655
- DDD: /^-?(\d{3})$/,
3656
- MMDD: /^-?(\d{2})-?(\d{2})$/,
3657
- Www: /^-?W(\d{2})$/,
3658
- WwwD: /^-?W(\d{2})-?(\d{1})$/,
3659
- HH: /^(\d{2}([.,]\d*)?)$/,
3660
- HHMM: /^(\d{2}):?(\d{2}([.,]\d*)?)$/,
3661
- HHMMSS: /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,
3662
- // time zone tokens (to identify the presence of a tz)
3663
- timeZone: tzPattern
3664
- };
3665
- function toDate(argument, options = {}) {
3666
- if (arguments.length < 1) {
3667
- throw new TypeError("1 argument required, but only " + arguments.length + " present");
3668
- }
3669
- if (argument === null) {
3670
- return /* @__PURE__ */ new Date(NaN);
3671
- }
3672
- const additionalDigits = options.additionalDigits == null ? DEFAULT_ADDITIONAL_DIGITS : Number(options.additionalDigits);
3673
- if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
3674
- throw new RangeError("additionalDigits must be 0, 1 or 2");
3675
- }
3676
- if (argument instanceof Date || typeof argument === "object" && Object.prototype.toString.call(argument) === "[object Date]") {
3677
- return new Date(argument.getTime());
3678
- } else if (typeof argument === "number" || Object.prototype.toString.call(argument) === "[object Number]") {
3679
- return new Date(argument);
3680
- } else if (!(Object.prototype.toString.call(argument) === "[object String]")) {
3681
- return /* @__PURE__ */ new Date(NaN);
3682
- }
3683
- const dateStrings = splitDateString(argument);
3684
- const { year, restDateString } = parseYear(dateStrings.date, additionalDigits);
3685
- const date = parseDate(restDateString, year);
3686
- if (date === null || isNaN(date.getTime())) {
3687
- return /* @__PURE__ */ new Date(NaN);
3688
- }
3689
- if (date) {
3690
- const timestamp = date.getTime();
3691
- let time = 0;
3692
- let offset;
3693
- if (dateStrings.time) {
3694
- time = parseTime(dateStrings.time);
3695
- if (time === null || isNaN(time)) {
3696
- return /* @__PURE__ */ new Date(NaN);
3697
- }
3698
- }
3699
- if (dateStrings.timeZone || options.timeZone) {
3700
- offset = tzParseTimezone(dateStrings.timeZone || options.timeZone, new Date(timestamp + time));
3701
- if (isNaN(offset)) {
3702
- return /* @__PURE__ */ new Date(NaN);
3703
- }
3704
- } else {
3705
- offset = getTimezoneOffsetInMilliseconds(new Date(timestamp + time));
3706
- offset = getTimezoneOffsetInMilliseconds(new Date(timestamp + time + offset));
3707
- }
3708
- return new Date(timestamp + time + offset);
3709
- } else {
3710
- return /* @__PURE__ */ new Date(NaN);
3711
- }
3712
- }
3713
- function splitDateString(dateString) {
3714
- const dateStrings = {};
3715
- let parts = patterns.dateTimePattern.exec(dateString);
3716
- let timeString;
3717
- if (!parts) {
3718
- parts = patterns.datePattern.exec(dateString);
3719
- if (parts) {
3720
- dateStrings.date = parts[1];
3721
- timeString = parts[2];
3722
- } else {
3723
- dateStrings.date = null;
3724
- timeString = dateString;
3725
- }
3726
- } else {
3727
- dateStrings.date = parts[1];
3728
- timeString = parts[3];
3729
- }
3730
- if (timeString) {
3731
- const token = patterns.timeZone.exec(timeString);
3732
- if (token) {
3733
- dateStrings.time = timeString.replace(token[1], "");
3734
- dateStrings.timeZone = token[1].trim();
3735
- } else {
3736
- dateStrings.time = timeString;
3737
- }
3738
- }
3739
- return dateStrings;
3740
- }
3741
- function parseYear(dateString, additionalDigits) {
3742
- if (dateString) {
3743
- const patternYYY = patterns.YYY[additionalDigits];
3744
- const patternYYYYY = patterns.YYYYY[additionalDigits];
3745
- let token = patterns.YYYY.exec(dateString) || patternYYYYY.exec(dateString);
3746
- if (token) {
3747
- const yearString = token[1];
3748
- return {
3749
- year: parseInt(yearString, 10),
3750
- restDateString: dateString.slice(yearString.length)
3751
- };
3752
- }
3753
- token = patterns.YY.exec(dateString) || patternYYY.exec(dateString);
3754
- if (token) {
3755
- const centuryString = token[1];
3756
- return {
3757
- year: parseInt(centuryString, 10) * 100,
3758
- restDateString: dateString.slice(centuryString.length)
3759
- };
3760
- }
3761
- }
3762
- return {
3763
- year: null
3764
- };
3765
- }
3766
- function parseDate(dateString, year) {
3767
- if (year === null) {
3768
- return null;
3769
- }
3770
- let date;
3771
- let month;
3772
- let week;
3773
- if (!dateString || !dateString.length) {
3774
- date = /* @__PURE__ */ new Date(0);
3775
- date.setUTCFullYear(year);
3776
- return date;
3777
- }
3778
- let token = patterns.MM.exec(dateString);
3779
- if (token) {
3780
- date = /* @__PURE__ */ new Date(0);
3781
- month = parseInt(token[1], 10) - 1;
3782
- if (!validateDate(year, month)) {
3783
- return /* @__PURE__ */ new Date(NaN);
3784
- }
3785
- date.setUTCFullYear(year, month);
3786
- return date;
3787
- }
3788
- token = patterns.DDD.exec(dateString);
3789
- if (token) {
3790
- date = /* @__PURE__ */ new Date(0);
3791
- const dayOfYear = parseInt(token[1], 10);
3792
- if (!validateDayOfYearDate(year, dayOfYear)) {
3793
- return /* @__PURE__ */ new Date(NaN);
3794
- }
3795
- date.setUTCFullYear(year, 0, dayOfYear);
3796
- return date;
3797
- }
3798
- token = patterns.MMDD.exec(dateString);
3799
- if (token) {
3800
- date = /* @__PURE__ */ new Date(0);
3801
- month = parseInt(token[1], 10) - 1;
3802
- const day = parseInt(token[2], 10);
3803
- if (!validateDate(year, month, day)) {
3804
- return /* @__PURE__ */ new Date(NaN);
3805
- }
3806
- date.setUTCFullYear(year, month, day);
3807
- return date;
3808
- }
3809
- token = patterns.Www.exec(dateString);
3810
- if (token) {
3811
- week = parseInt(token[1], 10) - 1;
3812
- if (!validateWeekDate(week)) {
3813
- return /* @__PURE__ */ new Date(NaN);
3814
- }
3815
- return dayOfISOWeekYear(year, week);
3816
- }
3817
- token = patterns.WwwD.exec(dateString);
3818
- if (token) {
3819
- week = parseInt(token[1], 10) - 1;
3820
- const dayOfWeek = parseInt(token[2], 10) - 1;
3821
- if (!validateWeekDate(week, dayOfWeek)) {
3822
- return /* @__PURE__ */ new Date(NaN);
3823
- }
3824
- return dayOfISOWeekYear(year, week, dayOfWeek);
3825
- }
3826
- return null;
3827
- }
3828
- function parseTime(timeString) {
3829
- let hours;
3830
- let minutes;
3831
- let token = patterns.HH.exec(timeString);
3832
- if (token) {
3833
- hours = parseFloat(token[1].replace(",", "."));
3834
- if (!validateTime(hours)) {
3835
- return NaN;
3836
- }
3837
- return hours % 24 * MILLISECONDS_IN_HOUR;
3838
- }
3839
- token = patterns.HHMM.exec(timeString);
3840
- if (token) {
3841
- hours = parseInt(token[1], 10);
3842
- minutes = parseFloat(token[2].replace(",", "."));
3843
- if (!validateTime(hours, minutes)) {
3844
- return NaN;
3845
- }
3846
- return hours % 24 * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE;
3847
- }
3848
- token = patterns.HHMMSS.exec(timeString);
3849
- if (token) {
3850
- hours = parseInt(token[1], 10);
3851
- minutes = parseInt(token[2], 10);
3852
- const seconds = parseFloat(token[3].replace(",", "."));
3853
- if (!validateTime(hours, minutes, seconds)) {
3854
- return NaN;
3855
- }
3856
- return hours % 24 * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE + seconds * 1e3;
3857
- }
3858
- return null;
3859
- }
3860
- function dayOfISOWeekYear(isoWeekYear, week, day) {
3861
- week = week || 0;
3862
- day = day || 0;
3863
- const date = /* @__PURE__ */ new Date(0);
3864
- date.setUTCFullYear(isoWeekYear, 0, 4);
3865
- const fourthOfJanuaryDay = date.getUTCDay() || 7;
3866
- const diff = week * 7 + day + 1 - fourthOfJanuaryDay;
3867
- date.setUTCDate(date.getUTCDate() + diff);
3868
- return date;
3869
- }
3870
- const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3871
- const DAYS_IN_MONTH_LEAP_YEAR = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3872
- function isLeapYearIndex(year) {
3873
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
3874
- }
3875
- function validateDate(year, month, date) {
3876
- if (month < 0 || month > 11) {
3877
- return false;
3878
- }
3879
- if (date != null) {
3880
- if (date < 1) {
3881
- return false;
3882
- }
3883
- const isLeapYear = isLeapYearIndex(year);
3884
- if (isLeapYear && date > DAYS_IN_MONTH_LEAP_YEAR[month]) {
3885
- return false;
3886
- }
3887
- if (!isLeapYear && date > DAYS_IN_MONTH[month]) {
3888
- return false;
3889
- }
3890
- }
3891
- return true;
3892
- }
3893
- function validateDayOfYearDate(year, dayOfYear) {
3894
- if (dayOfYear < 1) {
3895
- return false;
3896
- }
3897
- const isLeapYear = isLeapYearIndex(year);
3898
- if (isLeapYear && dayOfYear > 366) {
3899
- return false;
3900
- }
3901
- if (!isLeapYear && dayOfYear > 365) {
3902
- return false;
3903
- }
3904
- return true;
3905
- }
3906
- function validateWeekDate(week, day) {
3907
- if (week < 0 || week > 52) {
3908
- return false;
3909
- }
3910
- if (day != null && (day < 0 || day > 6)) {
3911
- return false;
3912
- }
3913
- return true;
3914
- }
3915
- function validateTime(hours, minutes, seconds) {
3916
- if (hours < 0 || hours >= 25) {
3917
- return false;
3918
- }
3919
- if (minutes != null && (minutes < 0 || minutes >= 60)) {
3920
- return false;
3921
- }
3922
- if (seconds != null && (seconds < 0 || seconds >= 60)) {
3923
- return false;
3924
- }
3925
- return true;
3926
- }
3927
- const tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g;
3928
- function format(date, formatStr, options = {}) {
3929
- formatStr = String(formatStr);
3930
- const matches = formatStr.match(tzFormattingTokensRegExp);
3931
- if (matches) {
3932
- const d = toDate(options.originalDate || date, options);
3933
- formatStr = matches.reduce(function(result, token) {
3934
- if (token[0] === "'") {
3935
- return result;
3936
- }
3937
- const pos = result.indexOf(token);
3938
- const precededByQuotedSection = result[pos - 1] === "'";
3939
- const replaced = result.replace(token, "'" + formatters[token[0]](d, token, options) + "'");
3940
- return precededByQuotedSection ? replaced.substring(0, pos - 1) + replaced.substring(pos + 1) : replaced;
3941
- }, formatStr);
3942
- }
3943
- return format$1(date, formatStr, options);
3944
- }
3945
- function toZonedTime(date, timeZone, options) {
3946
- date = toDate(date, options);
3947
- const offsetMilliseconds = tzParseTimezone(timeZone, date, true);
3948
- const d = new Date(date.getTime() - offsetMilliseconds);
3949
- const resultDate = /* @__PURE__ */ new Date(0);
3950
- resultDate.setFullYear(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
3951
- resultDate.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
3952
- return resultDate;
3953
- }
3954
- function fromZonedTime(date, timeZone, options) {
3955
- if (typeof date === "string" && !date.match(tzPattern)) {
3956
- return toDate(date, __spreadProps(__spreadValues({}, options), { timeZone }));
3957
- }
3958
- date = toDate(date, options);
3959
- const utc = newDateUTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()).getTime();
3960
- const offsetMilliseconds = tzParseTimezone(timeZone, new Date(utc));
3961
- return new Date(utc + offsetMilliseconds);
3962
- }
3963
58
  const base64Decode = (encodedData) => {
3964
59
  try {
3965
60
  return atob(encodedData);
@@ -4138,14 +233,13 @@ const convertToUserTimeZone = (dateTime) => {
4138
233
  try {
4139
234
  const { timezone } = getConfig();
4140
235
  const originalTimeZone = `Etc/GMT${timezone > 0 ? `-${timezone}` : `+${Math.abs(timezone)}`}`;
4141
- const parsedDate = parse(dateTime, "yyyy-MM-dd HH:mm:ss", /* @__PURE__ */ new Date());
236
+ const userTimeZone = currentTimeZone();
237
+ const parsedDate = parseDate(dateTime);
4142
238
  if (isNaN(parsedDate.getTime())) {
4143
239
  throw new Error("Invalid date format");
4144
240
  }
4145
- const utcDate = fromZonedTime(parsedDate, originalTimeZone);
4146
- const userTimeZone = currentTimeZone();
4147
- const userZonedTime = toZonedTime(utcDate, userTimeZone);
4148
- return format(userZonedTime, "yyyy-MM-dd HH:mm:ss", { timeZone: userTimeZone });
241
+ const convertedDate = timeConversion(parsedDate, originalTimeZone, userTimeZone);
242
+ return timeFormat(convertedDate);
4149
243
  } catch (error) {
4150
244
  console.error("Error converting to user timezone:", error);
4151
245
  throw error;
@@ -4230,6 +324,78 @@ const getImgPath = (initPath, gameId, versioning) => {
4230
324
  }
4231
325
  return path;
4232
326
  };
327
+ const getUtcOffset = (timeZone) => {
328
+ const formatter = new Intl.DateTimeFormat("en-US", {
329
+ timeZone,
330
+ timeZoneName: "shortOffset"
331
+ });
332
+ const parts = formatter.formatToParts(/* @__PURE__ */ new Date());
333
+ const offsetPart = parts.find((p) => p.type === "timeZoneName");
334
+ return offsetPart ? offsetPart.value : "";
335
+ };
336
+ const parseGmtOffset = (gmtString) => {
337
+ const match = gmtString.match(/^GMT([+-]\d{1,2})$/);
338
+ if (!match) throw new Error("Invalid GMT string: " + gmtString);
339
+ return parseInt(match[1], 10);
340
+ };
341
+ const compareGmt = (a, b) => {
342
+ const offsetA = parseGmtOffset(a);
343
+ const offsetB = parseGmtOffset(b);
344
+ return offsetB - offsetA;
345
+ };
346
+ const parseDate = (dateStr, format = "yyyy-MM-dd HH:mm:ss") => {
347
+ var _a, _b, _c, _d, _e, _f;
348
+ const tokenMap = {
349
+ yyyy: "(\\d{4})",
350
+ MM: "(\\d{2})",
351
+ dd: "(\\d{2})",
352
+ HH: "(\\d{2})",
353
+ mm: "(\\d{2})",
354
+ ss: "(\\d{2})"
355
+ };
356
+ const tokens = [];
357
+ const regex = new RegExp(
358
+ `^${format.replace(/(yyyy|MM|dd|HH|mm|ss)|[^A-Za-z0-9]/g, (m) => {
359
+ if (tokenMap[m]) {
360
+ tokens.push(m);
361
+ return tokenMap[m];
362
+ }
363
+ return "\\" + m;
364
+ })}$`
365
+ );
366
+ const match = dateStr.match(regex);
367
+ if (!match) throw new Error(`Date string does not match format: ${format}`);
368
+ const parts = {};
369
+ tokens.forEach((t, i) => parts[t] = +match[i + 1]);
370
+ return new Date(
371
+ (_a = parts.yyyy) != null ? _a : 1970,
372
+ ((_b = parts.MM) != null ? _b : 1) - 1,
373
+ (_c = parts.dd) != null ? _c : 1,
374
+ (_d = parts.HH) != null ? _d : 0,
375
+ (_e = parts.mm) != null ? _e : 0,
376
+ (_f = parts.ss) != null ? _f : 0
377
+ );
378
+ };
379
+ const timeFormat = (date, format = "yyyy-MM-dd HH:mm:ss") => {
380
+ const parts = new Intl.DateTimeFormat("en-US", {
381
+ year: "numeric",
382
+ month: "2-digit",
383
+ day: "2-digit",
384
+ hour: "2-digit",
385
+ minute: "2-digit",
386
+ second: "2-digit",
387
+ hour12: false
388
+ }).formatToParts(date);
389
+ const lookup = {};
390
+ for (const p of parts) {
391
+ if (p.type !== "literal") lookup[p.type] = p.value;
392
+ }
393
+ return format.replace("yyyy", lookup.year).replace("MM", lookup.month).replace("dd", lookup.day).replace("HH", lookup.hour).replace("mm", lookup.minute).replace("ss", lookup.second);
394
+ };
395
+ const timeConversion = (date, fromTimeZone, toTimeZone) => {
396
+ const tzDifference = compareGmt(getUtcOffset(fromTimeZone), getUtcOffset(toTimeZone));
397
+ return new Date(date.getTime() + tzDifference * 60 * 60 * 1e3);
398
+ };
4233
399
  class DefaultApiModelRegistry {
4234
400
  constructor() {
4235
401
  __publicField(this, "models", /* @__PURE__ */ new Map());
@@ -4521,6 +687,7 @@ var Api = /* @__PURE__ */ ((Api2) => {
4521
687
  Api2["agMemberTransaction"] = "agMemberTransaction";
4522
688
  Api2["submitTacCode"] = "submitTacCode";
4523
689
  Api2["updateRegister"] = "updateRegister";
690
+ Api2["getAppSetting"] = "getAppSetting";
4524
691
  return Api2;
4525
692
  })(Api || {});
4526
693
  const modifyGameListRequest = (requests) => {
@@ -5358,6 +1525,8 @@ var SettingCategory = /* @__PURE__ */ ((SettingCategory2) => {
5358
1525
  SettingCategory2["socialFirebaseAppId"] = "social_firebase_appid";
5359
1526
  SettingCategory2["userDetailMobileValidation"] = "userdetailmobilevalidation";
5360
1527
  SettingCategory2["allLiveChats"] = "alllivechats";
1528
+ SettingCategory2["socialGoogleLoginStatus"] = "social_google_login_status";
1529
+ SettingCategory2["socialFacebookLoginStatus"] = "social_facebook_login_status";
5361
1530
  return SettingCategory2;
5362
1531
  })(SettingCategory || {});
5363
1532
  const modifyVipListRequest = (requests) => {
@@ -5866,8 +2035,8 @@ const getGetSettingResponse = (raw) => {
5866
2035
  email: (_d = (_c = raw.forgetuser) == null ? void 0 : _c.email) != null ? _d : false,
5867
2036
  sms: (_f = (_e = raw.forgetuser) == null ? void 0 : _e.sms) != null ? _f : false
5868
2037
  },
5869
- loginCaptcha: raw.logincaptcha ? raw.logincaptcha === "1" : false,
5870
- registerCaptcha: raw.registercaptcha ? raw.registercaptcha === "1" : false,
2038
+ loginCaptcha: raw.logincaptcha === "1" || false,
2039
+ registerCaptcha: raw.registercaptcha === "1" || false,
5871
2040
  telegramAuthDomain: (_g = raw.telegramauthdomain) != null ? _g : "",
5872
2041
  telegramBotId: (_h = raw.telegrambotid) != null ? _h : "",
5873
2042
  whatsappRegister: (_i = raw.registerwa) != null ? _i : "",
@@ -5886,14 +2055,16 @@ const getGetSettingResponse = (raw) => {
5886
2055
  socialFirebaseApikey: (_z = raw.social_firebase_apikey) != null ? _z : "",
5887
2056
  socialFirebaseProjectId: (_A = raw.social_firebase_projectid) != null ? _A : "",
5888
2057
  socialFirebaseAppId: (_B = raw.social_firebase_appid) != null ? _B : "",
5889
- userDetailMobileValidation: raw.userdetailmobilevalidation ? raw.userdetailmobilevalidation === "1" : false,
2058
+ userDetailMobileValidation: raw.userdetailmobilevalidation === "1" || false,
5890
2059
  liveChatList: (_D = (_C = raw.alllivechats) == null ? void 0 : _C.map((item) => {
5891
2060
  var _a2, _b2;
5892
2061
  return {
5893
2062
  name: (_a2 = item.name) != null ? _a2 : "",
5894
2063
  url: (_b2 = item.url) != null ? _b2 : ""
5895
2064
  };
5896
- })) != null ? _D : []
2065
+ })) != null ? _D : [],
2066
+ socialFacebookLoginStatus: raw.social_facebook_login_status == "1" || false,
2067
+ socialGoogleLoginStatus: raw.social_google_login_status == "1" || false
5897
2068
  };
5898
2069
  };
5899
2070
  const modifyGetSettingRequest = (requests) => {
@@ -10412,8 +6583,8 @@ const authHeaders = () => {
10412
6583
  }, token ? { Authorization: `Bearer ${token}` } : {});
10413
6584
  };
10414
6585
  const getCookie = (name) => {
10415
- const match2 = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
10416
- return match2 ? decodeURIComponent(match2[2]) : "";
6586
+ const match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
6587
+ return match ? decodeURIComponent(match[2]) : "";
10417
6588
  };
10418
6589
  const safeJson = (response) => __async(void 0, null, function* () {
10419
6590
  try {