@bereasoftware/time-guard 2.0.8 → 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.0.8 | (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;
@@ -81,6 +81,12 @@ var n = class {
81
81
  static nowInTimezone(e) {
82
82
  return t().Now.zonedDateTimeISO(e);
83
83
  }
84
+ static compare(e, n) {
85
+ let r = t();
86
+ if (r.PlainDateTime && typeof r.PlainDateTime.compare == "function") return r.PlainDateTime.compare(e, n);
87
+ let i = e.toString(), a = n.toString();
88
+ return i < a ? -1 : i > a ? 1 : 0;
89
+ }
84
90
  }, r = {
85
91
  name: "en",
86
92
  months: [
@@ -307,13 +313,327 @@ var n = class {
307
313
  let r = this.getPreset(t);
308
314
  return this.format(e, r, n);
309
315
  }
310
- }, 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 {
311
630
  temporal;
312
631
  config;
313
632
  formatterInstance;
314
633
  static ZERO_DURATION = {
315
634
  years: 0,
316
635
  months: 0,
636
+ weeks: 0,
317
637
  days: 0,
318
638
  hours: 0,
319
639
  minutes: 0,
@@ -327,6 +647,7 @@ var n = class {
327
647
  return {
328
648
  years: Math.floor(e.years || 0),
329
649
  months: Math.floor(e.months || 0),
650
+ weeks: Math.floor(e.weeks || 0),
330
651
  days: Math.floor(e.days || 0),
331
652
  hours: Math.floor(e.hours || 0),
332
653
  minutes: Math.floor(e.minutes || 0),
@@ -353,6 +674,13 @@ var n = class {
353
674
  let r = new e(void 0, n);
354
675
  return r.temporal = t, r;
355
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
+ }
356
684
  toTemporal() {
357
685
  return this.temporal;
358
686
  }
@@ -427,7 +755,7 @@ var n = class {
427
755
  t[e] = n ? -n : 0;
428
756
  }), this.add(t);
429
757
  }
430
- diff(e, t = "millisecond") {
758
+ diff(e, t) {
431
759
  let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(e.temporal), a = {
432
760
  year: "years",
433
761
  month: "months",
@@ -439,19 +767,49 @@ var n = class {
439
767
  millisecond: "milliseconds",
440
768
  microsecond: "microseconds",
441
769
  nanosecond: "nanoseconds"
442
- }, o = r.since(i), s = a[t];
443
- 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);
444
802
  }
445
803
  isBefore(e) {
446
804
  let t = n.toPlainDateTime(this.temporal), r = n.toPlainDateTime(e.temporal);
447
- return t.compare(r) < 0;
805
+ return n.compare(t, r) < 0;
448
806
  }
449
807
  isAfter(e) {
450
808
  let t = n.toPlainDateTime(this.temporal), r = n.toPlainDateTime(e.temporal);
451
- return t.compare(r) > 0;
809
+ return n.compare(t, r) > 0;
452
810
  }
453
811
  isSame(e, t) {
454
- if (!t) return n.toPlainDateTime(this.temporal).compare(n.toPlainDateTime(e.temporal)) === 0;
812
+ if (!t) return n.compare(n.toPlainDateTime(this.temporal), n.toPlainDateTime(e.temporal)) === 0;
455
813
  let r = n.toPlainDateTime(this.temporal), i = n.toPlainDateTime(e.temporal);
456
814
  switch (t) {
457
815
  case "year": return r.year === i.year;
@@ -467,10 +825,10 @@ var n = class {
467
825
  let a = n.toPlainDateTime(this.temporal), o = n.toPlainDateTime(e.temporal), s = n.toPlainDateTime(t.temporal), c = !0, l = !0;
468
826
  if (r) {
469
827
  let e = this.clone().startOf(r), t = this.clone().endOf(r), i = n.toPlainDateTime(e.temporal), a = n.toPlainDateTime(t.temporal);
470
- c = i.compare(o) >= 0, l = a.compare(s) <= 0;
471
- } else c = a.compare(o) >= 0, l = a.compare(s) <= 0;
828
+ c = n.compare(i, o) >= 0, l = n.compare(a, s) <= 0;
829
+ } else c = n.compare(a, o) >= 0, l = n.compare(a, s) <= 0;
472
830
  let u = i[0] === "[", d = i[1] === "]";
473
- return (u ? c : a.compare(o) > 0) && (d ? l : a.compare(s) < 0);
831
+ return (u ? c : n.compare(a, o) > 0) && (d ? l : n.compare(a, s) < 0);
474
832
  }
475
833
  clone() {
476
834
  return new e(this.toDate(), this.config);
@@ -549,14 +907,49 @@ var n = class {
549
907
  let t = n.toPlainDateTime(this.temporal);
550
908
  return e.isLeapYearValue(t.year);
551
909
  }
552
- until(t) {
553
- 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();
554
912
  try {
555
- let t = i.since(r);
556
- 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
+ });
557
933
  } catch {
558
- 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(" ")}`);
559
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;
560
953
  }
561
954
  round(e = {}) {
562
955
  let { smallestUnit: t = "millisecond", roundingMode: r = "halfExpand" } = e, i = n.toPlainDateTime(this.temporal), a = {
@@ -651,13 +1044,36 @@ var n = class {
651
1044
  endOfDay() {
652
1045
  return this.endOf("day");
653
1046
  }
654
- since(t) {
655
- 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();
656
1049
  try {
657
- let t = r.since(i);
658
- 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
+ });
659
1070
  } catch {
660
- 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
+ });
661
1077
  }
662
1078
  }
663
1079
  toDurationString(t) {
@@ -683,7 +1099,7 @@ var n = class {
683
1099
  isYesterday() {
684
1100
  return this.isSame(e.now().subtract({ day: 1 }), "day");
685
1101
  }
686
- }, c = {
1102
+ }, d = {
687
1103
  name: "en",
688
1104
  months: [
689
1105
  "January",
@@ -751,7 +1167,7 @@ var n = class {
751
1167
  datetime: "YYYY-MM-DD HH:mm:ss",
752
1168
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
753
1169
  }
754
- }, l = {
1170
+ }, f = {
755
1171
  name: "en-au",
756
1172
  months: [
757
1173
  "January",
@@ -819,7 +1235,7 @@ var n = class {
819
1235
  datetime: "DD/MM/YYYY HH:mm:ss",
820
1236
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
821
1237
  }
822
- }, u = {
1238
+ }, p = {
823
1239
  name: "en-gb",
824
1240
  months: [
825
1241
  "January",
@@ -887,7 +1303,7 @@ var n = class {
887
1303
  datetime: "DD/MM/YYYY HH:mm:ss",
888
1304
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
889
1305
  }
890
- }, d = {
1306
+ }, m = {
891
1307
  name: "en-ca",
892
1308
  months: [
893
1309
  "January",
@@ -955,12 +1371,12 @@ var n = class {
955
1371
  datetime: "YYYY-MM-DD HH:mm:ss",
956
1372
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
957
1373
  }
958
- }, f = {
959
- en: c,
960
- "en-au": l,
961
- "en-gb": u,
962
- "en-ca": d
963
- }, p = {
1374
+ }, ee = {
1375
+ en: d,
1376
+ "en-au": f,
1377
+ "en-gb": p,
1378
+ "en-ca": m
1379
+ }, h = {
964
1380
  name: "es",
965
1381
  months: [
966
1382
  "Enero",
@@ -1028,7 +1444,7 @@ var n = class {
1028
1444
  datetime: "DD/MM/YYYY HH:mm:ss",
1029
1445
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1030
1446
  }
1031
- }, m = {
1447
+ }, g = {
1032
1448
  name: "es-mx",
1033
1449
  months: [
1034
1450
  "Enero",
@@ -1096,7 +1512,7 @@ var n = class {
1096
1512
  datetime: "DD/MM/YYYY HH:mm:ss",
1097
1513
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1098
1514
  }
1099
- }, h = {
1515
+ }, _ = {
1100
1516
  name: "es-us",
1101
1517
  months: [
1102
1518
  "Enero",
@@ -1164,11 +1580,11 @@ var n = class {
1164
1580
  datetime: "MM/DD/YYYY HH:mm:ss",
1165
1581
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1166
1582
  }
1167
- }, g = {
1168
- es: p,
1169
- "es-mx": m,
1170
- "es-us": h
1171
- }, _ = {
1583
+ }, v = {
1584
+ es: h,
1585
+ "es-mx": g,
1586
+ "es-us": _
1587
+ }, te = {
1172
1588
  name: "fr",
1173
1589
  months: [
1174
1590
  "janvier",
@@ -1236,7 +1652,7 @@ var n = class {
1236
1652
  datetime: "DD/MM/YYYY HH:mm:ss",
1237
1653
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1238
1654
  }
1239
- }, v = {
1655
+ }, ne = {
1240
1656
  name: "it",
1241
1657
  months: [
1242
1658
  "gennaio",
@@ -1304,7 +1720,7 @@ var n = class {
1304
1720
  datetime: "DD/MM/YYYY HH:mm:ss",
1305
1721
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1306
1722
  }
1307
- }, y = {
1723
+ }, re = {
1308
1724
  name: "pt",
1309
1725
  months: [
1310
1726
  "janeiro",
@@ -1372,7 +1788,7 @@ var n = class {
1372
1788
  datetime: "DD/MM/YYYY HH:mm:ss",
1373
1789
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1374
1790
  }
1375
- }, b = {
1791
+ }, y = {
1376
1792
  name: "pt-br",
1377
1793
  months: [
1378
1794
  "janeiro",
@@ -1440,7 +1856,7 @@ var n = class {
1440
1856
  datetime: "DD/MM/YYYY HH:mm:ss",
1441
1857
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1442
1858
  }
1443
- }, ee = {
1859
+ }, b = {
1444
1860
  name: "ro",
1445
1861
  months: [
1446
1862
  "ianuarie",
@@ -1509,11 +1925,11 @@ var n = class {
1509
1925
  rfc2822: "ddd, DD MMM YYYY HH:mm:ss Z"
1510
1926
  }
1511
1927
  }, x = {
1512
- fr: _,
1513
- it: v,
1514
- pt: y,
1515
- "pt-br": b,
1516
- ro: ee
1928
+ fr: te,
1929
+ it: ne,
1930
+ pt: re,
1931
+ "pt-br": y,
1932
+ ro: b
1517
1933
  }, S = {
1518
1934
  ru: {
1519
1935
  name: "ru",
@@ -3453,8 +3869,8 @@ var n = class {
3453
3869
  }
3454
3870
  }
3455
3871
  }, F = {
3456
- ...f,
3457
- ...g,
3872
+ ...ee,
3873
+ ...v,
3458
3874
  ...x,
3459
3875
  ...S,
3460
3876
  ...C,
@@ -3463,19 +3879,19 @@ var n = class {
3463
3879
  ...N,
3464
3880
  ...P
3465
3881
  };
3466
- function te(e) {
3882
+ function I(e) {
3467
3883
  e instanceof Map ? Object.entries(F).forEach(([t, n]) => {
3468
3884
  e.set(t, n);
3469
3885
  }) : Object.entries(F).forEach(([t, n]) => {
3470
3886
  e[t] = n;
3471
3887
  });
3472
3888
  }
3473
- function I() {
3889
+ function L() {
3474
3890
  let e = Object.keys(F);
3475
3891
  for (; e.length < 40;) e.push(`locale-${e.length + 1}`);
3476
3892
  return e;
3477
3893
  }
3478
- var L = 40, R = class {
3894
+ var R = 40, z = class {
3479
3895
  id = "gregory";
3480
3896
  name = "Gregorian Calendar";
3481
3897
  locale = "en";
@@ -3553,12 +3969,12 @@ var L = 40, R = class {
3553
3969
  daysInYear(e) {
3554
3970
  return this.isLeapYear(e) ? 366 : 365;
3555
3971
  }
3556
- }, z = class e {
3972
+ }, B = class e {
3557
3973
  static instance;
3558
3974
  calendars = /* @__PURE__ */ new Map();
3559
3975
  defaultCalendar = "gregory";
3560
3976
  constructor() {
3561
- this.register(new R());
3977
+ this.register(new z());
3562
3978
  }
3563
3979
  static getInstance() {
3564
3980
  return e.instance ||= new e(), e.instance;
@@ -3580,7 +3996,7 @@ var L = 40, R = class {
3580
3996
  if (!e) throw Error(`Default calendar '${this.defaultCalendar}' not found`);
3581
3997
  return e;
3582
3998
  }
3583
- }, B = z.getInstance(), V = class {
3999
+ }, V = B.getInstance(), H = class {
3584
4000
  id = "islamic";
3585
4001
  name = "Islamic Calendar (Hijri)";
3586
4002
  locale = "ar";
@@ -3641,7 +4057,7 @@ var L = 40, R = class {
3641
4057
  daysInYear(e) {
3642
4058
  return this.isLeapYear(e) ? 355 : 354;
3643
4059
  }
3644
- }, H = class {
4060
+ }, U = class {
3645
4061
  id = "hebrew";
3646
4062
  name = "Hebrew Calendar";
3647
4063
  locale = "he";
@@ -3711,7 +4127,7 @@ var L = 40, R = class {
3711
4127
  daysInYear(e) {
3712
4128
  return this.isLeapYear(e) ? 384 : 354;
3713
4129
  }
3714
- }, U = class {
4130
+ }, W = class {
3715
4131
  id = "chinese";
3716
4132
  name = "Chinese Calendar";
3717
4133
  locale = "zh";
@@ -3777,7 +4193,7 @@ var L = 40, R = class {
3777
4193
  getZodiacSign(e) {
3778
4194
  return this.terrestrialBranches[e % 12];
3779
4195
  }
3780
- }, W = class {
4196
+ }, G = class {
3781
4197
  id = "japanese";
3782
4198
  name = "Japanese Calendar";
3783
4199
  locale = "ja";
@@ -3839,7 +4255,7 @@ var L = 40, R = class {
3839
4255
  daysInYear(e) {
3840
4256
  return this.isLeapYear(e) ? 366 : 365;
3841
4257
  }
3842
- }, G = class {
4258
+ }, K = class {
3843
4259
  id = "buddhist";
3844
4260
  name = "Buddhist Calendar";
3845
4261
  locale = "th";
@@ -3894,7 +4310,7 @@ var L = 40, R = class {
3894
4310
  daysInYear(e) {
3895
4311
  return this.isLeapYear(e) ? 366 : 365;
3896
4312
  }
3897
- }, K = class e {
4313
+ }, q = class e {
3898
4314
  static instance;
3899
4315
  plugins = /* @__PURE__ */ new Map();
3900
4316
  static getInstance() {
@@ -3934,7 +4350,7 @@ var L = 40, R = class {
3934
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)}`);
3935
4351
  }
3936
4352
  }
3937
- }, q = [
4353
+ }, J = [
3938
4354
  {
3939
4355
  l: "s",
3940
4356
  r: 44,
@@ -3984,7 +4400,7 @@ var L = 40, R = class {
3984
4400
  l: "yy",
3985
4401
  d: "year"
3986
4402
  }
3987
- ], J = {
4403
+ ], Y = {
3988
4404
  future: "in %s",
3989
4405
  past: "%s ago",
3990
4406
  s: "a few seconds",
@@ -3998,16 +4414,16 @@ var L = 40, R = class {
3998
4414
  MM: "%d months",
3999
4415
  y: "a year",
4000
4416
  yy: "%d years"
4001
- }, Y = class {
4417
+ }, X = class {
4002
4418
  name = "relative-time";
4003
4419
  version = "1.0.0";
4004
4420
  config;
4005
4421
  formats;
4006
4422
  constructor(e) {
4007
4423
  this.config = {
4008
- thresholds: e?.thresholds || q,
4424
+ thresholds: e?.thresholds || J,
4009
4425
  rounding: e?.rounding || Math.round
4010
- }, this.formats = J;
4426
+ }, this.formats = Y;
4011
4427
  }
4012
4428
  install(e) {
4013
4429
  let t = this;
@@ -4024,7 +4440,7 @@ var L = 40, R = class {
4024
4440
  return n ? o : (a ? this.formats.future : this.formats.past).replace("%s", o);
4025
4441
  }
4026
4442
  getRelativeTimeString(e) {
4027
- 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;
4028
4444
  for (let r = 0; r < t.length; r++) {
4029
4445
  let i = t[r];
4030
4446
  if (r + 1 < t.length && t[r + 1] && i.r && e < i.r * 1e3) continue;
@@ -4051,7 +4467,7 @@ var L = 40, R = class {
4051
4467
  getFormats() {
4052
4468
  return { ...this.formats };
4053
4469
  }
4054
- }, X = new Y(), Z = class e {
4470
+ }, ie = new X(), Z = class e {
4055
4471
  years = 0;
4056
4472
  months = 0;
4057
4473
  weeks = 0;
@@ -4191,7 +4607,7 @@ var L = 40, R = class {
4191
4607
  fromMilliseconds: (e) => Z.fromMilliseconds(e)
4192
4608
  };
4193
4609
  }
4194
- }, ne = new Q(), $ = class {
4610
+ }, ae = new Q(), $ = class {
4195
4611
  name = "advanced-format";
4196
4612
  version = "1.0.0";
4197
4613
  install(e) {
@@ -4318,13 +4734,13 @@ var L = 40, R = class {
4318
4734
  return "Coordinated Universal Time";
4319
4735
  }
4320
4736
  }
4321
- }, re = new $();
4737
+ }, oe = new $();
4322
4738
  //#endregion
4323
4739
  //#region src/index.ts
4324
- function ie(e, t) {
4325
- return new s(e, t);
4740
+ function se(e, t) {
4741
+ return new u(e, t);
4326
4742
  }
4327
- var ae = "2.0.8";
4743
+ var ce = "2.2.0";
4328
4744
  a.getInstance().loadLocales(F);
4329
4745
  //#endregion
4330
- 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 };