@bereasoftware/time-guard 2.4.0 → 2.4.1
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/calendars/index.es.js +1 -1
- package/dist/plugins/advanced-format.es.js +1 -1
- package/dist/plugins/duration.es.js +1 -1
- package/dist/plugins/relative-time.es.js +1 -1
- package/dist/time-guard.cjs +1 -1
- package/dist/time-guard.cjs.map +1 -1
- package/dist/time-guard.es.js +156 -149
- package/dist/time-guard.es.js.map +1 -1
- package/dist/time-guard.iife.js +1 -1
- package/dist/time-guard.iife.js.map +1 -1
- package/dist/time-guard.umd.js +1 -1
- package/dist/time-guard.umd.js.map +1 -1
- package/dist/types/polyfill-loader.d.ts +1 -1
- package/package.json +2 -7
package/dist/time-guard.es.js
CHANGED
|
@@ -1,45 +1,52 @@
|
|
|
1
|
-
/*! time-guard v2.4.
|
|
1
|
+
/*! time-guard v2.4.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
2
|
import "@js-temporal/polyfill";
|
|
3
3
|
//#region src/adapters/temporal.adapter.ts
|
|
4
|
-
var e = null;
|
|
5
|
-
function
|
|
4
|
+
var e = null, t = !1;
|
|
5
|
+
function n() {
|
|
6
6
|
if (e) return e;
|
|
7
|
-
let
|
|
8
|
-
if (!
|
|
9
|
-
|
|
7
|
+
let n = globalThis.Temporal;
|
|
8
|
+
if (!n) {
|
|
9
|
+
if (!t && typeof globalThis.require == "function") try {
|
|
10
|
+
globalThis.require("@js-temporal/polyfill"), t = !0;
|
|
11
|
+
let n = globalThis.Temporal;
|
|
12
|
+
if (n) return e = n, n;
|
|
13
|
+
} catch {}
|
|
14
|
+
throw Error("Temporal API not loaded. Make sure @js-temporal/polyfill is imported in your app.");
|
|
15
|
+
}
|
|
16
|
+
return e = n, n;
|
|
10
17
|
}
|
|
11
|
-
var
|
|
18
|
+
var r = class {
|
|
12
19
|
static parseToPlainDateTime(e) {
|
|
13
|
-
let
|
|
20
|
+
let t = n();
|
|
14
21
|
return this.isPlainDateTime(e) ? e : this.isZonedDateTime(e) ? e.toPlainDateTime() : this.isPlainDate(e) ? e.toPlainDateTime({
|
|
15
22
|
hour: 0,
|
|
16
23
|
minute: 0,
|
|
17
24
|
second: 0,
|
|
18
25
|
millisecond: 0
|
|
19
|
-
}) : this.isPlainTime(e) ?
|
|
26
|
+
}) : this.isPlainTime(e) ? t.Now.plainDateTimeISO().with(e) : typeof e == "object" && e && "getTime" in e && typeof e.getTime == "function" ? this.fromDate(e) : typeof e == "number" ? this.fromUnix(e) : typeof e == "string" ? this.parseISOString(e) : typeof e == "object" && e ? this.fromObject(e) : t.Now.plainDateTimeISO();
|
|
20
27
|
}
|
|
21
28
|
static fromDate(e) {
|
|
22
|
-
let
|
|
23
|
-
return
|
|
29
|
+
let t = n(), [r, i] = e.toISOString().split("T");
|
|
30
|
+
return t.PlainDateTime.from(r + "T" + i.slice(0, -1));
|
|
24
31
|
}
|
|
25
32
|
static fromUnix(e) {
|
|
26
33
|
return this.fromDate(new Date(e));
|
|
27
34
|
}
|
|
28
35
|
static parseISOString(e) {
|
|
29
|
-
let
|
|
36
|
+
let t = n();
|
|
30
37
|
try {
|
|
31
38
|
if (e.includes("T") || / \d{2}:\d{2}/.test(e)) {
|
|
32
|
-
let
|
|
33
|
-
return
|
|
39
|
+
let n = e.replace(" ", "T");
|
|
40
|
+
return t.PlainDateTime.from(n);
|
|
34
41
|
}
|
|
35
|
-
return
|
|
42
|
+
return t.PlainDate.from(e).toPlainDateTime({ hour: 0 });
|
|
36
43
|
} catch {
|
|
37
|
-
return
|
|
44
|
+
return t.Now.plainDateTimeISO();
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
static fromObject(e) {
|
|
41
|
-
let
|
|
42
|
-
return
|
|
48
|
+
let t = n(), r = e.year || t.Now.plainDateISO().year, i = e.month || 1, a = e.day || 1, o = e.hour || 0, s = e.minute || 0, c = e.second || 0, l = e.millisecond || 0;
|
|
49
|
+
return t.PlainDateTime.from({
|
|
43
50
|
year: r,
|
|
44
51
|
month: i,
|
|
45
52
|
day: a,
|
|
@@ -76,18 +83,18 @@ var n = class {
|
|
|
76
83
|
return typeof e == "object" && !!e && "hour" in e && !("year" in e);
|
|
77
84
|
}
|
|
78
85
|
static now() {
|
|
79
|
-
return
|
|
86
|
+
return n().Now.plainDateTimeISO();
|
|
80
87
|
}
|
|
81
88
|
static nowInTimezone(e) {
|
|
82
|
-
return
|
|
89
|
+
return n().Now.zonedDateTimeISO(e);
|
|
83
90
|
}
|
|
84
|
-
static compare(e,
|
|
85
|
-
let r =
|
|
86
|
-
if (r.PlainDateTime && typeof r.PlainDateTime.compare == "function") return r.PlainDateTime.compare(e,
|
|
87
|
-
let i = e.toString(), a =
|
|
91
|
+
static compare(e, t) {
|
|
92
|
+
let r = n();
|
|
93
|
+
if (r.PlainDateTime && typeof r.PlainDateTime.compare == "function") return r.PlainDateTime.compare(e, t);
|
|
94
|
+
let i = e.toString(), a = t.toString();
|
|
88
95
|
return i < a ? -1 : +(i > a);
|
|
89
96
|
}
|
|
90
|
-
},
|
|
97
|
+
}, i = {
|
|
91
98
|
name: "en",
|
|
92
99
|
months: [
|
|
93
100
|
"January",
|
|
@@ -155,7 +162,7 @@ var n = class {
|
|
|
155
162
|
datetime: "YYYY-MM-DD HH:mm:ss",
|
|
156
163
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
157
164
|
}
|
|
158
|
-
},
|
|
165
|
+
}, a = {
|
|
159
166
|
name: "es",
|
|
160
167
|
months: [
|
|
161
168
|
"Enero",
|
|
@@ -223,7 +230,7 @@ var n = class {
|
|
|
223
230
|
datetime: "DD/MM/YYYY HH:mm:ss",
|
|
224
231
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
225
232
|
}
|
|
226
|
-
},
|
|
233
|
+
}, o = class e {
|
|
227
234
|
static instance;
|
|
228
235
|
locales = /* @__PURE__ */ new Map();
|
|
229
236
|
currentLocale = "en";
|
|
@@ -231,14 +238,14 @@ var n = class {
|
|
|
231
238
|
return e.instance ||= new e(), e.instance;
|
|
232
239
|
}
|
|
233
240
|
constructor() {
|
|
234
|
-
this.locales.set("en",
|
|
241
|
+
this.locales.set("en", i), this.locales.set("es", a);
|
|
235
242
|
}
|
|
236
243
|
setLocale(e, t) {
|
|
237
244
|
t && this.locales.set(e.toLowerCase(), t), this.currentLocale = e.toLowerCase();
|
|
238
245
|
}
|
|
239
246
|
getLocale(e) {
|
|
240
247
|
let t = (e || this.currentLocale).toLowerCase();
|
|
241
|
-
return this.locales.get(t) || this.locales.get("en") ||
|
|
248
|
+
return this.locales.get(t) || this.locales.get("en") || i;
|
|
242
249
|
}
|
|
243
250
|
listLocales() {
|
|
244
251
|
return Array.from(this.locales.keys());
|
|
@@ -251,10 +258,10 @@ var n = class {
|
|
|
251
258
|
this.locales.set(e.toLowerCase(), t);
|
|
252
259
|
});
|
|
253
260
|
}
|
|
254
|
-
},
|
|
261
|
+
}, s = class {
|
|
255
262
|
localeManager;
|
|
256
263
|
constructor() {
|
|
257
|
-
this.localeManager =
|
|
264
|
+
this.localeManager = o.getInstance();
|
|
258
265
|
}
|
|
259
266
|
format(e, t, n) {
|
|
260
267
|
let r = this.localeManager.getLocale(n), i = [], a = t.replace(/\[([^\]]+)\]/g, (e, t) => (i.push(t), `~${i.length - 1}~`));
|
|
@@ -313,7 +320,7 @@ var n = class {
|
|
|
313
320
|
let r = this.getPreset(t);
|
|
314
321
|
return this.format(e, r, n);
|
|
315
322
|
}
|
|
316
|
-
},
|
|
323
|
+
}, c = {
|
|
317
324
|
en: {
|
|
318
325
|
year: ["year", "years"],
|
|
319
326
|
month: ["month", "months"],
|
|
@@ -344,7 +351,7 @@ var n = class {
|
|
|
344
351
|
second: ["seconde", "secondes"],
|
|
345
352
|
millisecond: ["milliseconde", "millisecondes"]
|
|
346
353
|
}
|
|
347
|
-
},
|
|
354
|
+
}, l = {
|
|
348
355
|
en: "and",
|
|
349
356
|
es: "y",
|
|
350
357
|
fr: "et",
|
|
@@ -352,19 +359,19 @@ var n = class {
|
|
|
352
359
|
it: "e",
|
|
353
360
|
pt: "e"
|
|
354
361
|
};
|
|
355
|
-
function
|
|
356
|
-
return ((
|
|
362
|
+
function u(e, t, n) {
|
|
363
|
+
return ((c[t] || c.en)[e] || [e, e + "s"])[n === 1 ? 0 : 1];
|
|
357
364
|
}
|
|
358
|
-
function
|
|
359
|
-
return
|
|
365
|
+
function d(e) {
|
|
366
|
+
return l[e] || "and";
|
|
360
367
|
}
|
|
361
|
-
function
|
|
368
|
+
function f(e, t) {
|
|
362
369
|
if (e.length === 0) return "";
|
|
363
370
|
if (e.length === 1) return e[0];
|
|
364
|
-
let n =
|
|
371
|
+
let n = d(t);
|
|
365
372
|
return e.length === 2 ? `${e[0]} ${n} ${e[1]}` : e.slice(0, -1).join(", ") + ` ${n} ${e[e.length - 1]}`;
|
|
366
373
|
}
|
|
367
|
-
function
|
|
374
|
+
function p(e) {
|
|
368
375
|
return {
|
|
369
376
|
en: "0 seconds",
|
|
370
377
|
es: "0 segundos",
|
|
@@ -373,7 +380,7 @@ function f(e) {
|
|
|
373
380
|
}
|
|
374
381
|
//#endregion
|
|
375
382
|
//#region src/plugins/manager.ts
|
|
376
|
-
var
|
|
383
|
+
var m = class e {
|
|
377
384
|
static instance;
|
|
378
385
|
plugins = /* @__PURE__ */ new Map();
|
|
379
386
|
static getInstance() {
|
|
@@ -413,7 +420,7 @@ var p = class e {
|
|
|
413
420
|
throw console.error(`Failed to register plugin "${e.name}":`, t), Error(`Failed to register plugin "${e.name}": ${t instanceof Error ? t.message : String(t)}`);
|
|
414
421
|
}
|
|
415
422
|
}
|
|
416
|
-
},
|
|
423
|
+
}, h = " days", g = 1e3, _ = g * 60, v = _ * 60, y = v * 24, b = y * 7, x = 365.25, S = x / 12 * y, C = x * y, w = class {
|
|
417
424
|
_value;
|
|
418
425
|
_tg1;
|
|
419
426
|
_tg2;
|
|
@@ -431,9 +438,9 @@ var p = class e {
|
|
|
431
438
|
}
|
|
432
439
|
format(e) {
|
|
433
440
|
let t = e || this._locale;
|
|
434
|
-
if (!this._breakdownData) return `${Math.abs(this._tg1.diff(this._tg2, "day"))}${
|
|
441
|
+
if (!this._breakdownData) return `${Math.abs(this._tg1.diff(this._tg2, "day"))}${h}`;
|
|
435
442
|
let n = [], r = this._breakdownData;
|
|
436
|
-
return r.years !== 0 && n.push(`${r.years} ${
|
|
443
|
+
return r.years !== 0 && n.push(`${r.years} ${u("year", t, r.years)}`), r.months !== 0 && n.push(`${r.months} ${u("month", t, r.months)}`), r.weeks !== 0 && n.push(`${r.weeks} ${u("week", t, r.weeks)}`), r.days !== 0 && n.push(`${r.days} ${u("day", t, r.days)}`), r.hours !== 0 && n.push(`${r.hours} ${u("hour", t, r.hours)}`), r.minutes !== 0 && n.push(`${r.minutes} ${u("minute", t, r.minutes)}`), r.seconds !== 0 && n.push(`${r.seconds} ${u("second", t, r.seconds)}`), n.length === 0 ? p(t) : f(n, t);
|
|
437
444
|
}
|
|
438
445
|
getMode() {
|
|
439
446
|
return this._mode;
|
|
@@ -447,7 +454,7 @@ var p = class e {
|
|
|
447
454
|
toJSON() {
|
|
448
455
|
return this._value;
|
|
449
456
|
}
|
|
450
|
-
},
|
|
457
|
+
}, T = class {
|
|
451
458
|
years;
|
|
452
459
|
months;
|
|
453
460
|
weeks;
|
|
@@ -513,22 +520,22 @@ var p = class e {
|
|
|
513
520
|
return `${e.value} ${this.pluralizeUnit(e.unit, e.value, t)}`;
|
|
514
521
|
}
|
|
515
522
|
}
|
|
516
|
-
return
|
|
517
|
-
let n =
|
|
523
|
+
return f(i.map((e) => {
|
|
524
|
+
let n = u(e.unit, t, e.value);
|
|
518
525
|
return `${e.value} ${n}`;
|
|
519
526
|
}), t);
|
|
520
527
|
}
|
|
521
528
|
total(e) {
|
|
522
529
|
let t = 0;
|
|
523
|
-
switch (t += this.years *
|
|
530
|
+
switch (t += this.years * C, t += this.months * S, t += this.weeks * b, t += this.days * y, t += this.hours * v, t += this.minutes * _, t += this.seconds * g, t += this.milliseconds, e) {
|
|
524
531
|
case "millisecond": return t;
|
|
525
|
-
case "second": return t /
|
|
526
|
-
case "minute": return t /
|
|
527
|
-
case "hour": return t /
|
|
528
|
-
case "day": return t /
|
|
529
|
-
case "week": return t /
|
|
530
|
-
case "month": return t /
|
|
531
|
-
case "year": return t /
|
|
532
|
+
case "second": return t / g;
|
|
533
|
+
case "minute": return t / _;
|
|
534
|
+
case "hour": return t / v;
|
|
535
|
+
case "day": return t / y;
|
|
536
|
+
case "week": return t / b;
|
|
537
|
+
case "month": return t / S;
|
|
538
|
+
case "year": return t / C;
|
|
532
539
|
case "microsecond": return t * 1e3;
|
|
533
540
|
case "nanosecond": return t * 1e6;
|
|
534
541
|
default: throw Error(`Unsupported unit: ${e}`);
|
|
@@ -594,16 +601,16 @@ var p = class e {
|
|
|
594
601
|
return e.push(`Total: ${t || "0"}`), e;
|
|
595
602
|
}
|
|
596
603
|
pluralizeUnit(e, t, n) {
|
|
597
|
-
return
|
|
604
|
+
return u(e, n, t);
|
|
598
605
|
}
|
|
599
|
-
},
|
|
606
|
+
}, E = class {
|
|
600
607
|
_start;
|
|
601
608
|
_end;
|
|
602
609
|
constructor(e, t) {
|
|
603
610
|
this._start = e, this._end = t;
|
|
604
611
|
}
|
|
605
612
|
toDuration() {
|
|
606
|
-
return
|
|
613
|
+
return D.between(this._start, this._end);
|
|
607
614
|
}
|
|
608
615
|
inMonths() {
|
|
609
616
|
return this.toDuration().total("month");
|
|
@@ -614,7 +621,7 @@ var p = class e {
|
|
|
614
621
|
in(e) {
|
|
615
622
|
return this.toDuration().total(e);
|
|
616
623
|
}
|
|
617
|
-
},
|
|
624
|
+
}, D = class e {
|
|
618
625
|
temporal;
|
|
619
626
|
config;
|
|
620
627
|
formatterInstance;
|
|
@@ -644,11 +651,11 @@ var p = class e {
|
|
|
644
651
|
};
|
|
645
652
|
}
|
|
646
653
|
constructor(e, t) {
|
|
647
|
-
if (this.formatterInstance = new
|
|
654
|
+
if (this.formatterInstance = new s(), this.config = {
|
|
648
655
|
locale: t?.locale || "en",
|
|
649
656
|
timezone: t?.timezone || "UTC",
|
|
650
657
|
strict: t?.strict ?? !1
|
|
651
|
-
}, this.temporal =
|
|
658
|
+
}, this.temporal = r.parseToPlainDateTime(e), this.config.timezone && this.config.timezone !== "UTC") try {
|
|
652
659
|
this.temporal = this.temporal.toZonedDateTime(this.config.timezone);
|
|
653
660
|
} catch {}
|
|
654
661
|
}
|
|
@@ -663,23 +670,23 @@ var p = class e {
|
|
|
663
670
|
return r.temporal = t, r;
|
|
664
671
|
}
|
|
665
672
|
static between(e, t) {
|
|
666
|
-
let
|
|
673
|
+
let n = r.toPlainDateTime(e.temporal), i = r.toPlainDateTime(t.temporal), [a, o] = r.compare(n, i) <= 0 ? [e, t] : [t, e];
|
|
667
674
|
return a.until(o);
|
|
668
675
|
}
|
|
669
676
|
static range(t, n) {
|
|
670
|
-
return new
|
|
677
|
+
return new E(t instanceof e ? t : new e(t), n instanceof e ? n : new e(n));
|
|
671
678
|
}
|
|
672
679
|
toTemporal() {
|
|
673
680
|
return this.temporal;
|
|
674
681
|
}
|
|
675
682
|
toDate() {
|
|
676
|
-
return
|
|
683
|
+
return r.toDate(this.temporal);
|
|
677
684
|
}
|
|
678
685
|
toISOString() {
|
|
679
|
-
return
|
|
686
|
+
return r.toISOString(this.temporal);
|
|
680
687
|
}
|
|
681
688
|
valueOf() {
|
|
682
|
-
return
|
|
689
|
+
return r.toUnix(this.temporal);
|
|
683
690
|
}
|
|
684
691
|
unix() {
|
|
685
692
|
return Math.floor(this.valueOf() / 1e3);
|
|
@@ -700,12 +707,12 @@ var p = class e {
|
|
|
700
707
|
let t = this.clone();
|
|
701
708
|
t.config.timezone = e;
|
|
702
709
|
try {
|
|
703
|
-
t.temporal =
|
|
710
|
+
t.temporal = r.toPlainDateTime(t.temporal).toZonedDateTime(e);
|
|
704
711
|
} catch {}
|
|
705
712
|
return t;
|
|
706
713
|
}
|
|
707
714
|
format(e) {
|
|
708
|
-
let t =
|
|
715
|
+
let t = r.toPlainDateTime(this.temporal), n = [
|
|
709
716
|
"iso",
|
|
710
717
|
"date",
|
|
711
718
|
"time",
|
|
@@ -714,10 +721,10 @@ var p = class e {
|
|
|
714
721
|
"rfc3339",
|
|
715
722
|
"utc"
|
|
716
723
|
].includes(e) ? this.formatterInstance.getPreset(e) : e;
|
|
717
|
-
return this.formatterInstance.format(t,
|
|
724
|
+
return this.formatterInstance.format(t, n, this.config.locale);
|
|
718
725
|
}
|
|
719
726
|
get(e) {
|
|
720
|
-
let t =
|
|
727
|
+
let t = r.toPlainDateTime(this.temporal);
|
|
721
728
|
return e === "week" ? t.weekOfYear : t[{
|
|
722
729
|
year: "year",
|
|
723
730
|
month: "month",
|
|
@@ -732,10 +739,10 @@ var p = class e {
|
|
|
732
739
|
}[e]];
|
|
733
740
|
}
|
|
734
741
|
add(t) {
|
|
735
|
-
let
|
|
742
|
+
let n = r.toPlainDateTime(this.temporal), i = {};
|
|
736
743
|
return Object.entries(t).forEach(([e, t]) => {
|
|
737
744
|
t !== void 0 && t !== 0 && (i[e + "s"] = t);
|
|
738
|
-
}),
|
|
745
|
+
}), n = n.add(i), e.fromTemporal(n, this.config);
|
|
739
746
|
}
|
|
740
747
|
subtract(e) {
|
|
741
748
|
let t = {};
|
|
@@ -744,7 +751,7 @@ var p = class e {
|
|
|
744
751
|
}), this.add(t);
|
|
745
752
|
}
|
|
746
753
|
diff(e, t) {
|
|
747
|
-
let
|
|
754
|
+
let n = r.toPlainDateTime(this.temporal), i = r.toPlainDateTime(e.temporal), a = {
|
|
748
755
|
year: "years",
|
|
749
756
|
month: "months",
|
|
750
757
|
week: "weeks",
|
|
@@ -757,23 +764,23 @@ var p = class e {
|
|
|
757
764
|
nanosecond: "nanoseconds"
|
|
758
765
|
};
|
|
759
766
|
if (typeof t == "string") {
|
|
760
|
-
let e = t,
|
|
761
|
-
return Math.round(o[
|
|
767
|
+
let e = t, r = a[e], o = n.since(i, { smallestUnit: e });
|
|
768
|
+
return Math.round(o[r] || 0);
|
|
762
769
|
}
|
|
763
770
|
let o = t || {}, s = o.mode || "exact", c = o.unit || "millisecond", l = o.locale || this.config.locale;
|
|
764
771
|
if (s === "exact") {
|
|
765
|
-
let
|
|
772
|
+
let r = a[c], o = n.since(i, { smallestUnit: c }), u = Math.round(o[r] || 0);
|
|
766
773
|
if (t === void 0 || typeof t == "object") {
|
|
767
774
|
let t = (o.years || 0) * 365.25 * 24 * 60 * 60 * 1e3 + (o.months || 0) * 30.44 * 24 * 60 * 60 * 1e3 + (o.weeks || 0) * 7 * 24 * 60 * 60 * 1e3 + (o.days || 0) * 24 * 60 * 60 * 1e3 + (o.hours || 0) * 60 * 60 * 1e3 + (o.minutes || 0) * 60 * 1e3 + (o.seconds || 0) * 1e3 + (o.milliseconds || 0);
|
|
768
|
-
return new
|
|
775
|
+
return new w(Math.round(t), this, e, s, void 0, l);
|
|
769
776
|
}
|
|
770
777
|
return u;
|
|
771
778
|
}
|
|
772
779
|
if (s === "calendar") {
|
|
773
|
-
let t =
|
|
780
|
+
let t = n.since(i, {
|
|
774
781
|
largestUnit: "month",
|
|
775
782
|
smallestUnit: "millisecond"
|
|
776
|
-
}),
|
|
783
|
+
}), r = {
|
|
777
784
|
years: Math.floor(t.years || 0),
|
|
778
785
|
months: Math.floor(t.months || 0),
|
|
779
786
|
weeks: Math.floor(t.weeks || 0),
|
|
@@ -783,46 +790,46 @@ var p = class e {
|
|
|
783
790
|
seconds: Math.floor(t.seconds || 0),
|
|
784
791
|
milliseconds: Math.floor(t.milliseconds || 0)
|
|
785
792
|
}, a = (t.years || 0) * 365.25 * 24 * 60 * 60 * 1e3 + (t.months || 0) * 30.44 * 24 * 60 * 60 * 1e3 + (t.weeks || 0) * 7 * 24 * 60 * 60 * 1e3 + (t.days || 0) * 24 * 60 * 60 * 1e3 + (t.hours || 0) * 60 * 60 * 1e3 + (t.minutes || 0) * 60 * 1e3 + (t.seconds || 0) * 1e3 + (t.milliseconds || 0);
|
|
786
|
-
return new
|
|
793
|
+
return new w(Math.round(a), this, e, s, r, l);
|
|
787
794
|
}
|
|
788
|
-
let u =
|
|
789
|
-
return new
|
|
795
|
+
let u = n.since(i, { smallestUnit: "millisecond" }), d = (u.years || 0) * 365.25 * 24 * 60 * 60 * 1e3 + (u.months || 0) * 30.44 * 24 * 60 * 60 * 1e3 + (u.weeks || 0) * 7 * 24 * 60 * 60 * 1e3 + (u.days || 0) * 24 * 60 * 60 * 1e3 + (u.hours || 0) * 60 * 60 * 1e3 + (u.minutes || 0) * 60 * 1e3 + (u.seconds || 0) * 1e3 + (u.milliseconds || 0);
|
|
796
|
+
return new w(Math.round(d), this, e, s, void 0, l);
|
|
790
797
|
}
|
|
791
798
|
isBefore(e) {
|
|
792
|
-
let t =
|
|
793
|
-
return
|
|
799
|
+
let t = r.toPlainDateTime(this.temporal), n = r.toPlainDateTime(e.temporal);
|
|
800
|
+
return r.compare(t, n) < 0;
|
|
794
801
|
}
|
|
795
802
|
isAfter(e) {
|
|
796
|
-
let t =
|
|
797
|
-
return
|
|
803
|
+
let t = r.toPlainDateTime(this.temporal), n = r.toPlainDateTime(e.temporal);
|
|
804
|
+
return r.compare(t, n) > 0;
|
|
798
805
|
}
|
|
799
806
|
isSame(e, t) {
|
|
800
|
-
if (!t) return
|
|
801
|
-
let
|
|
807
|
+
if (!t) return r.compare(r.toPlainDateTime(this.temporal), r.toPlainDateTime(e.temporal)) === 0;
|
|
808
|
+
let n = r.toPlainDateTime(this.temporal), i = r.toPlainDateTime(e.temporal);
|
|
802
809
|
switch (t) {
|
|
803
|
-
case "year": return
|
|
804
|
-
case "month": return
|
|
805
|
-
case "day": return
|
|
806
|
-
case "hour": return
|
|
807
|
-
case "minute": return
|
|
808
|
-
case "second": return
|
|
810
|
+
case "year": return n.year === i.year;
|
|
811
|
+
case "month": return n.year === i.year && n.month === i.month;
|
|
812
|
+
case "day": return n.year === i.year && n.month === i.month && n.day === i.day;
|
|
813
|
+
case "hour": return n.year === i.year && n.month === i.month && n.day === i.day && n.hour === i.hour;
|
|
814
|
+
case "minute": return n.year === i.year && n.month === i.month && n.day === i.day && n.hour === i.hour && n.minute === i.minute;
|
|
815
|
+
case "second": return n.year === i.year && n.month === i.month && n.day === i.day && n.hour === i.hour && n.minute === i.minute && n.second === i.second;
|
|
809
816
|
default: return !1;
|
|
810
817
|
}
|
|
811
818
|
}
|
|
812
|
-
isBetween(e, t,
|
|
813
|
-
let a =
|
|
814
|
-
if (
|
|
815
|
-
let e = this.clone().startOf(
|
|
816
|
-
c =
|
|
817
|
-
} else c =
|
|
819
|
+
isBetween(e, t, n, i = "[]") {
|
|
820
|
+
let a = r.toPlainDateTime(this.temporal), o = r.toPlainDateTime(e.temporal), s = r.toPlainDateTime(t.temporal), c = !0, l = !0;
|
|
821
|
+
if (n) {
|
|
822
|
+
let e = this.clone().startOf(n), t = this.clone().endOf(n), i = r.toPlainDateTime(e.temporal), a = r.toPlainDateTime(t.temporal);
|
|
823
|
+
c = r.compare(i, o) >= 0, l = r.compare(a, s) <= 0;
|
|
824
|
+
} else c = r.compare(a, o) >= 0, l = r.compare(a, s) <= 0;
|
|
818
825
|
let u = i[0] === "[", d = i[1] === "]";
|
|
819
|
-
return (u ? c :
|
|
826
|
+
return (u ? c : r.compare(a, o) > 0) && (d ? l : r.compare(a, s) < 0);
|
|
820
827
|
}
|
|
821
828
|
clone() {
|
|
822
829
|
return new e(this.toDate(), this.config);
|
|
823
830
|
}
|
|
824
831
|
startOf(t) {
|
|
825
|
-
let
|
|
832
|
+
let n = r.toPlainDateTime(this.temporal), i = {};
|
|
826
833
|
switch (t) {
|
|
827
834
|
case "year":
|
|
828
835
|
i.month = 1, i.day = 1, i.hour = 0, i.minute = 0, i.second = 0, i.millisecond = 0;
|
|
@@ -844,63 +851,63 @@ var p = class e {
|
|
|
844
851
|
i.millisecond = 0;
|
|
845
852
|
break;
|
|
846
853
|
}
|
|
847
|
-
let a =
|
|
854
|
+
let a = n.with(i);
|
|
848
855
|
return e.fromTemporal(a, this.config);
|
|
849
856
|
}
|
|
850
857
|
endOf(e) {
|
|
851
858
|
return this.startOf(e).add({ [e]: 1 }).subtract({ millisecond: 1 });
|
|
852
859
|
}
|
|
853
860
|
set(t) {
|
|
854
|
-
let
|
|
855
|
-
return e.fromTemporal(
|
|
861
|
+
let n = r.toPlainDateTime(this.temporal).with(t);
|
|
862
|
+
return e.fromTemporal(n, this.config);
|
|
856
863
|
}
|
|
857
864
|
year() {
|
|
858
|
-
return
|
|
865
|
+
return r.toPlainDateTime(this.temporal).year;
|
|
859
866
|
}
|
|
860
867
|
month() {
|
|
861
|
-
return
|
|
868
|
+
return r.toPlainDateTime(this.temporal).month;
|
|
862
869
|
}
|
|
863
870
|
day() {
|
|
864
|
-
return
|
|
871
|
+
return r.toPlainDateTime(this.temporal).day;
|
|
865
872
|
}
|
|
866
873
|
hour() {
|
|
867
|
-
return
|
|
874
|
+
return r.toPlainDateTime(this.temporal).hour;
|
|
868
875
|
}
|
|
869
876
|
minute() {
|
|
870
|
-
return
|
|
877
|
+
return r.toPlainDateTime(this.temporal).minute;
|
|
871
878
|
}
|
|
872
879
|
second() {
|
|
873
|
-
return
|
|
880
|
+
return r.toPlainDateTime(this.temporal).second;
|
|
874
881
|
}
|
|
875
882
|
millisecond() {
|
|
876
|
-
return
|
|
883
|
+
return r.toPlainDateTime(this.temporal).millisecond;
|
|
877
884
|
}
|
|
878
885
|
dayOfWeek() {
|
|
879
|
-
return
|
|
886
|
+
return r.toPlainDateTime(this.temporal).dayOfWeek;
|
|
880
887
|
}
|
|
881
888
|
dayOfYear() {
|
|
882
|
-
return
|
|
889
|
+
return r.toPlainDateTime(this.temporal).dayOfYear;
|
|
883
890
|
}
|
|
884
891
|
weekOfYear() {
|
|
885
|
-
return
|
|
892
|
+
return r.toPlainDateTime(this.temporal).weekOfYear;
|
|
886
893
|
}
|
|
887
894
|
daysInMonth() {
|
|
888
|
-
return
|
|
895
|
+
return r.toPlainDateTime(this.temporal).add({ months: 1 }).with({ day: 1 }).subtract({ days: 1 }).day;
|
|
889
896
|
}
|
|
890
897
|
daysInYear() {
|
|
891
898
|
let t = this.year();
|
|
892
899
|
return e.isLeapYearValue(t) ? 366 : 365;
|
|
893
900
|
}
|
|
894
901
|
inLeapYear() {
|
|
895
|
-
let t =
|
|
902
|
+
let t = r.toPlainDateTime(this.temporal);
|
|
896
903
|
return e.isLeapYearValue(t.year);
|
|
897
904
|
}
|
|
898
|
-
until(t,
|
|
899
|
-
let i =
|
|
905
|
+
until(t, n) {
|
|
906
|
+
let i = r.toPlainDateTime(this.temporal), a = r.toPlainDateTime(t.temporal), o = performance.now();
|
|
900
907
|
try {
|
|
901
908
|
let t = {};
|
|
902
|
-
|
|
903
|
-
let
|
|
909
|
+
n?.largestUnit && (t.largestUnit = n.largestUnit), n?.smallestUnit && (t.smallestUnit = n.smallestUnit);
|
|
910
|
+
let r = a.since(i, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(r), c = i.year, l = a.year, u = [];
|
|
904
911
|
for (let t = c; t <= l; t++) {
|
|
905
912
|
let n = e.isLeapYearValue(t);
|
|
906
913
|
u.push({
|
|
@@ -910,7 +917,7 @@ var p = class e {
|
|
|
910
917
|
});
|
|
911
918
|
}
|
|
912
919
|
let d = this.generateUntilSteps(i, a, s, u), f = performance.now() - o;
|
|
913
|
-
return new
|
|
920
|
+
return new T(s, this.config.locale, {
|
|
914
921
|
startDate: i.toString(),
|
|
915
922
|
endDate: a.toString(),
|
|
916
923
|
steps: d,
|
|
@@ -919,7 +926,7 @@ var p = class e {
|
|
|
919
926
|
calculationTimeMs: f
|
|
920
927
|
});
|
|
921
928
|
} catch {
|
|
922
|
-
return new
|
|
929
|
+
return new T(e.ZERO_DURATION, this.config.locale, {
|
|
923
930
|
startDate: i.toString(),
|
|
924
931
|
endDate: a.toString(),
|
|
925
932
|
steps: ["Calculation failed, returning zero duration"],
|
|
@@ -940,7 +947,7 @@ var p = class e {
|
|
|
940
947
|
return a.push(`Total: approximately ${s.toFixed(2)} days`), a;
|
|
941
948
|
}
|
|
942
949
|
round(e = {}) {
|
|
943
|
-
let { smallestUnit: t = "millisecond", roundingMode:
|
|
950
|
+
let { smallestUnit: t = "millisecond", roundingMode: n = "halfExpand" } = e, i = r.toPlainDateTime(this.temporal), a = {
|
|
944
951
|
year: i.year,
|
|
945
952
|
month: i.month,
|
|
946
953
|
day: i.day,
|
|
@@ -980,12 +987,12 @@ var p = class e {
|
|
|
980
987
|
case "expand": return t > 0;
|
|
981
988
|
default: return t >= 5;
|
|
982
989
|
}
|
|
983
|
-
})(
|
|
990
|
+
})(n, a[o[s + 1]]) && (u += 1), c[l] = u;
|
|
984
991
|
for (let e = s + 1; e < o.length; e++) c[o[e]] = 0;
|
|
985
992
|
return this.set(c);
|
|
986
993
|
}
|
|
987
994
|
toPlainDate() {
|
|
988
|
-
let e =
|
|
995
|
+
let e = r.toPlainDateTime(this.temporal);
|
|
989
996
|
return {
|
|
990
997
|
year: e.year,
|
|
991
998
|
month: e.month,
|
|
@@ -994,7 +1001,7 @@ var p = class e {
|
|
|
994
1001
|
};
|
|
995
1002
|
}
|
|
996
1003
|
toPlainTime() {
|
|
997
|
-
let e =
|
|
1004
|
+
let e = r.toPlainDateTime(this.temporal);
|
|
998
1005
|
return {
|
|
999
1006
|
hour: e.hour,
|
|
1000
1007
|
minute: e.minute,
|
|
@@ -1032,12 +1039,12 @@ var p = class e {
|
|
|
1032
1039
|
endOfDay() {
|
|
1033
1040
|
return this.endOf("day");
|
|
1034
1041
|
}
|
|
1035
|
-
since(t,
|
|
1036
|
-
let i =
|
|
1042
|
+
since(t, n) {
|
|
1043
|
+
let i = r.toPlainDateTime(this.temporal), a = r.toPlainDateTime(t.temporal), o = performance.now();
|
|
1037
1044
|
try {
|
|
1038
1045
|
let t = {};
|
|
1039
|
-
|
|
1040
|
-
let
|
|
1046
|
+
n?.largestUnit && (t.largestUnit = n.largestUnit), n?.smallestUnit && (t.smallestUnit = n.smallestUnit);
|
|
1047
|
+
let r = i.since(a, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(r), c = a.year, l = i.year, u = [];
|
|
1041
1048
|
for (let t = c; t <= l; t++) {
|
|
1042
1049
|
let n = e.isLeapYearValue(t);
|
|
1043
1050
|
u.push({
|
|
@@ -1047,7 +1054,7 @@ var p = class e {
|
|
|
1047
1054
|
});
|
|
1048
1055
|
}
|
|
1049
1056
|
let d = this.generateUntilSteps(a, i, s, u), f = performance.now() - o;
|
|
1050
|
-
return new
|
|
1057
|
+
return new T(s, this.config.locale, {
|
|
1051
1058
|
startDate: a.toString(),
|
|
1052
1059
|
endDate: i.toString(),
|
|
1053
1060
|
steps: d,
|
|
@@ -1056,7 +1063,7 @@ var p = class e {
|
|
|
1056
1063
|
calculationTimeMs: f
|
|
1057
1064
|
});
|
|
1058
1065
|
} catch {
|
|
1059
|
-
return new
|
|
1066
|
+
return new T(e.ZERO_DURATION, this.config.locale, {
|
|
1060
1067
|
startDate: a.toString(),
|
|
1061
1068
|
endDate: i.toString(),
|
|
1062
1069
|
steps: ["Calculation failed, returning zero duration"],
|
|
@@ -1087,7 +1094,7 @@ var p = class e {
|
|
|
1087
1094
|
isYesterday() {
|
|
1088
1095
|
return this.isSame(e.now().subtract({ day: 1 }), "day");
|
|
1089
1096
|
}
|
|
1090
|
-
},
|
|
1097
|
+
}, O = {
|
|
1091
1098
|
en: {
|
|
1092
1099
|
name: "en",
|
|
1093
1100
|
months: [
|
|
@@ -1364,7 +1371,7 @@ var p = class e {
|
|
|
1364
1371
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
1365
1372
|
}
|
|
1366
1373
|
}
|
|
1367
|
-
},
|
|
1374
|
+
}, k = {
|
|
1368
1375
|
es: {
|
|
1369
1376
|
name: "es",
|
|
1370
1377
|
months: [
|
|
@@ -1572,7 +1579,7 @@ var p = class e {
|
|
|
1572
1579
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
1573
1580
|
}
|
|
1574
1581
|
}
|
|
1575
|
-
},
|
|
1582
|
+
}, A = {
|
|
1576
1583
|
fr: {
|
|
1577
1584
|
name: "fr",
|
|
1578
1585
|
months: [
|
|
@@ -1918,7 +1925,7 @@ var p = class e {
|
|
|
1918
1925
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
1919
1926
|
}
|
|
1920
1927
|
}
|
|
1921
|
-
},
|
|
1928
|
+
}, j = {
|
|
1922
1929
|
ru: {
|
|
1923
1930
|
name: "ru",
|
|
1924
1931
|
months: [
|
|
@@ -2195,7 +2202,7 @@ var p = class e {
|
|
|
2195
2202
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
2196
2203
|
}
|
|
2197
2204
|
}
|
|
2198
|
-
},
|
|
2205
|
+
}, ee = {
|
|
2199
2206
|
sv: {
|
|
2200
2207
|
name: "sv",
|
|
2201
2208
|
months: [
|
|
@@ -2472,7 +2479,7 @@ var p = class e {
|
|
|
2472
2479
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
2473
2480
|
}
|
|
2474
2481
|
}
|
|
2475
|
-
},
|
|
2482
|
+
}, te = {
|
|
2476
2483
|
ja: {
|
|
2477
2484
|
name: "ja",
|
|
2478
2485
|
months: [
|
|
@@ -2956,7 +2963,7 @@ var p = class e {
|
|
|
2956
2963
|
rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
|
|
2957
2964
|
}
|
|
2958
2965
|
}
|
|
2959
|
-
},
|
|
2966
|
+
}, M = {
|
|
2960
2967
|
de: {
|
|
2961
2968
|
name: "de",
|
|
2962
2969
|
months: [
|
|
@@ -3857,13 +3864,13 @@ var p = class e {
|
|
|
3857
3864
|
}
|
|
3858
3865
|
}
|
|
3859
3866
|
}, F = {
|
|
3860
|
-
...D,
|
|
3861
3867
|
...O,
|
|
3862
3868
|
...k,
|
|
3863
3869
|
...A,
|
|
3864
3870
|
...j,
|
|
3865
|
-
...M,
|
|
3866
3871
|
...ee,
|
|
3872
|
+
...te,
|
|
3873
|
+
...M,
|
|
3867
3874
|
...N,
|
|
3868
3875
|
...P
|
|
3869
3876
|
};
|
|
@@ -4555,7 +4562,7 @@ var R = 40, z = class {
|
|
|
4555
4562
|
fromMilliseconds: (e) => Z.fromMilliseconds(e)
|
|
4556
4563
|
};
|
|
4557
4564
|
}
|
|
4558
|
-
},
|
|
4565
|
+
}, ne = new Q(), $ = class {
|
|
4559
4566
|
name = "advanced-format";
|
|
4560
4567
|
version = "1.0.0";
|
|
4561
4568
|
install(e) {
|
|
@@ -4682,15 +4689,15 @@ var R = 40, z = class {
|
|
|
4682
4689
|
return "Coordinated Universal Time";
|
|
4683
4690
|
}
|
|
4684
4691
|
}
|
|
4685
|
-
},
|
|
4692
|
+
}, re = new $();
|
|
4686
4693
|
//#endregion
|
|
4687
4694
|
//#region src/index.ts
|
|
4688
|
-
function
|
|
4689
|
-
return new
|
|
4695
|
+
function ie(e, t) {
|
|
4696
|
+
return new D(e, t);
|
|
4690
4697
|
}
|
|
4691
|
-
var
|
|
4692
|
-
|
|
4698
|
+
var ae = "2.4.1";
|
|
4699
|
+
o.getInstance().loadLocales(F);
|
|
4693
4700
|
//#endregion
|
|
4694
|
-
export { F as ALL_LOCALES, $ as AdvancedFormatPlugin, K as BuddhistCalendar, B as CalendarManager, W as ChineseCalendar,
|
|
4701
|
+
export { F as ALL_LOCALES, $ as AdvancedFormatPlugin, K as BuddhistCalendar, B as CalendarManager, W as ChineseCalendar, s as DateFormatter, Z as Duration, Q as DurationPlugin, T as DurationResult, i as EN_LOCALE, a as ES_LOCALE, z as GregorianCalendar, U as HebrewCalendar, H as IslamicCalendar, G as JapaneseCalendar, R as LOCALES_COUNT, o as LocaleManager, m as PluginManager, Y as RelativeTimePlugin, r as TemporalAdapter, D as TimeGuard, E as TimeRange, re as advancedFormatPlugin, V as calendarManager, ne as durationPlugin, L as getAvailableLocales, I as registerAllLocales, X as relativeTimePlugin, ie as timeGuard, ae as version };
|
|
4695
4702
|
|
|
4696
4703
|
//# sourceMappingURL=time-guard.es.js.map
|