@bereasoftware/time-guard 2.1.0 → 2.2.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.
@@ -1,4 +1,4 @@
1
- /*! time-guard v2.1.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.2.0 | (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
4
  var e = null;
@@ -313,13 +313,327 @@ var n = class {
313
313
  let r = this.getPreset(t);
314
314
  return this.format(e, r, n);
315
315
  }
316
- }, s = class e {
316
+ }, s = class {
317
+ _value;
318
+ _tg1;
319
+ _tg2;
320
+ _mode;
321
+ _breakdownData;
322
+ _locale;
323
+ constructor(e, t, n, r = "exact", i, a) {
324
+ this._value = e, this._tg1 = t, this._tg2 = n, this._mode = r, this._breakdownData = i || null, this._locale = a || "en";
325
+ }
326
+ as(e) {
327
+ return this._tg1.diff(this._tg2, e);
328
+ }
329
+ breakdown() {
330
+ return this._breakdownData;
331
+ }
332
+ format(e) {
333
+ let t = e || this._locale;
334
+ if (!this._breakdownData) return `${Math.abs(this._tg1.diff(this._tg2, "day"))} days`;
335
+ let n = [], r = this._breakdownData, i = (e, t, n) => {
336
+ if (e === 0) return null;
337
+ let r = {
338
+ en: {
339
+ year: e === 1 ? "year" : "years",
340
+ month: e === 1 ? "month" : "months",
341
+ week: e === 1 ? "week" : "weeks",
342
+ day: e === 1 ? "day" : "days",
343
+ hour: e === 1 ? "hour" : "hours",
344
+ minute: e === 1 ? "minute" : "minutes",
345
+ second: e === 1 ? "second" : "seconds"
346
+ },
347
+ es: {
348
+ year: e === 1 ? "año" : "años",
349
+ month: e === 1 ? "mes" : "meses",
350
+ week: e === 1 ? "semana" : "semanas",
351
+ day: e === 1 ? "día" : "días",
352
+ hour: e === 1 ? "hora" : "horas",
353
+ minute: e === 1 ? "minuto" : "minutos",
354
+ second: e === 1 ? "segundo" : "segundos"
355
+ },
356
+ fr: {
357
+ year: e === 1 ? "année" : "années",
358
+ month: "mois",
359
+ week: e === 1 ? "semaine" : "semaines",
360
+ day: e === 1 ? "jour" : "jours",
361
+ hour: e === 1 ? "heure" : "heures",
362
+ minute: e === 1 ? "minute" : "minutes",
363
+ second: e === 1 ? "seconde" : "secondes"
364
+ }
365
+ };
366
+ return `${e} ${(r[n] || r.en)[t] || t}`;
367
+ };
368
+ if (r.years !== 0 && n.push(i(r.years, "year", t)), r.months !== 0 && n.push(i(r.months, "month", t)), r.weeks !== 0 && n.push(i(r.weeks, "week", t)), r.days !== 0 && n.push(i(r.days, "day", t)), r.hours !== 0 && n.push(i(r.hours, "hour", t)), r.minutes !== 0 && n.push(i(r.minutes, "minute", t)), r.seconds !== 0 && n.push(i(r.seconds, "second", t)), n.length === 0) return "0 " + (t === "es" ? "segundos" : t === "fr" ? "secondes" : "seconds");
369
+ let a = {
370
+ en: " and ",
371
+ es: " y ",
372
+ fr: " et "
373
+ }[t] || " and ";
374
+ return n.length === 1 ? n[0] : n.slice(0, -1).join(", ") + a + n[n.length - 1];
375
+ }
376
+ getMode() {
377
+ return this._mode;
378
+ }
379
+ valueOf() {
380
+ return this._value;
381
+ }
382
+ toString() {
383
+ return this._mode === "calendar" && this._breakdownData ? this.format() : this._value.toString();
384
+ }
385
+ toJSON() {
386
+ return this._value;
387
+ }
388
+ }, c = class {
389
+ years;
390
+ months;
391
+ weeks;
392
+ days;
393
+ hours;
394
+ minutes;
395
+ seconds;
396
+ milliseconds;
397
+ _locale;
398
+ _startDate;
399
+ _endDate;
400
+ _steps = [];
401
+ _mode = "exact";
402
+ _leapYearFlags = [];
403
+ _calculationTimeMs = 0;
404
+ constructor(e, t = "en", n) {
405
+ this.years = e.years, this.months = e.months, this.weeks = e.weeks, this.days = e.days, this.hours = e.hours, this.minutes = e.minutes, this.seconds = e.seconds, this.milliseconds = e.milliseconds, this._locale = t, n && (this._startDate = n.startDate, this._endDate = n.endDate, this._steps = n.steps || [], this._mode = n.mode || "exact", this._leapYearFlags = n.leapYearFlags || [], this._calculationTimeMs = n.calculationTimeMs || 0);
406
+ }
407
+ humanize(e) {
408
+ let t = e?.locale || this._locale, n = e?.fullBreakdown ?? !1, r = e?.numeric ?? "always", i = [
409
+ {
410
+ unit: "year",
411
+ value: this.years
412
+ },
413
+ {
414
+ unit: "month",
415
+ value: this.months
416
+ },
417
+ {
418
+ unit: "week",
419
+ value: this.weeks
420
+ },
421
+ {
422
+ unit: "day",
423
+ value: this.days
424
+ },
425
+ {
426
+ unit: "hour",
427
+ value: this.hours
428
+ },
429
+ {
430
+ unit: "minute",
431
+ value: this.minutes
432
+ },
433
+ {
434
+ unit: "second",
435
+ value: this.seconds
436
+ },
437
+ {
438
+ unit: "millisecond",
439
+ value: this.milliseconds
440
+ }
441
+ ].filter((e) => e.value > 0);
442
+ if (i.length === 0) return "0 seconds";
443
+ if (!n || i.length === 1) {
444
+ let e = i[0];
445
+ try {
446
+ return new Intl.RelativeTimeFormat(t, {
447
+ numeric: r,
448
+ style: "long"
449
+ }).format(e.value, e.unit);
450
+ } catch {
451
+ return `${e.value} ${this.pluralizeUnit(e.unit, e.value, t)}`;
452
+ }
453
+ }
454
+ let a = {
455
+ en: {
456
+ year: ["year", "years"],
457
+ month: ["month", "months"],
458
+ week: ["week", "weeks"],
459
+ day: ["day", "days"],
460
+ hour: ["hour", "hours"],
461
+ minute: ["minute", "minutes"],
462
+ second: ["second", "seconds"],
463
+ millisecond: ["millisecond", "milliseconds"]
464
+ },
465
+ es: {
466
+ year: ["año", "años"],
467
+ month: ["mes", "meses"],
468
+ week: ["semana", "semanas"],
469
+ day: ["día", "días"],
470
+ hour: ["hora", "horas"],
471
+ minute: ["minuto", "minutos"],
472
+ second: ["segundo", "segundos"],
473
+ millisecond: ["milisegundo", "milisegundos"]
474
+ },
475
+ fr: {
476
+ year: ["année", "années"],
477
+ month: ["mois", "mois"],
478
+ week: ["semaine", "semaines"],
479
+ day: ["jour", "jours"],
480
+ hour: ["heure", "heures"],
481
+ minute: ["minute", "minutes"],
482
+ second: ["seconde", "secondes"],
483
+ millisecond: ["milliseconde", "millisecondes"]
484
+ }
485
+ }, o = a[t] || a.en, s = this.getConjunction(t), c = i.map((e) => {
486
+ let t = (o[e.unit] || [e.unit, e.unit + "s"])[e.value === 1 ? 0 : 1];
487
+ return `${e.value} ${t}`;
488
+ });
489
+ return c.length === 1 ? c[0] : c.length === 2 ? `${c[0]} ${s} ${c[1]}` : c.slice(0, -1).join(", ") + ` ${s} ${c[c.length - 1]}`;
490
+ }
491
+ total(e) {
492
+ let t = 1e3, n = t * 60, r = n * 60, i = r * 24, a = i * 7, o = 365.25, s = o / 12 * i, c = o * i, l = 0;
493
+ switch (l += this.years * c, l += this.months * s, l += this.weeks * a, l += this.days * i, l += this.hours * r, l += this.minutes * n, l += this.seconds * t, l += this.milliseconds, e) {
494
+ case "millisecond": return l;
495
+ case "second": return l / t;
496
+ case "minute": return l / n;
497
+ case "hour": return l / r;
498
+ case "day": return l / i;
499
+ case "week": return l / a;
500
+ case "month": return l / s;
501
+ case "year": return l / c;
502
+ case "microsecond": return l * 1e3;
503
+ case "nanosecond": return l * 1e6;
504
+ default: throw Error(`Unsupported unit: ${e}`);
505
+ }
506
+ }
507
+ toString() {
508
+ return this.humanize({ fullBreakdown: !0 });
509
+ }
510
+ toJSON() {
511
+ return {
512
+ years: this.years,
513
+ months: this.months,
514
+ weeks: this.weeks,
515
+ days: this.days,
516
+ hours: this.hours,
517
+ minutes: this.minutes,
518
+ seconds: this.seconds,
519
+ milliseconds: this.milliseconds
520
+ };
521
+ }
522
+ explain() {
523
+ let e = [...this._steps];
524
+ e.length === 0 && (e = this.generateExplanationSteps());
525
+ let t = [];
526
+ if (this._startDate && this._endDate && t.push(`Calculated duration from ${this._startDate} to ${this._endDate}`), this._leapYearFlags && this._leapYearFlags.length > 0) {
527
+ let e = this._leapYearFlags.filter((e) => e.isLeap).map((e) => e.year);
528
+ e.length > 0 && t.push(`Leap year(s) detected: ${e.join(", ")}`);
529
+ }
530
+ return t.push(`Breakdown: ${this.years} year(s), ${this.months} month(s), ${this.days} day(s)`), t.push(`Mode: ${this._mode} calculation`), {
531
+ input: this._startDate && this._endDate ? [this._startDate, this._endDate] : [],
532
+ steps: e,
533
+ breakdown: {
534
+ years: this.years,
535
+ months: this.months,
536
+ weeks: this.weeks,
537
+ days: this.days,
538
+ hours: this.hours,
539
+ minutes: this.minutes,
540
+ seconds: this.seconds,
541
+ milliseconds: this.milliseconds
542
+ },
543
+ mode: this._mode,
544
+ explanation: t.join(". "),
545
+ locale: this._locale,
546
+ leapYearFlags: this._leapYearFlags.length > 0 ? this._leapYearFlags : void 0,
547
+ metadata: {
548
+ calculationTimeMs: this._calculationTimeMs,
549
+ precision: "day"
550
+ }
551
+ };
552
+ }
553
+ generateExplanationSteps() {
554
+ let e = [];
555
+ if (this._startDate && this._endDate ? e.push(`Input: ${this._startDate} to ${this._endDate}`) : e.push("Duration calculation started"), this.years > 0 && e.push(`Years: ${this.years}`), this.months > 0 && e.push(`Months: ${this.months}`), this.weeks > 0 && e.push(`Weeks: ${this.weeks}`), this.days > 0 && e.push(`Days: ${this.days}`), this.hours > 0 && e.push(`Hours: ${this.hours}`), this.minutes > 0 && e.push(`Minutes: ${this.minutes}`), this.seconds > 0 && e.push(`Seconds: ${this.seconds}`), this.milliseconds > 0 && e.push(`Milliseconds: ${this.milliseconds}`), this._leapYearFlags && this._leapYearFlags.length > 0) for (let t of this._leapYearFlags) t.isLeap && e.push(`${t.year} is a leap year (February has ${t.daysInFebruary} days)`);
556
+ let t = [
557
+ this.years > 0 ? `${this.years}y` : "",
558
+ this.months > 0 ? `${this.months}m` : "",
559
+ this.days > 0 ? `${this.days}d` : "",
560
+ this.hours > 0 ? `${this.hours}h` : "",
561
+ this.minutes > 0 ? `${this.minutes}min` : "",
562
+ this.seconds > 0 ? `${this.seconds}s` : ""
563
+ ].filter((e) => e.length > 0).join(" ");
564
+ return e.push(`Total: ${t || "0"}`), e;
565
+ }
566
+ getConjunction(e) {
567
+ return {
568
+ en: "and",
569
+ es: "y",
570
+ fr: "et",
571
+ de: "und",
572
+ it: "e",
573
+ pt: "e"
574
+ }[e] || "and";
575
+ }
576
+ pluralizeUnit(e, t, n) {
577
+ let r = {
578
+ en: {
579
+ year: ["year", "years"],
580
+ month: ["month", "months"],
581
+ week: ["week", "weeks"],
582
+ day: ["day", "days"],
583
+ hour: ["hour", "hours"],
584
+ minute: ["minute", "minutes"],
585
+ second: ["second", "seconds"],
586
+ millisecond: ["millisecond", "milliseconds"]
587
+ },
588
+ es: {
589
+ year: ["año", "años"],
590
+ month: ["mes", "meses"],
591
+ week: ["semana", "semanas"],
592
+ day: ["día", "días"],
593
+ hour: ["hora", "horas"],
594
+ minute: ["minuto", "minutos"],
595
+ second: ["segundo", "segundos"],
596
+ millisecond: ["milisegundo", "milisegundos"]
597
+ },
598
+ fr: {
599
+ year: ["année", "années"],
600
+ month: ["mois", "mois"],
601
+ week: ["semaine", "semaines"],
602
+ day: ["jour", "jours"],
603
+ hour: ["heure", "heures"],
604
+ minute: ["minute", "minutes"],
605
+ second: ["seconde", "secondes"],
606
+ millisecond: ["milliseconde", "millisecondes"]
607
+ }
608
+ };
609
+ return ((r[n] || r.en)[e] || [e, e + "s"])[t === 1 ? 0 : 1];
610
+ }
611
+ }, l = class {
612
+ _start;
613
+ _end;
614
+ constructor(e, t) {
615
+ this._start = e, this._end = t;
616
+ }
617
+ toDuration() {
618
+ return u.between(this._start, this._end);
619
+ }
620
+ inMonths() {
621
+ return this.toDuration().total("month");
622
+ }
623
+ humanize(e) {
624
+ return this.toDuration().humanize(e);
625
+ }
626
+ in(e) {
627
+ return this.toDuration().total(e);
628
+ }
629
+ }, u = class e {
317
630
  temporal;
318
631
  config;
319
632
  formatterInstance;
320
633
  static ZERO_DURATION = {
321
634
  years: 0,
322
635
  months: 0,
636
+ weeks: 0,
323
637
  days: 0,
324
638
  hours: 0,
325
639
  minutes: 0,
@@ -333,6 +647,7 @@ var n = class {
333
647
  return {
334
648
  years: Math.floor(e.years || 0),
335
649
  months: Math.floor(e.months || 0),
650
+ weeks: Math.floor(e.weeks || 0),
336
651
  days: Math.floor(e.days || 0),
337
652
  hours: Math.floor(e.hours || 0),
338
653
  minutes: Math.floor(e.minutes || 0),
@@ -359,6 +674,13 @@ var n = class {
359
674
  let r = new e(void 0, n);
360
675
  return r.temporal = t, r;
361
676
  }
677
+ static between(e, t) {
678
+ let r = n.toPlainDateTime(e.temporal), i = n.toPlainDateTime(t.temporal), [a, o] = n.compare(r, i) <= 0 ? [e, t] : [t, e];
679
+ return a.until(o);
680
+ }
681
+ static range(t, n) {
682
+ return new l(t instanceof e ? t : new e(t), n instanceof e ? n : new e(n));
683
+ }
362
684
  toTemporal() {
363
685
  return this.temporal;
364
686
  }
@@ -433,7 +755,7 @@ var n = class {
433
755
  t[e] = n ? -n : 0;
434
756
  }), this.add(t);
435
757
  }
436
- diff(e, t = "millisecond") {
758
+ diff(e, t) {
437
759
  let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(e.temporal), a = {
438
760
  year: "years",
439
761
  month: "months",
@@ -445,8 +767,38 @@ var n = class {
445
767
  millisecond: "milliseconds",
446
768
  microsecond: "microseconds",
447
769
  nanosecond: "nanoseconds"
448
- }, o = r.since(i), s = a[t];
449
- return Math.round(o[s] || 0);
770
+ };
771
+ if (typeof t == "string") {
772
+ let e = t, n = a[e], o = r.since(i, { smallestUnit: e });
773
+ return Math.round(o[n] || 0);
774
+ }
775
+ let o = t || {}, c = o.mode || "exact", l = o.unit || "millisecond", u = o.locale || this.config.locale;
776
+ if (c === "exact") {
777
+ let n = a[l], o = r.since(i, { smallestUnit: l }), d = Math.round(o[n] || 0);
778
+ if (t === void 0 || typeof t == "object") {
779
+ 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);
780
+ return new s(Math.round(t), this, e, c, void 0, u);
781
+ }
782
+ return d;
783
+ }
784
+ if (c === "calendar") {
785
+ let t = r.since(i, {
786
+ largestUnit: "month",
787
+ smallestUnit: "millisecond"
788
+ }), n = {
789
+ years: Math.floor(t.years || 0),
790
+ months: Math.floor(t.months || 0),
791
+ weeks: Math.floor(t.weeks || 0),
792
+ days: Math.floor(t.days || 0),
793
+ hours: Math.floor(t.hours || 0),
794
+ minutes: Math.floor(t.minutes || 0),
795
+ seconds: Math.floor(t.seconds || 0),
796
+ milliseconds: Math.floor(t.milliseconds || 0)
797
+ }, 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);
798
+ return new s(Math.round(a), this, e, c, n, u);
799
+ }
800
+ let d = r.since(i, { smallestUnit: "millisecond" }), f = (d.years || 0) * 365.25 * 24 * 60 * 60 * 1e3 + (d.months || 0) * 30.44 * 24 * 60 * 60 * 1e3 + (d.weeks || 0) * 7 * 24 * 60 * 60 * 1e3 + (d.days || 0) * 24 * 60 * 60 * 1e3 + (d.hours || 0) * 60 * 60 * 1e3 + (d.minutes || 0) * 60 * 1e3 + (d.seconds || 0) * 1e3 + (d.milliseconds || 0);
801
+ return new s(Math.round(f), this, e, c, void 0, u);
450
802
  }
451
803
  isBefore(e) {
452
804
  let t = n.toPlainDateTime(this.temporal), r = n.toPlainDateTime(e.temporal);
@@ -555,14 +907,49 @@ var n = class {
555
907
  let t = n.toPlainDateTime(this.temporal);
556
908
  return e.isLeapYearValue(t.year);
557
909
  }
558
- until(t) {
559
- let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(t.temporal);
910
+ until(t, r) {
911
+ let i = n.toPlainDateTime(this.temporal), a = n.toPlainDateTime(t.temporal), o = performance.now();
560
912
  try {
561
- let t = i.since(r);
562
- return e.toDurationParts(t);
913
+ let t = {};
914
+ r?.largestUnit && (t.largestUnit = r.largestUnit), r?.smallestUnit && (t.smallestUnit = r.smallestUnit);
915
+ let n = a.since(i, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(n), l = i.year, u = a.year, d = [];
916
+ for (let t = l; t <= u; t++) {
917
+ let n = e.isLeapYearValue(t);
918
+ d.push({
919
+ year: t,
920
+ isLeap: n,
921
+ daysInFebruary: n ? 29 : 28
922
+ });
923
+ }
924
+ let f = this.generateUntilSteps(i, a, s, d), p = performance.now() - o;
925
+ return new c(s, this.config.locale, {
926
+ startDate: i.toString(),
927
+ endDate: a.toString(),
928
+ steps: f,
929
+ mode: "exact",
930
+ leapYearFlags: d.filter((e) => e.isLeap),
931
+ calculationTimeMs: p
932
+ });
563
933
  } catch {
564
- return { ...e.ZERO_DURATION };
934
+ return new c(e.ZERO_DURATION, this.config.locale, {
935
+ startDate: i.toString(),
936
+ endDate: a.toString(),
937
+ steps: ["Calculation failed, returning zero duration"],
938
+ mode: "estimated"
939
+ });
940
+ }
941
+ }
942
+ generateUntilSteps(t, n, r, i) {
943
+ let a = [];
944
+ a.push(`Parsed dates: ${t.year}-${String(t.month).padStart(2, "0")}-${String(t.day).padStart(2, "0")} (day ${t.dayOfYear} of ${e.isLeapYearValue(t.year) ? 366 : 365})`), a.push(`to ${n.year}-${String(n.month).padStart(2, "0")}-${String(n.day).padStart(2, "0")} (day ${n.dayOfYear} of ${e.isLeapYearValue(n.year) ? 366 : 365})`);
945
+ let o = i.filter((e) => e.isLeap);
946
+ if (o.length > 0) for (let e of o) a.push(`${e.year} is a leap year (February has ${e.daysInFebruary} days)`);
947
+ if (r.years > 0 && a.push(`Years: ${r.years}`), r.months > 0 && a.push(`Months: ${r.months}`), r.days > 0 && a.push(`Days: ${r.days}`), r.hours > 0 || r.minutes > 0 || r.seconds > 0) {
948
+ let e = [];
949
+ r.hours > 0 && e.push(`${r.hours}h`), r.minutes > 0 && e.push(`${r.minutes}m`), r.seconds > 0 && e.push(`${r.seconds}s`), a.push(`Time: ${e.join(" ")}`);
565
950
  }
951
+ let s = r.years * 365.25 + r.months * 30.4375 + r.days + r.hours / 24;
952
+ return a.push(`Total: approximately ${s.toFixed(2)} days`), a;
566
953
  }
567
954
  round(e = {}) {
568
955
  let { smallestUnit: t = "millisecond", roundingMode: r = "halfExpand" } = e, i = n.toPlainDateTime(this.temporal), a = {
@@ -657,13 +1044,36 @@ var n = class {
657
1044
  endOfDay() {
658
1045
  return this.endOf("day");
659
1046
  }
660
- since(t) {
661
- let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(t.temporal);
1047
+ since(t, r) {
1048
+ let i = n.toPlainDateTime(this.temporal), a = n.toPlainDateTime(t.temporal), o = performance.now();
662
1049
  try {
663
- let t = r.since(i);
664
- return e.toDurationParts(t);
1050
+ let t = {};
1051
+ r?.largestUnit && (t.largestUnit = r.largestUnit), r?.smallestUnit && (t.smallestUnit = r.smallestUnit);
1052
+ let n = i.since(a, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(n), l = a.year, u = i.year, d = [];
1053
+ for (let t = l; t <= u; t++) {
1054
+ let n = e.isLeapYearValue(t);
1055
+ d.push({
1056
+ year: t,
1057
+ isLeap: n,
1058
+ daysInFebruary: n ? 29 : 28
1059
+ });
1060
+ }
1061
+ let f = this.generateUntilSteps(a, i, s, d), p = performance.now() - o;
1062
+ return new c(s, this.config.locale, {
1063
+ startDate: a.toString(),
1064
+ endDate: i.toString(),
1065
+ steps: f,
1066
+ mode: "exact",
1067
+ leapYearFlags: d.filter((e) => e.isLeap),
1068
+ calculationTimeMs: p
1069
+ });
665
1070
  } catch {
666
- return { ...e.ZERO_DURATION };
1071
+ return new c(e.ZERO_DURATION, this.config.locale, {
1072
+ startDate: a.toString(),
1073
+ endDate: i.toString(),
1074
+ steps: ["Calculation failed, returning zero duration"],
1075
+ mode: "estimated"
1076
+ });
667
1077
  }
668
1078
  }
669
1079
  toDurationString(t) {
@@ -689,7 +1099,7 @@ var n = class {
689
1099
  isYesterday() {
690
1100
  return this.isSame(e.now().subtract({ day: 1 }), "day");
691
1101
  }
692
- }, c = {
1102
+ }, d = {
693
1103
  name: "en",
694
1104
  months: [
695
1105
  "January",
@@ -757,7 +1167,7 @@ var n = class {
757
1167
  datetime: "YYYY-MM-DD HH:mm:ss",
758
1168
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
759
1169
  }
760
- }, l = {
1170
+ }, f = {
761
1171
  name: "en-au",
762
1172
  months: [
763
1173
  "January",
@@ -825,7 +1235,7 @@ var n = class {
825
1235
  datetime: "DD/MM/YYYY HH:mm:ss",
826
1236
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
827
1237
  }
828
- }, u = {
1238
+ }, p = {
829
1239
  name: "en-gb",
830
1240
  months: [
831
1241
  "January",
@@ -893,7 +1303,7 @@ var n = class {
893
1303
  datetime: "DD/MM/YYYY HH:mm:ss",
894
1304
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
895
1305
  }
896
- }, d = {
1306
+ }, m = {
897
1307
  name: "en-ca",
898
1308
  months: [
899
1309
  "January",
@@ -961,12 +1371,12 @@ var n = class {
961
1371
  datetime: "YYYY-MM-DD HH:mm:ss",
962
1372
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
963
1373
  }
964
- }, f = {
965
- en: c,
966
- "en-au": l,
967
- "en-gb": u,
968
- "en-ca": d
969
- }, p = {
1374
+ }, ee = {
1375
+ en: d,
1376
+ "en-au": f,
1377
+ "en-gb": p,
1378
+ "en-ca": m
1379
+ }, h = {
970
1380
  name: "es",
971
1381
  months: [
972
1382
  "Enero",
@@ -1034,7 +1444,7 @@ var n = class {
1034
1444
  datetime: "DD/MM/YYYY HH:mm:ss",
1035
1445
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1036
1446
  }
1037
- }, m = {
1447
+ }, g = {
1038
1448
  name: "es-mx",
1039
1449
  months: [
1040
1450
  "Enero",
@@ -1102,7 +1512,7 @@ var n = class {
1102
1512
  datetime: "DD/MM/YYYY HH:mm:ss",
1103
1513
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1104
1514
  }
1105
- }, h = {
1515
+ }, _ = {
1106
1516
  name: "es-us",
1107
1517
  months: [
1108
1518
  "Enero",
@@ -1170,11 +1580,11 @@ var n = class {
1170
1580
  datetime: "MM/DD/YYYY HH:mm:ss",
1171
1581
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1172
1582
  }
1173
- }, g = {
1174
- es: p,
1175
- "es-mx": m,
1176
- "es-us": h
1177
- }, _ = {
1583
+ }, v = {
1584
+ es: h,
1585
+ "es-mx": g,
1586
+ "es-us": _
1587
+ }, te = {
1178
1588
  name: "fr",
1179
1589
  months: [
1180
1590
  "janvier",
@@ -1242,7 +1652,7 @@ var n = class {
1242
1652
  datetime: "DD/MM/YYYY HH:mm:ss",
1243
1653
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1244
1654
  }
1245
- }, v = {
1655
+ }, ne = {
1246
1656
  name: "it",
1247
1657
  months: [
1248
1658
  "gennaio",
@@ -1310,7 +1720,7 @@ var n = class {
1310
1720
  datetime: "DD/MM/YYYY HH:mm:ss",
1311
1721
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1312
1722
  }
1313
- }, y = {
1723
+ }, re = {
1314
1724
  name: "pt",
1315
1725
  months: [
1316
1726
  "janeiro",
@@ -1378,7 +1788,7 @@ var n = class {
1378
1788
  datetime: "DD/MM/YYYY HH:mm:ss",
1379
1789
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1380
1790
  }
1381
- }, b = {
1791
+ }, y = {
1382
1792
  name: "pt-br",
1383
1793
  months: [
1384
1794
  "janeiro",
@@ -1446,7 +1856,7 @@ var n = class {
1446
1856
  datetime: "DD/MM/YYYY HH:mm:ss",
1447
1857
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1448
1858
  }
1449
- }, ee = {
1859
+ }, b = {
1450
1860
  name: "ro",
1451
1861
  months: [
1452
1862
  "ianuarie",
@@ -1515,11 +1925,11 @@ var n = class {
1515
1925
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1516
1926
  }
1517
1927
  }, x = {
1518
- fr: _,
1519
- it: v,
1520
- pt: y,
1521
- "pt-br": b,
1522
- ro: ee
1928
+ fr: te,
1929
+ it: ne,
1930
+ pt: re,
1931
+ "pt-br": y,
1932
+ ro: b
1523
1933
  }, S = {
1524
1934
  ru: {
1525
1935
  name: "ru",
@@ -3459,8 +3869,8 @@ var n = class {
3459
3869
  }
3460
3870
  }
3461
3871
  }, F = {
3462
- ...f,
3463
- ...g,
3872
+ ...ee,
3873
+ ...v,
3464
3874
  ...x,
3465
3875
  ...S,
3466
3876
  ...C,
@@ -3469,19 +3879,19 @@ var n = class {
3469
3879
  ...N,
3470
3880
  ...P
3471
3881
  };
3472
- function te(e) {
3882
+ function I(e) {
3473
3883
  e instanceof Map ? Object.entries(F).forEach(([t, n]) => {
3474
3884
  e.set(t, n);
3475
3885
  }) : Object.entries(F).forEach(([t, n]) => {
3476
3886
  e[t] = n;
3477
3887
  });
3478
3888
  }
3479
- function I() {
3889
+ function L() {
3480
3890
  let e = Object.keys(F);
3481
3891
  for (; e.length < 40;) e.push(`locale-${e.length + 1}`);
3482
3892
  return e;
3483
3893
  }
3484
- var L = 40, R = class {
3894
+ var R = 40, z = class {
3485
3895
  id = "gregory";
3486
3896
  name = "Gregorian Calendar";
3487
3897
  locale = "en";
@@ -3559,12 +3969,12 @@ var L = 40, R = class {
3559
3969
  daysInYear(e) {
3560
3970
  return this.isLeapYear(e) ? 366 : 365;
3561
3971
  }
3562
- }, z = class e {
3972
+ }, B = class e {
3563
3973
  static instance;
3564
3974
  calendars = /* @__PURE__ */ new Map();
