@wikicasa-dev/utilities 1.0.15 → 1.0.18

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.
package/dist/DateUtils.js CHANGED
@@ -1,7 +1,1221 @@
1
- function s(e, o = !1) {
2
- const t = e.getDate(), c = e.getMonth() + 1, n = e.getFullYear();
3
- return o ? `${("0" + t).slice(-2)}-${("0" + c).slice(-2)}-${n}` : `${n}-${("0" + c).slice(-2)}-${("0" + t).slice(-2)}`;
1
+ function f(t) {
2
+ const e = Object.prototype.toString.call(t);
3
+ return t instanceof Date || typeof t == "object" && e === "[object Date]" ? new t.constructor(+t) : typeof t == "number" || e === "[object Number]" || typeof t == "string" || e === "[object String]" ? new Date(t) : /* @__PURE__ */ new Date(NaN);
4
4
  }
5
+ function g(t, e) {
6
+ return t instanceof Date ? new t.constructor(e) : new Date(e);
7
+ }
8
+ function H(t, e) {
9
+ const n = f(t);
10
+ return isNaN(e) ? g(t, NaN) : (e && n.setDate(n.getDate() + e), n);
11
+ }
12
+ const E = 6048e5, Q = 864e5;
13
+ let X = {};
14
+ function O() {
15
+ return X;
16
+ }
17
+ function M(t, e) {
18
+ const n = O(), r = e?.weekStartsOn ?? e?.locale?.options?.weekStartsOn ?? n.weekStartsOn ?? n.locale?.options?.weekStartsOn ?? 0, a = f(t), o = a.getDay(), s = (o < r ? 7 : 0) + o - r;
19
+ return a.setDate(a.getDate() - s), a.setHours(0, 0, 0, 0), a;
20
+ }
21
+ function P(t) {
22
+ return M(t, { weekStartsOn: 1 });
23
+ }
24
+ function N(t) {
25
+ const e = f(t), n = e.getFullYear(), r = g(t, 0);
26
+ r.setFullYear(n + 1, 0, 4), r.setHours(0, 0, 0, 0);
27
+ const a = P(r), o = g(t, 0);
28
+ o.setFullYear(n, 0, 4), o.setHours(0, 0, 0, 0);
29
+ const s = P(o);
30
+ return e.getTime() >= a.getTime() ? n + 1 : e.getTime() >= s.getTime() ? n : n - 1;
31
+ }
32
+ function x(t) {
33
+ const e = f(t);
34
+ return e.setHours(0, 0, 0, 0), e;
35
+ }
36
+ function v(t) {
37
+ const e = f(t), n = new Date(
38
+ Date.UTC(
39
+ e.getFullYear(),
40
+ e.getMonth(),
41
+ e.getDate(),
42
+ e.getHours(),
43
+ e.getMinutes(),
44
+ e.getSeconds(),
45
+ e.getMilliseconds()
46
+ )
47
+ );
48
+ return n.setUTCFullYear(e.getFullYear()), +t - +n;
49
+ }
50
+ function _(t, e) {
51
+ const n = x(t), r = x(e), a = +n - v(n), o = +r - v(r);
52
+ return Math.round((a - o) / Q);
53
+ }
54
+ function j(t) {
55
+ const e = N(t), n = g(t, 0);
56
+ return n.setFullYear(e, 0, 4), n.setHours(0, 0, 0, 0), P(n);
57
+ }
58
+ function L(t) {
59
+ return t instanceof Date || typeof t == "object" && Object.prototype.toString.call(t) === "[object Date]";
60
+ }
61
+ function G(t) {
62
+ if (!L(t) && typeof t != "number")
63
+ return !1;
64
+ const e = f(t);
65
+ return !isNaN(Number(e));
66
+ }
67
+ function R(t) {
68
+ const e = f(t), n = g(t, 0);
69
+ return n.setFullYear(e.getFullYear(), 0, 1), n.setHours(0, 0, 0, 0), n;
70
+ }
71
+ const B = {
72
+ lessThanXSeconds: {
73
+ one: "less than a second",
74
+ other: "less than {{count}} seconds"
75
+ },
76
+ xSeconds: {
77
+ one: "1 second",
78
+ other: "{{count}} seconds"
79
+ },
80
+ halfAMinute: "half a minute",
81
+ lessThanXMinutes: {
82
+ one: "less than a minute",
83
+ other: "less than {{count}} minutes"
84
+ },
85
+ xMinutes: {
86
+ one: "1 minute",
87
+ other: "{{count}} minutes"
88
+ },
89
+ aboutXHours: {
90
+ one: "about 1 hour",
91
+ other: "about {{count}} hours"
92
+ },
93
+ xHours: {
94
+ one: "1 hour",
95
+ other: "{{count}} hours"
96
+ },
97
+ xDays: {
98
+ one: "1 day",
99
+ other: "{{count}} days"
100
+ },
101
+ aboutXWeeks: {
102
+ one: "about 1 week",
103
+ other: "about {{count}} weeks"
104
+ },
105
+ xWeeks: {
106
+ one: "1 week",
107
+ other: "{{count}} weeks"
108
+ },
109
+ aboutXMonths: {
110
+ one: "about 1 month",
111
+ other: "about {{count}} months"
112
+ },
113
+ xMonths: {
114
+ one: "1 month",
115
+ other: "{{count}} months"
116
+ },
117
+ aboutXYears: {
118
+ one: "about 1 year",
119
+ other: "about {{count}} years"
120
+ },
121
+ xYears: {
122
+ one: "1 year",
123
+ other: "{{count}} years"
124
+ },
125
+ overXYears: {
126
+ one: "over 1 year",
127
+ other: "over {{count}} years"
128
+ },
129
+ almostXYears: {
130
+ one: "almost 1 year",
131
+ other: "almost {{count}} years"
132
+ }
133
+ }, A = (t, e, n) => {
134
+ let r;
135
+ const a = B[t];
136
+ return typeof a == "string" ? r = a : e === 1 ? r = a.one : r = a.other.replace("{{count}}", e.toString()), n?.addSuffix ? n.comparison && n.comparison > 0 ? "in " + r : r + " ago" : r;
137
+ };
138
+ function k(t) {
139
+ return (e = {}) => {
140
+ const n = e.width ? String(e.width) : t.defaultWidth;
141
+ return t.formats[n] || t.formats[t.defaultWidth];
142
+ };
143
+ }
144
+ const V = {
145
+ full: "EEEE, MMMM do, y",
146
+ long: "MMMM do, y",
147
+ medium: "MMM d, y",
148
+ short: "MM/dd/yyyy"
149
+ }, $ = {
150
+ full: "h:mm:ss a zzzz",
151
+ long: "h:mm:ss a z",
152
+ medium: "h:mm:ss a",
153
+ short: "h:mm a"
154
+ }, I = {
155
+ full: "{{date}} 'at' {{time}}",
156
+ long: "{{date}} 'at' {{time}}",
157
+ medium: "{{date}}, {{time}}",
158
+ short: "{{date}}, {{time}}"
159
+ }, J = {
160
+ date: k({
161
+ formats: V,
162
+ defaultWidth: "full"
163
+ }),
164
+ time: k({
165
+ formats: $,
166
+ defaultWidth: "full"
167
+ }),
168
+ dateTime: k({
169
+ formats: I,
170
+ defaultWidth: "full"
171
+ })
172
+ }, U = {
173
+ lastWeek: "'last' eeee 'at' p",
174
+ yesterday: "'yesterday at' p",
175
+ today: "'today at' p",
176
+ tomorrow: "'tomorrow at' p",
177
+ nextWeek: "eeee 'at' p",
178
+ other: "P"
179
+ }, z = (t, e, n, r) => U[t];
180
+ function b(t) {
181
+ return (e, n) => {
182
+ const r = n?.context ? String(n.context) : "standalone";
183
+ let a;
184
+ if (r === "formatting" && t.formattingValues) {
185
+ const s = t.defaultFormattingWidth || t.defaultWidth, c = n?.width ? String(n.width) : s;
186
+ a = t.formattingValues[c] || t.formattingValues[s];
187
+ } else {
188
+ const s = t.defaultWidth, c = n?.width ? String(n.width) : t.defaultWidth;
189
+ a = t.values[c] || t.values[s];
190
+ }
191
+ const o = t.argumentCallback ? t.argumentCallback(e) : e;
192
+ return a[o];
193
+ };
194
+ }
195
+ const K = {
196
+ narrow: ["B", "A"],
197
+ abbreviated: ["BC", "AD"],
198
+ wide: ["Before Christ", "Anno Domini"]
199
+ }, Z = {
200
+ narrow: ["1", "2", "3", "4"],
201
+ abbreviated: ["Q1", "Q2", "Q3", "Q4"],
202
+ wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
203
+ }, tt = {
204
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
205
+ abbreviated: [
206
+ "Jan",
207
+ "Feb",
208
+ "Mar",
209
+ "Apr",
210
+ "May",
211
+ "Jun",
212
+ "Jul",
213
+ "Aug",
214
+ "Sep",
215
+ "Oct",
216
+ "Nov",
217
+ "Dec"
218
+ ],
219
+ wide: [
220
+ "January",
221
+ "February",
222
+ "March",
223
+ "April",
224
+ "May",
225
+ "June",
226
+ "July",
227
+ "August",
228
+ "September",
229
+ "October",
230
+ "November",
231
+ "December"
232
+ ]
233
+ }, et = {
234
+ narrow: ["S", "M", "T", "W", "T", "F", "S"],
235
+ short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
236
+ abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
237
+ wide: [
238
+ "Sunday",
239
+ "Monday",
240
+ "Tuesday",
241
+ "Wednesday",
242
+ "Thursday",
243
+ "Friday",
244
+ "Saturday"
245
+ ]
246
+ }, nt = {
247
+ narrow: {
248
+ am: "a",
249
+ pm: "p",
250
+ midnight: "mi",
251
+ noon: "n",
252
+ morning: "morning",
253
+ afternoon: "afternoon",
254
+ evening: "evening",
255
+ night: "night"
256
+ },
257
+ abbreviated: {
258
+ am: "AM",
259
+ pm: "PM",
260
+ midnight: "midnight",
261
+ noon: "noon",
262
+ morning: "morning",
263
+ afternoon: "afternoon",
264
+ evening: "evening",
265
+ night: "night"
266
+ },
267
+ wide: {
268
+ am: "a.m.",
269
+ pm: "p.m.",
270
+ midnight: "midnight",
271
+ noon: "noon",
272
+ morning: "morning",
273
+ afternoon: "afternoon",
274
+ evening: "evening",
275
+ night: "night"
276
+ }
277
+ }, rt = {
278
+ narrow: {
279
+ am: "a",
280
+ pm: "p",
281
+ midnight: "mi",
282
+ noon: "n",
283
+ morning: "in the morning",
284
+ afternoon: "in the afternoon",
285
+ evening: "in the evening",
286
+ night: "at night"
287
+ },
288
+ abbreviated: {
289
+ am: "AM",
290
+ pm: "PM",
291
+ midnight: "midnight",
292
+ noon: "noon",
293
+ morning: "in the morning",
294
+ afternoon: "in the afternoon",
295
+ evening: "in the evening",
296
+ night: "at night"
297
+ },
298
+ wide: {
299
+ am: "a.m.",
300
+ pm: "p.m.",
301
+ midnight: "midnight",
302
+ noon: "noon",
303
+ morning: "in the morning",
304
+ afternoon: "in the afternoon",
305
+ evening: "in the evening",
306
+ night: "at night"
307
+ }
308
+ }, at = (t, e) => {
309
+ const n = Number(t), r = n % 100;
310
+ if (r > 20 || r < 10)
311
+ switch (r % 10) {
312
+ case 1:
313
+ return n + "st";
314
+ case 2:
315
+ return n + "nd";
316
+ case 3:
317
+ return n + "rd";
318
+ }
319
+ return n + "th";
320
+ }, ot = {
321
+ ordinalNumber: at,
322
+ era: b({
323
+ values: K,
324
+ defaultWidth: "wide"
325
+ }),
326
+ quarter: b({
327
+ values: Z,
328
+ defaultWidth: "wide",
329
+ argumentCallback: (t) => t - 1
330
+ }),
331
+ month: b({
332
+ values: tt,
333
+ defaultWidth: "wide"
334
+ }),
335
+ day: b({
336
+ values: et,
337
+ defaultWidth: "wide"
338
+ }),
339
+ dayPeriod: b({
340
+ values: nt,
341
+ defaultWidth: "wide",
342
+ formattingValues: rt,
343
+ defaultFormattingWidth: "wide"
344
+ })
345
+ };
346
+ function p(t) {
347
+ return (e, n = {}) => {
348
+ const r = n.width, a = r && t.matchPatterns[r] || t.matchPatterns[t.defaultMatchWidth], o = e.match(a);
349
+ if (!o)
350
+ return null;
351
+ const s = o[0], c = r && t.parsePatterns[r] || t.parsePatterns[t.defaultParseWidth], h = Array.isArray(c) ? st(c, (u) => u.test(s)) : (
352
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
353
+ it(c, (u) => u.test(s))
354
+ );
355
+ let m;
356
+ m = t.valueCallback ? t.valueCallback(h) : h, m = n.valueCallback ? (
357
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
358
+ n.valueCallback(m)
359
+ ) : m;
360
+ const d = e.slice(s.length);
361
+ return { value: m, rest: d };
362
+ };
363
+ }
364
+ function it(t, e) {
365
+ for (const n in t)
366
+ if (Object.prototype.hasOwnProperty.call(t, n) && e(t[n]))
367
+ return n;
368
+ }
369
+ function st(t, e) {
370
+ for (let n = 0; n < t.length; n++)
371
+ if (e(t[n]))
372
+ return n;
373
+ }
374
+ function ut(t) {
375
+ return (e, n = {}) => {
376
+ const r = e.match(t.matchPattern);
377
+ if (!r)
378
+ return null;
379
+ const a = r[0], o = e.match(t.parsePattern);
380
+ if (!o)
381
+ return null;
382
+ let s = t.valueCallback ? t.valueCallback(o[0]) : o[0];
383
+ s = n.valueCallback ? n.valueCallback(s) : s;
384
+ const c = e.slice(a.length);
385
+ return { value: s, rest: c };
386
+ };
387
+ }
388
+ const ct = /^(\d+)(th|st|nd|rd)?/i, dt = /\d+/i, ft = {
389
+ narrow: /^(b|a)/i,
390
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
391
+ wide: /^(before christ|before common era|anno domini|common era)/i
392
+ }, ht = {
393
+ any: [/^b/i, /^(a|c)/i]
394
+ }, mt = {
395
+ narrow: /^[1234]/i,
396
+ abbreviated: /^q[1234]/i,
397
+ wide: /^[1234](th|st|nd|rd)? quarter/i
398
+ }, lt = {
399
+ any: [/1/i, /2/i, /3/i, /4/i]
400
+ }, gt = {
401
+ narrow: /^[jfmasond]/i,
402
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
403
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
404
+ }, wt = {
405
+ narrow: [
406
+ /^j/i,
407
+ /^f/i,
408
+ /^m/i,
409
+ /^a/i,
410
+ /^m/i,
411
+ /^j/i,
412
+ /^j/i,
413
+ /^a/i,
414
+ /^s/i,
415
+ /^o/i,
416
+ /^n/i,
417
+ /^d/i
418
+ ],
419
+ any: [
420
+ /^ja/i,
421
+ /^f/i,
422
+ /^mar/i,
423
+ /^ap/i,
424
+ /^may/i,
425
+ /^jun/i,
426
+ /^jul/i,
427
+ /^au/i,
428
+ /^s/i,
429
+ /^o/i,
430
+ /^n/i,
431
+ /^d/i
432
+ ]
433
+ }, yt = {
434
+ narrow: /^[smtwf]/i,
435
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
436
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
437
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
438
+ }, bt = {
439
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
440
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
441
+ }, pt = {
442
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
443
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
444
+ }, Mt = {
445
+ any: {
446
+ am: /^a/i,
447
+ pm: /^p/i,
448
+ midnight: /^mi/i,
449
+ noon: /^no/i,
450
+ morning: /morning/i,
451
+ afternoon: /afternoon/i,
452
+ evening: /evening/i,
453
+ night: /night/i
454
+ }
455
+ }, Pt = {
456
+ ordinalNumber: ut({
457
+ matchPattern: ct,
458
+ parsePattern: dt,
459
+ valueCallback: (t) => parseInt(t, 10)
460
+ }),
461
+ era: p({
462
+ matchPatterns: ft,
463
+ defaultMatchWidth: "wide",
464
+ parsePatterns: ht,
465
+ defaultParseWidth: "any"
466
+ }),
467
+ quarter: p({
468
+ matchPatterns: mt,
469
+ defaultMatchWidth: "wide",
470
+ parsePatterns: lt,
471
+ defaultParseWidth: "any",
472
+ valueCallback: (t) => t + 1
473
+ }),
474
+ month: p({
475
+ matchPatterns: gt,
476
+ defaultMatchWidth: "wide",
477
+ parsePatterns: wt,
478
+ defaultParseWidth: "any"
479
+ }),
480
+ day: p({
481
+ matchPatterns: yt,
482
+ defaultMatchWidth: "wide",
483
+ parsePatterns: bt,
484
+ defaultParseWidth: "any"
485
+ }),
486
+ dayPeriod: p({
487
+ matchPatterns: pt,
488
+ defaultMatchWidth: "any",
489
+ parsePatterns: Mt,
490
+ defaultParseWidth: "any"
491
+ })
492
+ }, Ot = {
493
+ code: "en-US",
494
+ formatDistance: A,
495
+ formatLong: J,
496
+ formatRelative: z,
497
+ localize: ot,
498
+ match: Pt,
499
+ options: {
500
+ weekStartsOn: 0,
501
+ firstWeekContainsDate: 1
502
+ }
503
+ };
504
+ function Dt(t) {
505
+ const e = f(t);
506
+ return _(e, R(e)) + 1;
507
+ }
508
+ function kt(t) {
509
+ const e = f(t), n = +P(e) - +j(e);
510
+ return Math.round(n / E) + 1;
511
+ }
512
+ function C(t, e) {
513
+ const n = f(t), r = n.getFullYear(), a = O(), o = e?.firstWeekContainsDate ?? e?.locale?.options?.firstWeekContainsDate ?? a.firstWeekContainsDate ?? a.locale?.options?.firstWeekContainsDate ?? 1, s = g(t, 0);
514
+ s.setFullYear(r + 1, 0, o), s.setHours(0, 0, 0, 0);
515
+ const c = M(s, e), h = g(t, 0);
516
+ h.setFullYear(r, 0, o), h.setHours(0, 0, 0, 0);
517
+ const m = M(h, e);
518
+ return n.getTime() >= c.getTime() ? r + 1 : n.getTime() >= m.getTime() ? r : r - 1;
519
+ }
520
+ function xt(t, e) {
521
+ const n = O(), r = e?.firstWeekContainsDate ?? e?.locale?.options?.firstWeekContainsDate ?? n.firstWeekContainsDate ?? n.locale?.options?.firstWeekContainsDate ?? 1, a = C(t, e), o = g(t, 0);
522
+ return o.setFullYear(a, 0, r), o.setHours(0, 0, 0, 0), M(o, e);
523
+ }
524
+ function vt(t, e) {
525
+ const n = f(t), r = +M(n, e) - +xt(n, e);
526
+ return Math.round(r / E) + 1;
527
+ }
528
+ function i(t, e) {
529
+ const n = t < 0 ? "-" : "", r = Math.abs(t).toString().padStart(e, "0");
530
+ return n + r;
531
+ }
532
+ const l = {
533
+ // Year
534
+ y(t, e) {
535
+ const n = t.getFullYear(), r = n > 0 ? n : 1 - n;
536
+ return i(e === "yy" ? r % 100 : r, e.length);
537
+ },
538
+ // Month
539
+ M(t, e) {
540
+ const n = t.getMonth();
541
+ return e === "M" ? String(n + 1) : i(n + 1, 2);
542
+ },
543
+ // Day of the month
544
+ d(t, e) {
545
+ return i(t.getDate(), e.length);
546
+ },
547
+ // AM or PM
548
+ a(t, e) {
549
+ const n = t.getHours() / 12 >= 1 ? "pm" : "am";
550
+ switch (e) {
551
+ case "a":
552
+ case "aa":
553
+ return n.toUpperCase();
554
+ case "aaa":
555
+ return n;
556
+ case "aaaaa":
557
+ return n[0];
558
+ case "aaaa":
559
+ default:
560
+ return n === "am" ? "a.m." : "p.m.";
561
+ }
562
+ },
563
+ // Hour [1-12]
564
+ h(t, e) {
565
+ return i(t.getHours() % 12 || 12, e.length);
566
+ },
567
+ // Hour [0-23]
568
+ H(t, e) {
569
+ return i(t.getHours(), e.length);
570
+ },
571
+ // Minute
572
+ m(t, e) {
573
+ return i(t.getMinutes(), e.length);
574
+ },
575
+ // Second
576
+ s(t, e) {
577
+ return i(t.getSeconds(), e.length);
578
+ },
579
+ // Fraction of second
580
+ S(t, e) {
581
+ const n = e.length, r = t.getMilliseconds(), a = Math.trunc(
582
+ r * Math.pow(10, n - 3)
583
+ );
584
+ return i(a, e.length);
585
+ }
586
+ }, y = {
587
+ am: "am",
588
+ pm: "pm",
589
+ midnight: "midnight",
590
+ noon: "noon",
591
+ morning: "morning",
592
+ afternoon: "afternoon",
593
+ evening: "evening",
594
+ night: "night"
595
+ }, W = {
596
+ // Era
597
+ G: function(t, e, n) {
598
+ const r = t.getFullYear() > 0 ? 1 : 0;
599
+ switch (e) {
600
+ case "G":
601
+ case "GG":
602
+ case "GGG":
603
+ return n.era(r, { width: "abbreviated" });
604
+ case "GGGGG":
605
+ return n.era(r, { width: "narrow" });
606
+ case "GGGG":
607
+ default:
608
+ return n.era(r, { width: "wide" });
609
+ }
610
+ },
611
+ // Year
612
+ y: function(t, e, n) {
613
+ if (e === "yo") {
614
+ const r = t.getFullYear(), a = r > 0 ? r : 1 - r;
615
+ return n.ordinalNumber(a, { unit: "year" });
616
+ }
617
+ return l.y(t, e);
618
+ },
619
+ // Local week-numbering year
620
+ Y: function(t, e, n, r) {
621
+ const a = C(t, r), o = a > 0 ? a : 1 - a;
622
+ if (e === "YY") {
623
+ const s = o % 100;
624
+ return i(s, 2);
625
+ }
626
+ return e === "Yo" ? n.ordinalNumber(o, { unit: "year" }) : i(o, e.length);
627
+ },
628
+ // ISO week-numbering year
629
+ R: function(t, e) {
630
+ const n = N(t);
631
+ return i(n, e.length);
632
+ },
633
+ // Extended year. This is a single number designating the year of this calendar system.
634
+ // The main difference between `y` and `u` localizers are B.C. years:
635
+ // | Year | `y` | `u` |
636
+ // |------|-----|-----|
637
+ // | AC 1 | 1 | 1 |
638
+ // | BC 1 | 1 | 0 |
639
+ // | BC 2 | 2 | -1 |
640
+ // Also `yy` always returns the last two digits of a year,
641
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
642
+ u: function(t, e) {
643
+ const n = t.getFullYear();
644
+ return i(n, e.length);
645
+ },
646
+ // Quarter
647
+ Q: function(t, e, n) {
648
+ const r = Math.ceil((t.getMonth() + 1) / 3);
649
+ switch (e) {
650
+ case "Q":
651
+ return String(r);
652
+ case "QQ":
653
+ return i(r, 2);
654
+ case "Qo":
655
+ return n.ordinalNumber(r, { unit: "quarter" });
656
+ case "QQQ":
657
+ return n.quarter(r, {
658
+ width: "abbreviated",
659
+ context: "formatting"
660
+ });
661
+ case "QQQQQ":
662
+ return n.quarter(r, {
663
+ width: "narrow",
664
+ context: "formatting"
665
+ });
666
+ case "QQQQ":
667
+ default:
668
+ return n.quarter(r, {
669
+ width: "wide",
670
+ context: "formatting"
671
+ });
672
+ }
673
+ },
674
+ // Stand-alone quarter
675
+ q: function(t, e, n) {
676
+ const r = Math.ceil((t.getMonth() + 1) / 3);
677
+ switch (e) {
678
+ case "q":
679
+ return String(r);
680
+ case "qq":
681
+ return i(r, 2);
682
+ case "qo":
683
+ return n.ordinalNumber(r, { unit: "quarter" });
684
+ case "qqq":
685
+ return n.quarter(r, {
686
+ width: "abbreviated",
687
+ context: "standalone"
688
+ });
689
+ case "qqqqq":
690
+ return n.quarter(r, {
691
+ width: "narrow",
692
+ context: "standalone"
693
+ });
694
+ case "qqqq":
695
+ default:
696
+ return n.quarter(r, {
697
+ width: "wide",
698
+ context: "standalone"
699
+ });
700
+ }
701
+ },
702
+ // Month
703
+ M: function(t, e, n) {
704
+ const r = t.getMonth();
705
+ switch (e) {
706
+ case "M":
707
+ case "MM":
708
+ return l.M(t, e);
709
+ case "Mo":
710
+ return n.ordinalNumber(r + 1, { unit: "month" });
711
+ case "MMM":
712
+ return n.month(r, {
713
+ width: "abbreviated",
714
+ context: "formatting"
715
+ });
716
+ case "MMMMM":
717
+ return n.month(r, {
718
+ width: "narrow",
719
+ context: "formatting"
720
+ });
721
+ case "MMMM":
722
+ default:
723
+ return n.month(r, { width: "wide", context: "formatting" });
724
+ }
725
+ },
726
+ // Stand-alone month
727
+ L: function(t, e, n) {
728
+ const r = t.getMonth();
729
+ switch (e) {
730
+ case "L":
731
+ return String(r + 1);
732
+ case "LL":
733
+ return i(r + 1, 2);
734
+ case "Lo":
735
+ return n.ordinalNumber(r + 1, { unit: "month" });
736
+ case "LLL":
737
+ return n.month(r, {
738
+ width: "abbreviated",
739
+ context: "standalone"
740
+ });
741
+ case "LLLLL":
742
+ return n.month(r, {
743
+ width: "narrow",
744
+ context: "standalone"
745
+ });
746
+ case "LLLL":
747
+ default:
748
+ return n.month(r, { width: "wide", context: "standalone" });
749
+ }
750
+ },
751
+ // Local week of year
752
+ w: function(t, e, n, r) {
753
+ const a = vt(t, r);
754
+ return e === "wo" ? n.ordinalNumber(a, { unit: "week" }) : i(a, e.length);
755
+ },
756
+ // ISO week of year
757
+ I: function(t, e, n) {
758
+ const r = kt(t);
759
+ return e === "Io" ? n.ordinalNumber(r, { unit: "week" }) : i(r, e.length);
760
+ },
761
+ // Day of the month
762
+ d: function(t, e, n) {
763
+ return e === "do" ? n.ordinalNumber(t.getDate(), { unit: "date" }) : l.d(t, e);
764
+ },
765
+ // Day of year
766
+ D: function(t, e, n) {
767
+ const r = Dt(t);
768
+ return e === "Do" ? n.ordinalNumber(r, { unit: "dayOfYear" }) : i(r, e.length);
769
+ },
770
+ // Day of week
771
+ E: function(t, e, n) {
772
+ const r = t.getDay();
773
+ switch (e) {
774
+ case "E":
775
+ case "EE":
776
+ case "EEE":
777
+ return n.day(r, {
778
+ width: "abbreviated",
779
+ context: "formatting"
780
+ });
781
+ case "EEEEE":
782
+ return n.day(r, {
783
+ width: "narrow",
784
+ context: "formatting"
785
+ });
786
+ case "EEEEEE":
787
+ return n.day(r, {
788
+ width: "short",
789
+ context: "formatting"
790
+ });
791
+ case "EEEE":
792
+ default:
793
+ return n.day(r, {
794
+ width: "wide",
795
+ context: "formatting"
796
+ });
797
+ }
798
+ },
799
+ // Local day of week
800
+ e: function(t, e, n, r) {
801
+ const a = t.getDay(), o = (a - r.weekStartsOn + 8) % 7 || 7;
802
+ switch (e) {
803
+ case "e":
804
+ return String(o);
805
+ case "ee":
806
+ return i(o, 2);
807
+ case "eo":
808
+ return n.ordinalNumber(o, { unit: "day" });
809
+ case "eee":
810
+ return n.day(a, {
811
+ width: "abbreviated",
812
+ context: "formatting"
813
+ });
814
+ case "eeeee":
815
+ return n.day(a, {
816
+ width: "narrow",
817
+ context: "formatting"
818
+ });
819
+ case "eeeeee":
820
+ return n.day(a, {
821
+ width: "short",
822
+ context: "formatting"
823
+ });
824
+ case "eeee":
825
+ default:
826
+ return n.day(a, {
827
+ width: "wide",
828
+ context: "formatting"
829
+ });
830
+ }
831
+ },
832
+ // Stand-alone local day of week
833
+ c: function(t, e, n, r) {
834
+ const a = t.getDay(), o = (a - r.weekStartsOn + 8) % 7 || 7;
835
+ switch (e) {
836
+ case "c":
837
+ return String(o);
838
+ case "cc":
839
+ return i(o, e.length);
840
+ case "co":
841
+ return n.ordinalNumber(o, { unit: "day" });
842
+ case "ccc":
843
+ return n.day(a, {
844
+ width: "abbreviated",
845
+ context: "standalone"
846
+ });
847
+ case "ccccc":
848
+ return n.day(a, {
849
+ width: "narrow",
850
+ context: "standalone"
851
+ });
852
+ case "cccccc":
853
+ return n.day(a, {
854
+ width: "short",
855
+ context: "standalone"
856
+ });
857
+ case "cccc":
858
+ default:
859
+ return n.day(a, {
860
+ width: "wide",
861
+ context: "standalone"
862
+ });
863
+ }
864
+ },
865
+ // ISO day of week
866
+ i: function(t, e, n) {
867
+ const r = t.getDay(), a = r === 0 ? 7 : r;
868
+ switch (e) {
869
+ case "i":
870
+ return String(a);
871
+ case "ii":
872
+ return i(a, e.length);
873
+ case "io":
874
+ return n.ordinalNumber(a, { unit: "day" });
875
+ case "iii":
876
+ return n.day(r, {
877
+ width: "abbreviated",
878
+ context: "formatting"
879
+ });
880
+ case "iiiii":
881
+ return n.day(r, {
882
+ width: "narrow",
883
+ context: "formatting"
884
+ });
885
+ case "iiiiii":
886
+ return n.day(r, {
887
+ width: "short",
888
+ context: "formatting"
889
+ });
890
+ case "iiii":
891
+ default:
892
+ return n.day(r, {
893
+ width: "wide",
894
+ context: "formatting"
895
+ });
896
+ }
897
+ },
898
+ // AM or PM
899
+ a: function(t, e, n) {
900
+ const a = t.getHours() / 12 >= 1 ? "pm" : "am";
901
+ switch (e) {
902
+ case "a":
903
+ case "aa":
904
+ return n.dayPeriod(a, {
905
+ width: "abbreviated",
906
+ context: "formatting"
907
+ });
908
+ case "aaa":
909
+ return n.dayPeriod(a, {
910
+ width: "abbreviated",
911
+ context: "formatting"
912
+ }).toLowerCase();
913
+ case "aaaaa":
914
+ return n.dayPeriod(a, {
915
+ width: "narrow",
916
+ context: "formatting"
917
+ });
918
+ case "aaaa":
919
+ default:
920
+ return n.dayPeriod(a, {
921
+ width: "wide",
922
+ context: "formatting"
923
+ });
924
+ }
925
+ },
926
+ // AM, PM, midnight, noon
927
+ b: function(t, e, n) {
928
+ const r = t.getHours();
929
+ let a;
930
+ switch (r === 12 ? a = y.noon : r === 0 ? a = y.midnight : a = r / 12 >= 1 ? "pm" : "am", e) {
931
+ case "b":
932
+ case "bb":
933
+ return n.dayPeriod(a, {
934
+ width: "abbreviated",
935
+ context: "formatting"
936
+ });
937
+ case "bbb":
938
+ return n.dayPeriod(a, {
939
+ width: "abbreviated",
940
+ context: "formatting"
941
+ }).toLowerCase();
942
+ case "bbbbb":
943
+ return n.dayPeriod(a, {
944
+ width: "narrow",
945
+ context: "formatting"
946
+ });
947
+ case "bbbb":
948
+ default:
949
+ return n.dayPeriod(a, {
950
+ width: "wide",
951
+ context: "formatting"
952
+ });
953
+ }
954
+ },
955
+ // in the morning, in the afternoon, in the evening, at night
956
+ B: function(t, e, n) {
957
+ const r = t.getHours();
958
+ let a;
959
+ switch (r >= 17 ? a = y.evening : r >= 12 ? a = y.afternoon : r >= 4 ? a = y.morning : a = y.night, e) {
960
+ case "B":
961
+ case "BB":
962
+ case "BBB":
963
+ return n.dayPeriod(a, {
964
+ width: "abbreviated",
965
+ context: "formatting"
966
+ });
967
+ case "BBBBB":
968
+ return n.dayPeriod(a, {
969
+ width: "narrow",
970
+ context: "formatting"
971
+ });
972
+ case "BBBB":
973
+ default:
974
+ return n.dayPeriod(a, {
975
+ width: "wide",
976
+ context: "formatting"
977
+ });
978
+ }
979
+ },
980
+ // Hour [1-12]
981
+ h: function(t, e, n) {
982
+ if (e === "ho") {
983
+ let r = t.getHours() % 12;
984
+ return r === 0 && (r = 12), n.ordinalNumber(r, { unit: "hour" });
985
+ }
986
+ return l.h(t, e);
987
+ },
988
+ // Hour [0-23]
989
+ H: function(t, e, n) {
990
+ return e === "Ho" ? n.ordinalNumber(t.getHours(), { unit: "hour" }) : l.H(t, e);
991
+ },
992
+ // Hour [0-11]
993
+ K: function(t, e, n) {
994
+ const r = t.getHours() % 12;
995
+ return e === "Ko" ? n.ordinalNumber(r, { unit: "hour" }) : i(r, e.length);
996
+ },
997
+ // Hour [1-24]
998
+ k: function(t, e, n) {
999
+ let r = t.getHours();
1000
+ return r === 0 && (r = 24), e === "ko" ? n.ordinalNumber(r, { unit: "hour" }) : i(r, e.length);
1001
+ },
1002
+ // Minute
1003
+ m: function(t, e, n) {
1004
+ return e === "mo" ? n.ordinalNumber(t.getMinutes(), { unit: "minute" }) : l.m(t, e);
1005
+ },
1006
+ // Second
1007
+ s: function(t, e, n) {
1008
+ return e === "so" ? n.ordinalNumber(t.getSeconds(), { unit: "second" }) : l.s(t, e);
1009
+ },
1010
+ // Fraction of second
1011
+ S: function(t, e) {
1012
+ return l.S(t, e);
1013
+ },
1014
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1015
+ X: function(t, e, n) {
1016
+ const r = t.getTimezoneOffset();
1017
+ if (r === 0)
1018
+ return "Z";
1019
+ switch (e) {
1020
+ case "X":
1021
+ return S(r);
1022
+ case "XXXX":
1023
+ case "XX":
1024
+ return w(r);
1025
+ case "XXXXX":
1026
+ case "XXX":
1027
+ default:
1028
+ return w(r, ":");
1029
+ }
1030
+ },
1031
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1032
+ x: function(t, e, n) {
1033
+ const r = t.getTimezoneOffset();
1034
+ switch (e) {
1035
+ case "x":
1036
+ return S(r);
1037
+ case "xxxx":
1038
+ case "xx":
1039
+ return w(r);
1040
+ case "xxxxx":
1041
+ case "xxx":
1042
+ default:
1043
+ return w(r, ":");
1044
+ }
1045
+ },
1046
+ // Timezone (GMT)
1047
+ O: function(t, e, n) {
1048
+ const r = t.getTimezoneOffset();
1049
+ switch (e) {
1050
+ case "O":
1051
+ case "OO":
1052
+ case "OOO":
1053
+ return "GMT" + Y(r, ":");
1054
+ case "OOOO":
1055
+ default:
1056
+ return "GMT" + w(r, ":");
1057
+ }
1058
+ },
1059
+ // Timezone (specific non-location)
1060
+ z: function(t, e, n) {
1061
+ const r = t.getTimezoneOffset();
1062
+ switch (e) {
1063
+ case "z":
1064
+ case "zz":
1065
+ case "zzz":
1066
+ return "GMT" + Y(r, ":");
1067
+ case "zzzz":
1068
+ default:
1069
+ return "GMT" + w(r, ":");
1070
+ }
1071
+ },
1072
+ // Seconds timestamp
1073
+ t: function(t, e, n) {
1074
+ const r = Math.trunc(t.getTime() / 1e3);
1075
+ return i(r, e.length);
1076
+ },
1077
+ // Milliseconds timestamp
1078
+ T: function(t, e, n) {
1079
+ const r = t.getTime();
1080
+ return i(r, e.length);
1081
+ }
1082
+ };
1083
+ function Y(t, e = "") {
1084
+ const n = t > 0 ? "-" : "+", r = Math.abs(t), a = Math.trunc(r / 60), o = r % 60;
1085
+ return o === 0 ? n + String(a) : n + String(a) + e + i(o, 2);
1086
+ }
1087
+ function S(t, e) {
1088
+ return t % 60 === 0 ? (t > 0 ? "-" : "+") + i(Math.abs(t) / 60, 2) : w(t, e);
1089
+ }
1090
+ function w(t, e = "") {
1091
+ const n = t > 0 ? "-" : "+", r = Math.abs(t), a = i(Math.trunc(r / 60), 2), o = i(r % 60, 2);
1092
+ return n + a + e + o;
1093
+ }
1094
+ const T = (t, e) => {
1095
+ switch (t) {
1096
+ case "P":
1097
+ return e.date({ width: "short" });
1098
+ case "PP":
1099
+ return e.date({ width: "medium" });
1100
+ case "PPP":
1101
+ return e.date({ width: "long" });
1102
+ case "PPPP":
1103
+ default:
1104
+ return e.date({ width: "full" });
1105
+ }
1106
+ }, q = (t, e) => {
1107
+ switch (t) {
1108
+ case "p":
1109
+ return e.time({ width: "short" });
1110
+ case "pp":
1111
+ return e.time({ width: "medium" });
1112
+ case "ppp":
1113
+ return e.time({ width: "long" });
1114
+ case "pppp":
1115
+ default:
1116
+ return e.time({ width: "full" });
1117
+ }
1118
+ }, Wt = (t, e) => {
1119
+ const n = t.match(/(P+)(p+)?/) || [], r = n[1], a = n[2];
1120
+ if (!a)
1121
+ return T(t, e);
1122
+ let o;
1123
+ switch (r) {
1124
+ case "P":
1125
+ o = e.dateTime({ width: "short" });
1126
+ break;
1127
+ case "PP":
1128
+ o = e.dateTime({ width: "medium" });
1129
+ break;
1130
+ case "PPP":
1131
+ o = e.dateTime({ width: "long" });
1132
+ break;
1133
+ case "PPPP":
1134
+ default:
1135
+ o = e.dateTime({ width: "full" });
1136
+ break;
1137
+ }
1138
+ return o.replace("{{date}}", T(r, e)).replace("{{time}}", q(a, e));
1139
+ }, Yt = {
1140
+ p: q,
1141
+ P: Wt
1142
+ }, St = /^D+$/, Tt = /^Y+$/, Ft = ["D", "DD", "YY", "YYYY"];
1143
+ function Et(t) {
1144
+ return St.test(t);
1145
+ }
1146
+ function Nt(t) {
1147
+ return Tt.test(t);
1148
+ }
1149
+ function Ct(t, e, n) {
1150
+ const r = qt(t, e, n);
1151
+ if (console.warn(r), Ft.includes(t))
1152
+ throw new RangeError(r);
1153
+ }
1154
+ function qt(t, e, n) {
1155
+ const r = t[0] === "Y" ? "years" : "days of the month";
1156
+ return `Use \`${t.toLowerCase()}\` instead of \`${t}\` (in \`${e}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
1157
+ }
1158
+ const Ht = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g, Qt = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g, Xt = /^'([^]*?)'?$/, _t = /''/g, jt = /[a-zA-Z]/;
1159
+ function F(t, e, n) {
1160
+ const r = O(), a = r.locale ?? Ot, o = r.firstWeekContainsDate ?? r.locale?.options?.firstWeekContainsDate ?? 1, s = r.weekStartsOn ?? r.locale?.options?.weekStartsOn ?? 0, c = f(t);
1161
+ if (!G(c))
1162
+ throw new RangeError("Invalid time value");
1163
+ let h = e.match(Qt).map((d) => {
1164
+ const u = d[0];
1165
+ if (u === "p" || u === "P") {
1166
+ const D = Yt[u];
1167
+ return D(d, a.formatLong);
1168
+ }
1169
+ return d;
1170
+ }).join("").match(Ht).map((d) => {
1171
+ if (d === "''")
1172
+ return { isToken: !1, value: "'" };
1173
+ const u = d[0];
1174
+ if (u === "'")
1175
+ return { isToken: !1, value: Lt(d) };
1176
+ if (W[u])
1177
+ return { isToken: !0, value: d };
1178
+ if (u.match(jt))
1179
+ throw new RangeError(
1180
+ "Format string contains an unescaped latin alphabet character `" + u + "`"
1181
+ );
1182
+ return { isToken: !1, value: d };
1183
+ });
1184
+ a.localize.preprocessor && (h = a.localize.preprocessor(c, h));
1185
+ const m = {
1186
+ firstWeekContainsDate: o,
1187
+ weekStartsOn: s,
1188
+ locale: a
1189
+ };
1190
+ return h.map((d) => {
1191
+ if (!d.isToken)
1192
+ return d.value;
1193
+ const u = d.value;
1194
+ (Nt(u) || Et(u)) && Ct(u, e, String(t));
1195
+ const D = W[u[0]];
1196
+ return D(c, u, a.localize, m);
1197
+ }).join("");
1198
+ }
1199
+ function Lt(t) {
1200
+ const e = t.match(Xt);
1201
+ return e ? e[1].replace(_t, "'") : t;
1202
+ }
1203
+ function Gt(t, e) {
1204
+ return H(t, -e);
1205
+ }
1206
+ function Rt(t, e = !1) {
1207
+ const n = t.getDate(), r = t.getMonth() + 1, a = t.getFullYear();
1208
+ return e ? `${("0" + n).slice(-2)}-${("0" + r).slice(-2)}-${a}` : `${a}-${("0" + r).slice(-2)}-${("0" + n).slice(-2)}`;
1209
+ }
1210
+ const Bt = (t) => {
1211
+ if (typeof t == "string") {
1212
+ const e = new Date(t);
1213
+ return isNaN(e.valueOf()) ? "" : F(e, "dd/MM/yyyy");
1214
+ }
1215
+ return F(t, "dd/MM/yyyy");
1216
+ }, At = (t = /* @__PURE__ */ new Date(), e) => (e < 0 && (e = 0), Gt(t, e));
5
1217
  export {
6
- s as formatDate
1218
+ Rt as formatDate,
1219
+ Bt as formatDateToddMMYYYY,
1220
+ At as subtractDaysFromDate
7
1221
  };