@bereasoftware/time-guard 2.1.0 → 2.2.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.
@@ -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.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
4
  var e = null;
@@ -314,12 +314,366 @@ var n = class {
314
314
  return this.format(e, r, n);
315
315
  }
316
316
  }, s = class e {
317
+ static instance;
318
+ plugins = /* @__PURE__ */ new Map();
319
+ static getInstance() {
320
+ return e.instance ||= new e(), e.instance;
321
+ }
322
+ static use(t, n, r) {
323
+ e.getInstance().register(t, n, r);
324
+ }
325
+ static useMultiple(t, n, r) {
326
+ let i = e.getInstance();
327
+ t.forEach((e) => i.register(e, n, r));
328
+ }
329
+ static getPlugin(t) {
330
+ return e.getInstance().plugins.get(t);
331
+ }
332
+ static hasPlugin(t) {
333
+ return e.getInstance().plugins.has(t);
334
+ }
335
+ static listPlugins() {
336
+ let t = e.getInstance();
337
+ return Array.from(t.plugins.keys());
338
+ }
339
+ static unuse(t) {
340
+ return e.getInstance().plugins.delete(t);
341
+ }
342
+ static clear() {
343
+ e.getInstance().plugins.clear();
344
+ }
345
+ register(e, t, n) {
346
+ if (this.plugins.has(e.name)) {
347
+ console.warn(`Plugin "${e.name}" is already registered. Skipping...`);
348
+ return;
349
+ }
350
+ try {
351
+ e.install(t, n), this.plugins.set(e.name, e), console.debug(`Plugin "${e.name}" v${e.version} registered successfully`);
352
+ } catch (t) {
353
+ throw console.error(`Failed to register plugin "${e.name}":`, t), Error(`Failed to register plugin "${e.name}": ${t instanceof Error ? t.message : String(t)}`);
354
+ }
355
+ }
356
+ }, c = class {
357
+ _value;
358
+ _tg1;
359
+ _tg2;
360
+ _mode;
361
+ _breakdownData;
362
+ _locale;
363
+ constructor(e, t, n, r = "exact", i, a) {
364
+ this._value = e, this._tg1 = t, this._tg2 = n, this._mode = r, this._breakdownData = i || null, this._locale = a || "en";
365
+ }
366
+ as(e) {
367
+ return this._tg1.diff(this._tg2, e);
368
+ }
369
+ breakdown() {
370
+ return this._breakdownData;
371
+ }
372
+ format(e) {
373
+ let t = e || this._locale;
374
+ if (!this._breakdownData) return `${Math.abs(this._tg1.diff(this._tg2, "day"))} days`;
375
+ let n = [], r = this._breakdownData, i = (e, t, n) => {
376
+ if (e === 0) return null;
377
+ let r = {
378
+ en: {
379
+ year: e === 1 ? "year" : "years",
380
+ month: e === 1 ? "month" : "months",
381
+ week: e === 1 ? "week" : "weeks",
382
+ day: e === 1 ? "day" : "days",
383
+ hour: e === 1 ? "hour" : "hours",
384
+ minute: e === 1 ? "minute" : "minutes",
385
+ second: e === 1 ? "second" : "seconds"
386
+ },
387
+ es: {
388
+ year: e === 1 ? "año" : "años",
389
+ month: e === 1 ? "mes" : "meses",
390
+ week: e === 1 ? "semana" : "semanas",
391
+ day: e === 1 ? "día" : "días",
392
+ hour: e === 1 ? "hora" : "horas",
393
+ minute: e === 1 ? "minuto" : "minutos",
394
+ second: e === 1 ? "segundo" : "segundos"
395
+ },
396
+ fr: {
397
+ year: e === 1 ? "année" : "années",
398
+ month: "mois",
399
+ week: e === 1 ? "semaine" : "semaines",
400
+ day: e === 1 ? "jour" : "jours",
401
+ hour: e === 1 ? "heure" : "heures",
402
+ minute: e === 1 ? "minute" : "minutes",
403
+ second: e === 1 ? "seconde" : "secondes"
404
+ }
405
+ };
406
+ return `${e} ${(r[n] || r.en)[t] || t}`;
407
+ };
408
+ 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");
409
+ let a = {
410
+ en: " and ",
411
+ es: " y ",
412
+ fr: " et "
413
+ }[t] || " and ";
414
+ return n.length === 1 ? n[0] : n.slice(0, -1).join(", ") + a + n[n.length - 1];
415
+ }
416
+ getMode() {
417
+ return this._mode;
418
+ }
419
+ valueOf() {
420
+ return this._value;
421
+ }
422
+ toString() {
423
+ return this._mode === "calendar" && this._breakdownData ? this.format() : this._value.toString();
424
+ }
425
+ toJSON() {
426
+ return this._value;
427
+ }
428
+ }, l = class {
429
+ years;
430
+ months;
431
+ weeks;
432
+ days;
433
+ hours;
434
+ minutes;
435
+ seconds;
436
+ milliseconds;
437
+ _locale;
438
+ _startDate;
439
+ _endDate;
440
+ _steps = [];
441
+ _mode = "exact";
442
+ _leapYearFlags = [];
443
+ _calculationTimeMs = 0;
444
+ constructor(e, t = "en", n) {
445
+ 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);
446
+ }
447
+ humanize(e) {
448
+ let t = e?.locale || this._locale, n = e?.fullBreakdown ?? !1, r = e?.numeric ?? "always", i = [
449
+ {
450
+ unit: "year",
451
+ value: this.years
452
+ },
453
+ {
454
+ unit: "month",
455
+ value: this.months
456
+ },
457
+ {
458
+ unit: "week",
459
+ value: this.weeks
460
+ },
461
+ {
462
+ unit: "day",
463
+ value: this.days
464
+ },
465
+ {
466
+ unit: "hour",
467
+ value: this.hours
468
+ },
469
+ {
470
+ unit: "minute",
471
+ value: this.minutes
472
+ },
473
+ {
474
+ unit: "second",
475
+ value: this.seconds
476
+ },
477
+ {
478
+ unit: "millisecond",
479
+ value: this.milliseconds
480
+ }
481
+ ].filter((e) => e.value > 0);
482
+ if (i.length === 0) return "0 seconds";
483
+ if (!n || i.length === 1) {
484
+ let e = i[0];
485
+ try {
486
+ return new Intl.RelativeTimeFormat(t, {
487
+ numeric: r,
488
+ style: "long"
489
+ }).format(e.value, e.unit);
490
+ } catch {
491
+ return `${e.value} ${this.pluralizeUnit(e.unit, e.value, t)}`;
492
+ }
493
+ }
494
+ let a = {
495
+ en: {
496
+ year: ["year", "years"],
497
+ month: ["month", "months"],
498
+ week: ["week", "weeks"],
499
+ day: ["day", "days"],
500
+ hour: ["hour", "hours"],
501
+ minute: ["minute", "minutes"],
502
+ second: ["second", "seconds"],
503
+ millisecond: ["millisecond", "milliseconds"]
504
+ },
505
+ es: {
506
+ year: ["año", "años"],
507
+ month: ["mes", "meses"],
508
+ week: ["semana", "semanas"],
509
+ day: ["día", "días"],
510
+ hour: ["hora", "horas"],
511
+ minute: ["minuto", "minutos"],
512
+ second: ["segundo", "segundos"],
513
+ millisecond: ["milisegundo", "milisegundos"]
514
+ },
515
+ fr: {
516
+ year: ["année", "années"],
517
+ month: ["mois", "mois"],
518
+ week: ["semaine", "semaines"],
519
+ day: ["jour", "jours"],
520
+ hour: ["heure", "heures"],
521
+ minute: ["minute", "minutes"],
522
+ second: ["seconde", "secondes"],
523
+ millisecond: ["milliseconde", "millisecondes"]
524
+ }
525
+ }, o = a[t] || a.en, s = this.getConjunction(t), c = i.map((e) => {
526
+ let t = (o[e.unit] || [e.unit, e.unit + "s"])[e.value === 1 ? 0 : 1];
527
+ return `${e.value} ${t}`;
528
+ });
529
+ return c.length === 1 ? c[0] : c.length === 2 ? `${c[0]} ${s} ${c[1]}` : c.slice(0, -1).join(", ") + ` ${s} ${c[c.length - 1]}`;
530
+ }
531
+ total(e) {
532
+ 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;
533
+ 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) {
534
+ case "millisecond": return l;
535
+ case "second": return l / t;
536
+ case "minute": return l / n;
537
+ case "hour": return l / r;
538
+ case "day": return l / i;
539
+ case "week": return l / a;
540
+ case "month": return l / s;
541
+ case "year": return l / c;
542
+ case "microsecond": return l * 1e3;
543
+ case "nanosecond": return l * 1e6;
544
+ default: throw Error(`Unsupported unit: ${e}`);
545
+ }
546
+ }
547
+ toString() {
548
+ return this.humanize({ fullBreakdown: !0 });
549
+ }
550
+ toJSON() {
551
+ return {
552
+ years: this.years,
553
+ months: this.months,
554
+ weeks: this.weeks,
555
+ days: this.days,
556
+ hours: this.hours,
557
+ minutes: this.minutes,
558
+ seconds: this.seconds,
559
+ milliseconds: this.milliseconds
560
+ };
561
+ }
562
+ explain() {
563
+ let e = [...this._steps];
564
+ e.length === 0 && (e = this.generateExplanationSteps());
565
+ let t = [];
566
+ if (this._startDate && this._endDate && t.push(`Calculated duration from ${this._startDate} to ${this._endDate}`), this._leapYearFlags && this._leapYearFlags.length > 0) {
567
+ let e = this._leapYearFlags.filter((e) => e.isLeap).map((e) => e.year);
568
+ e.length > 0 && t.push(`Leap year(s) detected: ${e.join(", ")}`);
569
+ }
570
+ return t.push(`Breakdown: ${this.years} year(s), ${this.months} month(s), ${this.days} day(s)`), t.push(`Mode: ${this._mode} calculation`), {
571
+ input: this._startDate && this._endDate ? [this._startDate, this._endDate] : [],
572
+ steps: e,
573
+ breakdown: {
574
+ years: this.years,
575
+ months: this.months,
576
+ weeks: this.weeks,
577
+ days: this.days,
578
+ hours: this.hours,
579
+ minutes: this.minutes,
580
+ seconds: this.seconds,
581
+ milliseconds: this.milliseconds
582
+ },
583
+ mode: this._mode,
584
+ explanation: t.join(". "),
585
+ locale: this._locale,
586
+ leapYearFlags: this._leapYearFlags.length > 0 ? this._leapYearFlags : void 0,
587
+ metadata: {
588
+ calculationTimeMs: this._calculationTimeMs,
589
+ precision: "day"
590
+ }
591
+ };
592
+ }
593
+ generateExplanationSteps() {
594
+ let e = [];
595
+ 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)`);
596
+ let t = [
597
+ this.years > 0 ? `${this.years}y` : "",
598
+ this.months > 0 ? `${this.months}m` : "",
599
+ this.days > 0 ? `${this.days}d` : "",
600
+ this.hours > 0 ? `${this.hours}h` : "",
601
+ this.minutes > 0 ? `${this.minutes}min` : "",
602
+ this.seconds > 0 ? `${this.seconds}s` : ""
603
+ ].filter((e) => e.length > 0).join(" ");
604
+ return e.push(`Total: ${t || "0"}`), e;
605
+ }
606
+ getConjunction(e) {
607
+ return {
608
+ en: "and",
609
+ es: "y",
610
+ fr: "et",
611
+ de: "und",
612
+ it: "e",
613
+ pt: "e"
614
+ }[e] || "and";
615
+ }
616
+ pluralizeUnit(e, t, n) {
617
+ let r = {
618
+ en: {
619
+ year: ["year", "years"],
620
+ month: ["month", "months"],
621
+ week: ["week", "weeks"],
622
+ day: ["day", "days"],
623
+ hour: ["hour", "hours"],
624
+ minute: ["minute", "minutes"],
625
+ second: ["second", "seconds"],
626
+ millisecond: ["millisecond", "milliseconds"]
627
+ },
628
+ es: {
629
+ year: ["año", "años"],
630
+ month: ["mes", "meses"],
631
+ week: ["semana", "semanas"],
632
+ day: ["día", "días"],
633
+ hour: ["hora", "horas"],
634
+ minute: ["minuto", "minutos"],
635
+ second: ["segundo", "segundos"],
636
+ millisecond: ["milisegundo", "milisegundos"]
637
+ },
638
+ fr: {
639
+ year: ["année", "années"],
640
+ month: ["mois", "mois"],
641
+ week: ["semaine", "semaines"],
642
+ day: ["jour", "jours"],
643
+ hour: ["heure", "heures"],
644
+ minute: ["minute", "minutes"],
645
+ second: ["seconde", "secondes"],
646
+ millisecond: ["milliseconde", "millisecondes"]
647
+ }
648
+ };
649
+ return ((r[n] || r.en)[e] || [e, e + "s"])[t === 1 ? 0 : 1];
650
+ }
651
+ }, u = class {
652
+ _start;
653
+ _end;
654
+ constructor(e, t) {
655
+ this._start = e, this._end = t;
656
+ }
657
+ toDuration() {
658
+ return d.between(this._start, this._end);
659
+ }
660
+ inMonths() {
661
+ return this.toDuration().total("month");
662
+ }
663
+ humanize(e) {
664
+ return this.toDuration().humanize(e);
665
+ }
666
+ in(e) {
667
+ return this.toDuration().total(e);
668
+ }
669
+ }, d = class e {
317
670
  temporal;
318
671
  config;
319
672
  formatterInstance;
320
673
  static ZERO_DURATION = {
321
674
  years: 0,
322
675
  months: 0,
676
+ weeks: 0,
323
677
  days: 0,
324
678
  hours: 0,
325
679
  minutes: 0,
@@ -333,6 +687,7 @@ var n = class {
333
687
  return {
334
688
  years: Math.floor(e.years || 0),
335
689
  months: Math.floor(e.months || 0),
690
+ weeks: Math.floor(e.weeks || 0),
336
691
  days: Math.floor(e.days || 0),
337
692
  hours: Math.floor(e.hours || 0),
338
693
  minutes: Math.floor(e.minutes || 0),
@@ -359,6 +714,13 @@ var n = class {
359
714
  let r = new e(void 0, n);
360
715
  return r.temporal = t, r;
361
716
  }
717
+ static between(e, t) {
718
+ let r = n.toPlainDateTime(e.temporal), i = n.toPlainDateTime(t.temporal), [a, o] = n.compare(r, i) <= 0 ? [e, t] : [t, e];
719
+ return a.until(o);
720
+ }
721
+ static range(t, n) {
722
+ return new u(t instanceof e ? t : new e(t), n instanceof e ? n : new e(n));
723
+ }
362
724
  toTemporal() {
363
725
  return this.temporal;
364
726
  }
@@ -433,7 +795,7 @@ var n = class {
433
795
  t[e] = n ? -n : 0;
434
796
  }), this.add(t);
435
797
  }
436
- diff(e, t = "millisecond") {
798
+ diff(e, t) {
437
799
  let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(e.temporal), a = {
438
800
  year: "years",
439
801
  month: "months",
@@ -445,8 +807,38 @@ var n = class {
445
807
  millisecond: "milliseconds",
446
808
  microsecond: "microseconds",
447
809
  nanosecond: "nanoseconds"
448
- }, o = r.since(i), s = a[t];
449
- return Math.round(o[s] || 0);
810
+ };
811
+ if (typeof t == "string") {
812
+ let e = t, n = a[e], o = r.since(i, { smallestUnit: e });
813
+ return Math.round(o[n] || 0);
814
+ }
815
+ let o = t || {}, s = o.mode || "exact", l = o.unit || "millisecond", u = o.locale || this.config.locale;
816
+ if (s === "exact") {
817
+ let n = a[l], o = r.since(i, { smallestUnit: l }), d = Math.round(o[n] || 0);
818
+ if (t === void 0 || typeof t == "object") {
819
+ 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);
820
+ return new c(Math.round(t), this, e, s, void 0, u);
821
+ }
822
+ return d;
823
+ }
824
+ if (s === "calendar") {
825
+ let t = r.since(i, {
826
+ largestUnit: "month",
827
+ smallestUnit: "millisecond"
828
+ }), n = {
829
+ years: Math.floor(t.years || 0),
830
+ months: Math.floor(t.months || 0),
831
+ weeks: Math.floor(t.weeks || 0),
832
+ days: Math.floor(t.days || 0),
833
+ hours: Math.floor(t.hours || 0),
834
+ minutes: Math.floor(t.minutes || 0),
835
+ seconds: Math.floor(t.seconds || 0),
836
+ milliseconds: Math.floor(t.milliseconds || 0)
837
+ }, 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);
838
+ return new c(Math.round(a), this, e, s, n, u);
839
+ }
840
+ 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);
841
+ return new c(Math.round(f), this, e, s, void 0, u);
450
842
  }
451
843
  isBefore(e) {
452
844
  let t = n.toPlainDateTime(this.temporal), r = n.toPlainDateTime(e.temporal);
@@ -555,14 +947,49 @@ var n = class {
555
947
  let t = n.toPlainDateTime(this.temporal);
556
948
  return e.isLeapYearValue(t.year);
557
949
  }
558
- until(t) {
559
- let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(t.temporal);
950
+ until(t, r) {
951
+ let i = n.toPlainDateTime(this.temporal), a = n.toPlainDateTime(t.temporal), o = performance.now();
560
952
  try {
561
- let t = i.since(r);
562
- return e.toDurationParts(t);
953
+ let t = {};
954
+ r?.largestUnit && (t.largestUnit = r.largestUnit), r?.smallestUnit && (t.smallestUnit = r.smallestUnit);
955
+ let n = a.since(i, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(n), c = i.year, u = a.year, d = [];
956
+ for (let t = c; t <= u; t++) {
957
+ let n = e.isLeapYearValue(t);
958
+ d.push({
959
+ year: t,
960
+ isLeap: n,
961
+ daysInFebruary: n ? 29 : 28
962
+ });
963
+ }
964
+ let f = this.generateUntilSteps(i, a, s, d), p = performance.now() - o;
965
+ return new l(s, this.config.locale, {
966
+ startDate: i.toString(),
967
+ endDate: a.toString(),
968
+ steps: f,
969
+ mode: "exact",
970
+ leapYearFlags: d.filter((e) => e.isLeap),
971
+ calculationTimeMs: p
972
+ });
563
973
  } catch {
564
- return { ...e.ZERO_DURATION };
974
+ return new l(e.ZERO_DURATION, this.config.locale, {
975
+ startDate: i.toString(),
976
+ endDate: a.toString(),
977
+ steps: ["Calculation failed, returning zero duration"],
978
+ mode: "estimated"
979
+ });
980
+ }
981
+ }
982
+ generateUntilSteps(t, n, r, i) {
983
+ let a = [];
984
+ 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})`);
985
+ let o = i.filter((e) => e.isLeap);
986
+ if (o.length > 0) for (let e of o) a.push(`${e.year} is a leap year (February has ${e.daysInFebruary} days)`);
987
+ 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) {
988
+ let e = [];
989
+ 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
990
  }
