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