3565
3975
  defaultCalendar = "gregory";
3566
3976
  constructor() {
3567
- this.register(new R());
3977
+ this.register(new z());
3568
3978
  }
3569
3979
  static getInstance() {
3570
3980
  return e.instance ||= new e(), e.instance;
@@ -3586,7 +3996,7 @@ var L = 40, R = class {
3586
3996
  if (!e) throw Error(`Default calendar '${this.defaultCalendar}' not found`);
3587
3997
  return e;
3588
3998
  }
3589
- }, B = z.getInstance(), V = class {
3999
+ }, V = B.getInstance(), H = class {
3590
4000
  id = "islamic";
3591
4001
  name = "Islamic Calendar (Hijri)";
3592
4002
  locale = "ar";
@@ -3647,7 +4057,7 @@ var L = 40, R = class {
3647
4057
  daysInYear(e) {
3648
4058
  return this.isLeapYear(e) ? 355 : 354;
3649
4059
  }
3650
- }, H = class {
4060
+ }, U = class {
3651
4061
  id = "hebrew";
3652
4062
  name = "Hebrew Calendar";
3653
4063
  locale = "he";
@@ -3717,7 +4127,7 @@ var L = 40, R = class {
3717
4127
  daysInYear(e) {
3718
4128
  return this.isLeapYear(e) ? 384 : 354;
3719
4129
  }
3720
- }, U = class {
4130
+ }, W = class {
3721
4131
  id = "chinese";
3722
4132
  name = "Chinese Calendar";
3723
4133
  locale = "zh";
@@ -3783,7 +4193,7 @@ var L = 40, R = class {
3783
4193
  getZodiacSign(e) {
3784
4194
  return this.terrestrialBranches[e % 12];
3785
4195
  }
3786
- }, W = class {
4196
+ }, G = class {
3787
4197
  id = "japanese";
3788
4198
  name = "Japanese Calendar";
3789
4199
  locale = "ja";
@@ -3845,7 +4255,7 @@ var L = 40, R = class {
3845
4255
  daysInYear(e) {
3846
4256
  return this.isLeapYear(e) ? 366 : 365;
3847
4257
  }
3848
- }, G = class {
4258
+ }, K = class {
3849
4259
  id = "buddhist";
3850
4260
  name = "Buddhist Calendar";
3851
4261
  locale = "th";
@@ -3900,7 +4310,7 @@ var L = 40, R = class {
3900
4310
  daysInYear(e) {
3901
4311
  return this.isLeapYear(e) ? 366 : 365;
3902
4312
  }
3903
- }, K = class e {
4313
+ }, q = class e {
3904
4314
  static instance;
3905
4315
  plugins = /* @__PURE__ */ new Map();
3906
4316
  static getInstance() {
@@ -3940,7 +4350,7 @@ var L = 40, R = class {
3940
4350
  throw console.error(`Failed to register plugin "${e.name}":`, t), Error(`Failed to register plugin "${e.name}": ${t instanceof Error ? t.message : String(t)}`);
3941
4351
  }
3942
4352
  }
3943
- }, q = [
4353
+ }, J = [
3944
4354
  {
3945
4355
  l: "s",
3946
4356
  r: 44,
@@ -3990,7 +4400,7 @@ var L = 40, R = class {
3990
4400
  l: "yy",
3991
4401
  d: "year"
3992
4402
  }
3993
- ], J = {
4403
+ ], Y = {
3994
4404
  future: "in %s",
3995
4405
  past: "%s ago",
3996
4406
  s: "a few seconds",
@@ -4004,16 +4414,16 @@ var L = 40, R = class {
4004
4414
  MM: "%d months",
4005
4415
  y: "a year",
4006
4416
  yy: "%d years"
4007
- }, Y = class {
4417
+ }, X = class {
4008
4418
  name = "relative-time";
4009
4419
  version = "1.0.0";
4010
4420
  config;
4011
4421
  formats;
4012
4422
  constructor(e) {
4013
4423
  this.config = {
4014
- thresholds: e?.thresholds || q,
4424
+ thresholds: e?.thresholds || J,
4015
4425
  rounding: e?.rounding || Math.round
4016
- }, this.formats = J;
4426
+ }, this.formats = Y;
4017
4427
  }
4018
4428
  install(e) {
4019
4429
  let t = this;
@@ -4030,7 +4440,7 @@ var L = 40, R = class {
4030
4440
  return n ? o : (a ? this.formats.future : this.formats.past).replace("%s", o);
4031
4441
  }
4032
4442
  getRelativeTimeString(e) {
4033
- let t = this.config.thresholds || q, n = this.config.rounding || Math.round;
4443
+ let t = this.config.thresholds || J, n = this.config.rounding || Math.round;
4034
4444
  for (let r = 0; r < t.length; r++) {
4035
4445
  let i = t[r];
4036
4446
  if (r + 1 < t.length && t[r + 1] && i.r && e < i.r * 1e3) continue;
@@ -4057,7 +4467,7 @@ var L = 40, R = class {
4057
4467
  getFormats() {
4058
4468
  return { ...this.formats };
4059
4469
  }
4060
- }, X = new Y(), Z = class e {
4470
+ }, ie = new X(), Z = class e {
4061
4471
  years = 0;
4062
4472
  months = 0;
4063
4473
  weeks = 0;
@@ -4197,7 +4607,7 @@ var L = 40, R = class {
4197
4607
  fromMilliseconds: (e) => Z.fromMilliseconds(e)
4198
4608
  };
4199
4609
  }
4200
- }, ne = new Q(), $ = class {
4610
+ }, ae = new Q(), $ = class {
4201
4611
  name = "advanced-format";
4202
4612
  version = "1.0.0";
4203
4613
  install(e) {
@@ -4324,13 +4734,13 @@ var L = 40, R = class {
4324
4734
  return "Coordinated Universal Time";
4325
4735
  }
4326
4736
  }
4327
- }, re = new $();
4737
+ }, oe = new $();
4328
4738
  //#endregion
4329
4739
  //#region src/index.ts
4330
- function ie(e, t) {
4331
- return new s(e, t);
4740
+ function se(e, t) {
4741
+ return new u(e, t);
4332
4742
  }
4333
- var ae = "2.1.0";
4743
+ var ce = "2.2.0";
4334
4744
  a.getInstance().loadLocales(F);
4335
4745
  //#endregion
4336
- export { F as ALL_LOCALES, $ as AdvancedFormatPlugin, G as BuddhistCalendar, z as CalendarManager, U as ChineseCalendar, o as DateFormatter, Z as Duration, Q as DurationPlugin, r as EN_LOCALE, i as ES_LOCALE, R as GregorianCalendar, H as HebrewCalendar, V as IslamicCalendar, W as JapaneseCalendar, L as LOCALES_COUNT, a as LocaleManager, K as PluginManager, Y as RelativeTimePlugin, n as TemporalAdapter, s as TimeGuard, re as advancedFormatPlugin, B as calendarManager, ne as durationPlugin, I as getAvailableLocales, te as registerAllLocales, X as relativeTimePlugin, ie as timeGuard, ae as version };
4746
+ export { F as ALL_LOCALES, $ as AdvancedFormatPlugin, K as BuddhistCalendar, B as CalendarManager, W as ChineseCalendar, o as DateFormatter, Z as Duration, Q as DurationPlugin, c as DurationResult, r as EN_LOCALE, i as ES_LOCALE, z as GregorianCalendar, U as HebrewCalendar, H as IslamicCalendar, G as JapaneseCalendar, R as LOCALES_COUNT, a as LocaleManager, q as PluginManager, X as RelativeTimePlugin, n as TemporalAdapter, u as TimeGuard, l as TimeRange, oe as advancedFormatPlugin, V as calendarManager, ae as durationPlugin, L as getAvailableLocales, I as registerAllLocales, ie as relativeTimePlugin, se as timeGuard, ce as version };