991
+ let s = r.years * 365.25 + r.months * 30.4375 + r.days + r.hours / 24;
992
+ return a.push(`Total: approximately ${s.toFixed(2)} days`), a;
566
993
  }
567
994
  round(e = {}) {
568
995
  let { smallestUnit: t = "millisecond", roundingMode: r = "halfExpand" } = e, i = n.toPlainDateTime(this.temporal), a = {
@@ -657,13 +1084,36 @@ var n = class {
657
1084
  endOfDay() {
658
1085
  return this.endOf("day");
659
1086
  }
660
- since(t) {
661
- let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(t.temporal);
1087
+ since(t, r) {
1088
+ let i = n.toPlainDateTime(this.temporal), a = n.toPlainDateTime(t.temporal), o = performance.now();
662
1089
  try {
663
- let t = r.since(i);
664
- return e.toDurationParts(t);
1090
+ let t = {};
1091
+ r?.largestUnit && (t.largestUnit = r.largestUnit), r?.smallestUnit && (t.smallestUnit = r.smallestUnit);
1092
+ let n = i.since(a, Object.keys(t).length > 0 ? t : void 0), s = e.toDurationParts(n), c = a.year, u = i.year, d = [];
1093
+ for (let t = c; t <= u; t++) {
1094
+ let n = e.isLeapYearValue(t);
1095
+ d.push({
1096
+ year: t,
1097
+ isLeap: n,
1098
+ daysInFebruary: n ? 29 : 28
1099
+ });
1100
+ }
1101
+ let f = this.generateUntilSteps(a, i, s, d), p = performance.now() - o;
1102
+ return new l(s, this.config.locale, {
1103
+ startDate: a.toString(),
1104
+ endDate: i.toString(),
1105
+ steps: f,
1106
+ mode: "exact",
1107
+ leapYearFlags: d.filter((e) => e.isLeap),
1108
+ calculationTimeMs: p
1109
+ });
665
1110
  } catch {
666
- return { ...e.ZERO_DURATION };
1111
+ return new l(e.ZERO_DURATION, this.config.locale, {
1112
+ startDate: a.toString(),
1113
+ endDate: i.toString(),
1114
+ steps: ["Calculation failed, returning zero duration"],
1115
+ mode: "estimated"
1116
+ });
667
1117
  }
668
1118
  }
669
1119
  toDurationString(t) {
@@ -689,7 +1139,7 @@ var n = class {
689
1139
  isYesterday() {
690
1140
  return this.isSame(e.now().subtract({ day: 1 }), "day");
691
1141
  }
692
- }, c = {
1142
+ }, f = {
693
1143
  name: "en",
694
1144
  months: [
695
1145
  "January",
@@ -757,7 +1207,7 @@ var n = class {
757
1207
  datetime: "YYYY-MM-DD HH:mm:ss",
758
1208
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
759
1209
  }
760
- }, l = {
1210
+ }, p = {
761
1211
  name: "en-au",
762
1212
  months: [
763
1213
  "January",
@@ -825,7 +1275,7 @@ var n = class {
825
1275
  datetime: "DD/MM/YYYY HH:mm:ss",
826
1276
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
827
1277
  }
828
- }, u = {
1278
+ }, m = {
829
1279
  name: "en-gb",
830
1280
  months: [
831
1281
  "January",
@@ -893,7 +1343,7 @@ var n = class {
893
1343
  datetime: "DD/MM/YYYY HH:mm:ss",
894
1344
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
895
1345
  }
896
- }, d = {
1346
+ }, h = {
897
1347
  name: "en-ca",
898
1348
  months: [
899
1349
  "January",
@@ -961,12 +1411,12 @@ var n = class {
961
1411
  datetime: "YYYY-MM-DD HH:mm:ss",
962
1412
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
963
1413
  }
964
- }, f = {
965
- en: c,
966
- "en-au": l,
967
- "en-gb": u,
968
- "en-ca": d
969
- }, p = {
1414
+ }, g = {
1415
+ en: f,
1416
+ "en-au": p,
1417
+ "en-gb": m,
1418
+ "en-ca": h
1419
+ }, _ = {
970
1420
  name: "es",
971
1421
  months: [
972
1422
  "Enero",
@@ -1034,7 +1484,7 @@ var n = class {
1034
1484
  datetime: "DD/MM/YYYY HH:mm:ss",
1035
1485
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1036
1486
  }
1037
- }, m = {
1487
+ }, v = {
1038
1488
  name: "es-mx",
1039
1489
  months: [
1040
1490
  "Enero",
@@ -1102,7 +1552,7 @@ var n = class {
1102
1552
  datetime: "DD/MM/YYYY HH:mm:ss",
1103
1553
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1104
1554
  }
1105
- }, h = {
1555
+ }, y = {
1106
1556
  name: "es-us",
1107
1557
  months: [
1108
1558
  "Enero",
@@ -1170,11 +1620,11 @@ var n = class {
1170
1620
  datetime: "MM/DD/YYYY HH:mm:ss",
1171
1621
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1172
1622
  }
1173
- }, g = {
1174
- es: p,
1175
- "es-mx": m,
1176
- "es-us": h
1177
- }, _ = {
1623
+ }, ee = {
1624
+ es: _,
1625
+ "es-mx": v,
1626
+ "es-us": y
1627
+ }, te = {
1178
1628
  name: "fr",
1179
1629
  months: [
1180
1630
  "janvier",
@@ -1242,7 +1692,7 @@ var n = class {
1242
1692
  datetime: "DD/MM/YYYY HH:mm:ss",
1243
1693
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1244
1694
  }
1245
- }, v = {
1695
+ }, ne = {
1246
1696
  name: "it",
1247
1697
  months: [
1248
1698
  "gennaio",
@@ -1310,7 +1760,7 @@ var n = class {
1310
1760
  datetime: "DD/MM/YYYY HH:mm:ss",
1311
1761
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1312
1762
  }
1313
- }, y = {
1763
+ }, b = {
1314
1764
  name: "pt",
1315
1765
  months: [
1316
1766
  "janeiro",
@@ -1378,7 +1828,7 @@ var n = class {
1378
1828
  datetime: "DD/MM/YYYY HH:mm:ss",
1379
1829
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1380
1830
  }
1381
- }, b = {
1831
+ }, x = {
1382
1832
  name: "pt-br",
1383
1833
  months: [
1384
1834
  "janeiro",
@@ -1446,7 +1896,7 @@ var n = class {
1446
1896
  datetime: "DD/MM/YYYY HH:mm:ss",
1447
1897
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1448
1898
  }
1449
- }, ee = {
1899
+ }, S = {
1450
1900
  name: "ro",
1451
1901
  months: [
1452
1902
  "ianuarie",
@@ -1514,13 +1964,13 @@ var n = class {
1514
1964
  datetime: "DD.MM.YYYY HH:mm:ss",
1515
1965
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1516
1966
  }
1517
- }, x = {
1518
- fr: _,
1519
- it: v,
1520
- pt: y,
1521
- "pt-br": b,
1522
- ro: ee
1523
- }, S = {
1967
+ }, C = {
1968
+ fr: te,
1969
+ it: ne,
1970
+ pt: b,
1971
+ "pt-br": x,
1972
+ ro: S
1973
+ }, w = {
1524
1974
  ru: {
1525
1975
  name: "ru",
1526
1976
  months: [
@@ -1797,7 +2247,7 @@ var n = class {
1797
2247
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1798
2248
  }
1799
2249
  }
1800
- }, C = {
2250
+ }, T = {
1801
2251
  sv: {
1802
2252
  name: "sv",
1803
2253
  months: [
@@ -2074,7 +2524,7 @@ var n = class {
2074
2524
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2075
2525
  }
2076
2526
  }
2077
- }, w = {
2527
+ }, E = {
2078
2528
  name: "ja",
2079
2529
  months: [
2080
2530
  "1月",
@@ -2142,7 +2592,7 @@ var n = class {
2142
2592
  datetime: "YYYY年MM月DD日 HH:mm:ss",
2143
2593
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2144
2594
  }
2145
- }, T = {
2595
+ }, D = {
2146
2596
  name: "zh-cn",
2147
2597
  months: [
2148
2598
  "1月",
@@ -2210,7 +2660,7 @@ var n = class {
2210
2660
  datetime: "YYYY-MM-DD HH:mm:ss",
2211
2661
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2212
2662
  }
2213
- }, E = {
2663
+ }, O = {
2214
2664
  name: "zh-tw",
2215
2665
  months: [
2216
2666
  "1月",
@@ -2278,7 +2728,7 @@ var n = class {
2278
2728
  datetime: "YYYY-MM-DD HH:mm:ss",
2279
2729
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2280
2730
  }
2281
- }, D = {
2731
+ }, k = {
2282
2732
  name: "ko",
2283
2733
  months: [
2284
2734
  "1월",
@@ -2346,7 +2796,7 @@ var n = class {
2346
2796
  datetime: "YYYY-MM-DD HH:mm:ss",
2347
2797
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2348
2798
  }
2349
- }, O = {
2799
+ }, A = {
2350
2800
  name: "th",
2351
2801
  months: [
2352
2802
  "มกราคม",
@@ -2414,7 +2864,7 @@ var n = class {
2414
2864
  datetime: "DD/MM/YYYY HH:mm:ss",
2415
2865
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2416
2866
  }
2417
- }, k = {
2867
+ }, j = {
2418
2868
  name: "vi",
2419
2869
  months: [
2420
2870
  "tháng 1",
@@ -2482,7 +2932,7 @@ var n = class {
2482
2932
  datetime: "DD/MM/YYYY HH:mm:ss",
2483
2933
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2484
2934
  }
2485
- }, A = {
2935
+ }, M = {
2486
2936
  name: "id",
2487
2937
  months: [
2488
2938
  "Januari",
@@ -2550,15 +3000,15 @@ var n = class {
2550
3000
  datetime: "DD/MM/YYYY HH:mm:ss",
2551
3001
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
2552
3002
  }
2553
- }, j = {
2554
- ja: w,
2555
- "zh-cn": T,
2556
- "zh-tw": E,
2557
- ko: D,
2558
- th: O,
2559
- vi: k,
2560
- id: A
2561
- }, M = {
3003
+ }, N = {
3004
+ ja: E,
3005
+ "zh-cn": D,
3006
+ "zh-tw": O,
3007
+ ko: k,
3008
+ th: A,
3009
+ vi: j,
3010
+ id: M
3011
+ }, P = {
2562
3012
  de: {
2563
3013
  name: "de",
2564
3014
  months: [
@@ -3042,7 +3492,7 @@ var n = class {
3042
3492
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
3043
3493
  }
3044
3494
  }
3045
- }, N = {
3495
+ }, F = {
3046
3496
  ar: {
3047
3497
  name: "ar",
3048
3498
  months: [
@@ -3250,7 +3700,7 @@ var n = class {
3250
3700
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
3251
3701
  }
3252
3702
  }
3253
- }, P = {
3703
+ }, I = {
3254
3704
  vi: {
3255
3705
  name: "vi",
3256
3706
  months: [
@@ -3458,30 +3908,30 @@ var n = class {
3458
3908
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
3459
3909
  }
3460
3910
  }
3461
- }, F = {
3462
- ...f,
3911
+ }, L = {
3463
3912
  ...g,
3464
- ...x,
3465
- ...S,
3913
+ ...ee,
3466
3914
  ...C,
3467
- ...j,
3468
- ...M,
3915
+ ...w,
3916
+ ...T,
3469
3917
  ...N,
3470
- ...P
3918
+ ...P,
3919
+ ...F,
3920
+ ...I
3471
3921
  };
3472
- function te(e) {
3473
- e instanceof Map ? Object.entries(F).forEach(([t, n]) => {
3922
+ function R(e) {
3923
+ e instanceof Map ? Object.entries(L).forEach(([t, n]) => {
3474
3924
  e.set(t, n);
3475
- }) : Object.entries(F).forEach(([t, n]) => {
3925
+ }) : Object.entries(L).forEach(([t, n]) => {
3476
3926
  e[t] = n;
3477
3927
  });
3478
3928
  }
3479
- function I() {
3480
- let e = Object.keys(F);
3929
+ function z() {
3930
+ let e = Object.keys(L);
3481
3931
  for (; e.length < 40;) e.push(`locale-${e.length + 1}`);
3482
3932
  return e;
3483
3933
  }
3484
- var L = 40, R = class {
3934
+ var re = 40, B = class {
3485
3935
  id = "gregory";
3486
3936
  name = "Gregorian Calendar";
3487
3937
  locale = "en";
@@ -3559,12 +4009,12 @@ var L = 40, R = class {
3559
4009
  daysInYear(e) {
3560
4010
  return this.isLeapYear(e) ? 366 : 365;
3561
4011
  }
3562
- }, z = class e {
4012
+ }, V = class e {
3563
4013
  static instance;
3564
4014
  calendars = /* @__PURE__ */ new Map();
3565
4015
  defaultCalendar = "gregory";
3566
4016
  constructor() {
3567
- this.register(new R());
4017
+ this.register(new B());
3568
4018
  }
3569
4019
  static getInstance() {
3570
4020
  return e.instance ||= new e(), e.instance;
@@ -3586,7 +4036,7 @@ var L = 40, R = class {
3586
4036
  if (!e) throw Error(`Default calendar '${this.defaultCalendar}' not found`);
3587
4037
  return e;
3588
4038
  }
3589
- }, B = z.getInstance(), V = class {
4039
+ }, H = V.getInstance(), U = class {
3590
4040
  id = "islamic";
3591
4041
  name = "Islamic Calendar (Hijri)";
3592
4042
  locale = "ar";
@@ -3647,7 +4097,7 @@ var L = 40, R = class {
3647
4097
  daysInYear(e) {
3648
4098
  return this.isLeapYear(e) ? 355 : 354;
3649
4099
  }
3650
- }, H = class {
4100
+ }, W = class {
3651
4101
  id = "hebrew";
3652
4102
  name = "Hebrew Calendar";
3653
4103
  locale = "he";
@@ -3717,7 +4167,7 @@ var L = 40, R = class {
3717
4167
  daysInYear(e) {
3718
4168
  return this.isLeapYear(e) ? 384 : 354;
3719
4169
  }
3720
- }, U = class {
4170
+ }, G = class {
3721
4171
  id = "chinese";
3722
4172
  name = "Chinese Calendar";
3723
4173
  locale = "zh";
@@ -3783,7 +4233,7 @@ var L = 40, R = class {
3783
4233
  getZodiacSign(e) {
3784
4234
  return this.terrestrialBranches[e % 12];
3785
4235
  }
3786
- }, W = class {
4236
+ }, K = class {
3787
4237
  id = "japanese";
3788
4238
  name = "Japanese Calendar";
3789
4239
  locale = "ja";
@@ -3845,7 +4295,7 @@ var L = 40, R = class {
3845
4295
  daysInYear(e) {
3846
4296
  return this.isLeapYear(e) ? 366 : 365;
3847
4297
  }
3848
- }, G = class {
4298
+ }, q = class {
3849
4299
  id = "buddhist";
3850
4300
  name = "Buddhist Calendar";
3851
4301
  locale = "th";
@@ -3900,47 +4350,7 @@ var L = 40, R = class {
3900
4350
  daysInYear(e) {
3901
4351
  return this.isLeapYear(e) ? 366 : 365;
3902
4352
  }
3903
- }, K = class e {
3904
- static instance;
3905
- plugins = /* @__PURE__ */ new Map();
3906
- static getInstance() {
3907
- return e.instance ||= new e(), e.instance;
3908
- }
3909
- static use(t, n, r) {
3910
- e.getInstance().register(t, n, r);
3911
- }
3912
- static useMultiple(t, n, r) {
3913
- let i = e.getInstance();
3914
- t.forEach((e) => i.register(e, n, r));
3915
- }
3916
- static getPlugin(t) {
3917
- return e.getInstance().plugins.get(t);
3918
- }
3919
- static hasPlugin(t) {
3920
- return e.getInstance().plugins.has(t);
3921
- }
3922
- static listPlugins() {
3923
- let t = e.getInstance();
3924
- return Array.from(t.plugins.keys());
3925
- }
3926
- static unuse(t) {
3927
- return e.getInstance().plugins.delete(t);
3928
- }
3929
- static clear() {
3930
- e.getInstance().plugins.clear();
3931
- }
3932
- register(e, t, n) {
3933
- if (this.plugins.has(e.name)) {
3934
- console.warn(`Plugin "${e.name}" is already registered. Skipping...`);
3935
- return;
3936
- }
3937
- try {
3938
- e.install(t, n), this.plugins.set(e.name, e), console.debug(`Plugin "${e.name}" v${e.version} registered successfully`);
3939
- } catch (t) {
3940
- 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
- }
3942
- }
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 d(e, t);
4332
4742
  }
4333
- var ae = "2.1.0";
4334
- a.getInstance().loadLocales(F);
4743
+ var ce = "2.2.1";
4744
+ a.getInstance().loadLocales(L);
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 { L as ALL_LOCALES, $ as AdvancedFormatPlugin, q as BuddhistCalendar, V as CalendarManager, G as ChineseCalendar, o as DateFormatter, Z as Duration, Q as DurationPlugin, l as DurationResult, r as EN_LOCALE, i as ES_LOCALE, B as GregorianCalendar, W as HebrewCalendar, U as IslamicCalendar, K as JapaneseCalendar, re as LOCALES_COUNT, a as LocaleManager, s as PluginManager, X as RelativeTimePlugin, n as TemporalAdapter, d as TimeGuard, u as TimeRange, oe as advancedFormatPlugin, H as calendarManager, ae as durationPlugin, z as getAvailableLocales, R as registerAllLocales, ie as relativeTimePlugin, se as timeGuard, ce as version };