rrule-temporal 1.4.3 → 1.4.5

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.
@@ -223,6 +223,13 @@ function parseRRuleString(input, targetTimezone, dtstart) {
223
223
  return opts;
224
224
  }
225
225
  var _RRuleTemporal = class _RRuleTemporal {
226
+ /**
227
+ * Normalize a ZonedDateTime to the polyfill implementation.
228
+ * This prevents type mismatches when mixing native and polyfill Temporal objects.
229
+ */
230
+ static normalizeToPolyfill(zdt) {
231
+ return Temporal.ZonedDateTime.from(zdt.toString());
232
+ }
226
233
  constructor(params) {
227
234
  var _a, _b, _c, _d, _e, _f, _g;
228
235
  let manual;
@@ -232,7 +239,7 @@ var _RRuleTemporal = class _RRuleTemporal {
232
239
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
233
240
  }
234
241
  this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
235
- this.originalDtstart = parsed.dtstart;
242
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
236
243
  manual = __spreadProps(__spreadValues({}, parsed), {
237
244
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
238
245
  count: (_c = params.count) != null ? _c : parsed.count,
@@ -249,7 +256,7 @@ var _RRuleTemporal = class _RRuleTemporal {
249
256
  }
250
257
  manual.tzid = manual.tzid || manual.dtstart.timeZoneId;
251
258
  this.tzid = manual.tzid;
252
- this.originalDtstart = manual.dtstart;
259
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
253
260
  }
254
261
  if (!manual.freq) throw new Error("RRULE must include FREQ");
255
262
  manual.interval = (_e = manual.interval) != null ? _e : 1;
@@ -259,6 +266,9 @@ var _RRuleTemporal = class _RRuleTemporal {
259
266
  if (manual.until && !(manual.until instanceof Temporal.ZonedDateTime)) {
260
267
  throw new Error("Manual until must be a ZonedDateTime");
261
268
  }
269
+ if (manual.until) {
270
+ manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
271
+ }
262
272
  this.opts = this.sanitizeOpts(manual);
263
273
  this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
264
274
  this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
@@ -1484,6 +1494,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1484
1494
  const safetyMargin = Math.min(targetRuleCount, 10);
1485
1495
  return matchCount >= targetRuleCount + safetyMargin;
1486
1496
  }
1497
+ hasTimeOfDayBetween(startTime, endTime) {
1498
+ var _a, _b, _c;
1499
+ if (Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1500
+ const base = this.originalDtstart;
1501
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1502
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1503
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1504
+ for (const hour of hours) {
1505
+ for (const minute of minutes) {
1506
+ for (const second of seconds) {
1507
+ const candidate = Temporal.PlainTime.from({
1508
+ hour,
1509
+ minute,
1510
+ second,
1511
+ millisecond: base.millisecond,
1512
+ microsecond: base.microsecond,
1513
+ nanosecond: base.nanosecond
1514
+ });
1515
+ if (Temporal.PlainTime.compare(candidate, startTime) >= 0 && Temporal.PlainTime.compare(candidate, endTime) < 0) {
1516
+ return true;
1517
+ }
1518
+ }
1519
+ }
1520
+ }
1521
+ return false;
1522
+ }
1487
1523
  /**
1488
1524
  * Returns all occurrences of the rule within a specified time window.
1489
1525
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1527,39 +1563,44 @@ var _RRuleTemporal = class _RRuleTemporal {
1527
1563
  default:
1528
1564
  unit = "seconds";
1529
1565
  }
1530
- const dtstartNormalized = Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1531
- const alignedNormalized = Temporal.ZonedDateTime.from(
1532
- aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1566
+ const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1567
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1568
+ const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1569
+ aligned.withPlainTime(this.originalDtstart.toPlainTime())
1533
1570
  ).withTimeZone(dtstartNormalized.timeZoneId);
1534
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1571
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1572
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1535
1573
  const unitsBetween = diffDur[unit];
1536
- const steps = Math.floor(unitsBetween / interval);
1537
- let toAdd;
1538
- const jump = steps * interval;
1539
- switch (unit) {
1540
- case "years":
1541
- toAdd = { years: jump };
1542
- break;
1543
- case "months":
1544
- toAdd = { months: jump };
1545
- break;
1546
- case "weeks":
1547
- toAdd = { weeks: jump };
1548
- break;
1549
- case "days":
1550
- toAdd = { days: jump };
1551
- break;
1552
- case "hours":
1553
- toAdd = { hours: jump };
1554
- break;
1555
- case "minutes":
1556
- toAdd = { minutes: jump };
1557
- break;
1558
- default:
1559
- toAdd = { seconds: jump };
1574
+ let steps = Math.floor(unitsBetween / interval);
1575
+ const durationForJump = (jump) => {
1576
+ switch (unit) {
1577
+ case "years":
1578
+ return { years: jump };
1579
+ case "months":
1580
+ return { months: jump };
1581
+ case "weeks":
1582
+ return { weeks: jump };
1583
+ case "days":
1584
+ return { days: jump };
1585
+ case "hours":
1586
+ return { hours: jump };
1587
+ case "minutes":
1588
+ return { minutes: jump };
1589
+ default:
1590
+ return { seconds: jump };
1591
+ }
1592
+ };
1593
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1594
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1595
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1596
+ if (sameDate && Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1597
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1598
+ steps -= 1;
1599
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1600
+ }
1601
+ }
1560
1602
  }
1561
- let candidate = Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1562
- const dtstartForCompare = Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1603
+ const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1563
1604
  if (Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1564
1605
  candidate = dtstartForCompare;
1565
1606
  }
package/dist/index.cjs CHANGED
@@ -244,6 +244,13 @@ function parseRRuleString(input, targetTimezone, dtstart) {
244
244
  return opts;
245
245
  }
246
246
  var _RRuleTemporal = class _RRuleTemporal {
247
+ /**
248
+ * Normalize a ZonedDateTime to the polyfill implementation.
249
+ * This prevents type mismatches when mixing native and polyfill Temporal objects.
250
+ */
251
+ static normalizeToPolyfill(zdt) {
252
+ return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
253
+ }
247
254
  constructor(params) {
248
255
  var _a, _b, _c, _d, _e, _f, _g;
249
256
  let manual;
@@ -253,7 +260,7 @@ var _RRuleTemporal = class _RRuleTemporal {
253
260
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
254
261
  }
255
262
  this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
256
- this.originalDtstart = parsed.dtstart;
263
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
257
264
  manual = __spreadProps(__spreadValues({}, parsed), {
258
265
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
259
266
  count: (_c = params.count) != null ? _c : parsed.count,
@@ -270,7 +277,7 @@ var _RRuleTemporal = class _RRuleTemporal {
270
277
  }
271
278
  manual.tzid = manual.tzid || manual.dtstart.timeZoneId;
272
279
  this.tzid = manual.tzid;
273
- this.originalDtstart = manual.dtstart;
280
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
274
281
  }
275
282
  if (!manual.freq) throw new Error("RRULE must include FREQ");
276
283
  manual.interval = (_e = manual.interval) != null ? _e : 1;
@@ -280,6 +287,9 @@ var _RRuleTemporal = class _RRuleTemporal {
280
287
  if (manual.until && !(manual.until instanceof import_polyfill.Temporal.ZonedDateTime)) {
281
288
  throw new Error("Manual until must be a ZonedDateTime");
282
289
  }
290
+ if (manual.until) {
291
+ manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
292
+ }
283
293
  this.opts = this.sanitizeOpts(manual);
284
294
  this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
285
295
  this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
@@ -1505,6 +1515,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1505
1515
  const safetyMargin = Math.min(targetRuleCount, 10);
1506
1516
  return matchCount >= targetRuleCount + safetyMargin;
1507
1517
  }
1518
+ hasTimeOfDayBetween(startTime, endTime) {
1519
+ var _a, _b, _c;
1520
+ if (import_polyfill.Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1521
+ const base = this.originalDtstart;
1522
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1523
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1524
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1525
+ for (const hour of hours) {
1526
+ for (const minute of minutes) {
1527
+ for (const second of seconds) {
1528
+ const candidate = import_polyfill.Temporal.PlainTime.from({
1529
+ hour,
1530
+ minute,
1531
+ second,
1532
+ millisecond: base.millisecond,
1533
+ microsecond: base.microsecond,
1534
+ nanosecond: base.nanosecond
1535
+ });
1536
+ if (import_polyfill.Temporal.PlainTime.compare(candidate, startTime) >= 0 && import_polyfill.Temporal.PlainTime.compare(candidate, endTime) < 0) {
1537
+ return true;
1538
+ }
1539
+ }
1540
+ }
1541
+ }
1542
+ return false;
1543
+ }
1508
1544
  /**
1509
1545
  * Returns all occurrences of the rule within a specified time window.
1510
1546
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1548,39 +1584,44 @@ var _RRuleTemporal = class _RRuleTemporal {
1548
1584
  default:
1549
1585
  unit = "seconds";
1550
1586
  }
1551
- const dtstartNormalized = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1552
- const alignedNormalized = import_polyfill.Temporal.ZonedDateTime.from(
1553
- aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1587
+ const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1588
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1589
+ const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1590
+ aligned.withPlainTime(this.originalDtstart.toPlainTime())
1554
1591
  ).withTimeZone(dtstartNormalized.timeZoneId);
1555
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1592
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1593
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1556
1594
  const unitsBetween = diffDur[unit];
1557
- const steps = Math.floor(unitsBetween / interval);
1558
- let toAdd;
1559
- const jump = steps * interval;
1560
- switch (unit) {
1561
- case "years":
1562
- toAdd = { years: jump };
1563
- break;
1564
- case "months":
1565
- toAdd = { months: jump };
1566
- break;
1567
- case "weeks":
1568
- toAdd = { weeks: jump };
1569
- break;
1570
- case "days":
1571
- toAdd = { days: jump };
1572
- break;
1573
- case "hours":
1574
- toAdd = { hours: jump };
1575
- break;
1576
- case "minutes":
1577
- toAdd = { minutes: jump };
1578
- break;
1579
- default:
1580
- toAdd = { seconds: jump };
1595
+ let steps = Math.floor(unitsBetween / interval);
1596
+ const durationForJump = (jump) => {
1597
+ switch (unit) {
1598
+ case "years":
1599
+ return { years: jump };
1600
+ case "months":
1601
+ return { months: jump };
1602
+ case "weeks":
1603
+ return { weeks: jump };
1604
+ case "days":
1605
+ return { days: jump };
1606
+ case "hours":
1607
+ return { hours: jump };
1608
+ case "minutes":
1609
+ return { minutes: jump };
1610
+ default:
1611
+ return { seconds: jump };
1612
+ }
1613
+ };
1614
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1615
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1616
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1617
+ if (sameDate && import_polyfill.Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1618
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1619
+ steps -= 1;
1620
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1621
+ }
1622
+ }
1581
1623
  }
1582
- let candidate = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1583
- const dtstartForCompare = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1624
+ const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1584
1625
  if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1585
1626
  candidate = dtstartForCompare;
1586
1627
  }
package/dist/index.d.cts CHANGED
@@ -76,6 +76,11 @@ declare class RRuleTemporal {
76
76
  private readonly maxIterations;
77
77
  private readonly includeDtstart;
78
78
  private static readonly rscaleCalendarSupport;
79
+ /**
80
+ * Normalize a ZonedDateTime to the polyfill implementation.
81
+ * This prevents type mismatches when mixing native and polyfill Temporal objects.
82
+ */
83
+ private static normalizeToPolyfill;
79
84
  constructor(params: RRuleOptions);
80
85
  private sanitizeNumericArray;
81
86
  private sanitizeByDay;
@@ -173,6 +178,7 @@ declare class RRuleTemporal {
173
178
  * @returns true if the loop should break
174
179
  */
175
180
  private shouldBreakForCountLimit;
181
+ private hasTimeOfDayBetween;
176
182
  /**
177
183
  * Returns all occurrences of the rule within a specified time window.
178
184
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.d.ts CHANGED
@@ -76,6 +76,11 @@ declare class RRuleTemporal {
76
76
  private readonly maxIterations;
77
77
  private readonly includeDtstart;
78
78
  private static readonly rscaleCalendarSupport;
79
+ /**
80
+ * Normalize a ZonedDateTime to the polyfill implementation.
81
+ * This prevents type mismatches when mixing native and polyfill Temporal objects.
82
+ */
83
+ private static normalizeToPolyfill;
79
84
  constructor(params: RRuleOptions);
80
85
  private sanitizeNumericArray;
81
86
  private sanitizeByDay;
@@ -173,6 +178,7 @@ declare class RRuleTemporal {
173
178
  * @returns true if the loop should break
174
179
  */
175
180
  private shouldBreakForCountLimit;
181
+ private hasTimeOfDayBetween;
176
182
  /**
177
183
  * Returns all occurrences of the rule within a specified time window.
178
184
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-BN57WTKY.js";
3
+ } from "./chunk-5IREWES7.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -246,6 +246,13 @@ function parseRRuleString(input, targetTimezone, dtstart) {
246
246
  return opts;
247
247
  }
248
248
  var _RRuleTemporal = class _RRuleTemporal {
249
+ /**
250
+ * Normalize a ZonedDateTime to the polyfill implementation.
251
+ * This prevents type mismatches when mixing native and polyfill Temporal objects.
252
+ */
253
+ static normalizeToPolyfill(zdt) {
254
+ return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
255
+ }
249
256
  constructor(params) {
250
257
  var _a, _b, _c, _d, _e, _f, _g;
251
258
  let manual;
@@ -255,7 +262,7 @@ var _RRuleTemporal = class _RRuleTemporal {
255
262
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
256
263
  }
257
264
  this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
258
- this.originalDtstart = parsed.dtstart;
265
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
259
266
  manual = __spreadProps(__spreadValues({}, parsed), {
260
267
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
261
268
  count: (_c = params.count) != null ? _c : parsed.count,
@@ -272,7 +279,7 @@ var _RRuleTemporal = class _RRuleTemporal {
272
279
  }
273
280
  manual.tzid = manual.tzid || manual.dtstart.timeZoneId;
274
281
  this.tzid = manual.tzid;
275
- this.originalDtstart = manual.dtstart;
282
+ this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
276
283
  }
277
284
  if (!manual.freq) throw new Error("RRULE must include FREQ");
278
285
  manual.interval = (_e = manual.interval) != null ? _e : 1;
@@ -282,6 +289,9 @@ var _RRuleTemporal = class _RRuleTemporal {
282
289
  if (manual.until && !(manual.until instanceof import_polyfill.Temporal.ZonedDateTime)) {
283
290
  throw new Error("Manual until must be a ZonedDateTime");
284
291
  }
292
+ if (manual.until) {
293
+ manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
294
+ }
285
295
  this.opts = this.sanitizeOpts(manual);
286
296
  this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
287
297
  this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
@@ -1507,6 +1517,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1507
1517
  const safetyMargin = Math.min(targetRuleCount, 10);
1508
1518
  return matchCount >= targetRuleCount + safetyMargin;
1509
1519
  }
1520
+ hasTimeOfDayBetween(startTime, endTime) {
1521
+ var _a, _b, _c;
1522
+ if (import_polyfill.Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1523
+ const base = this.originalDtstart;
1524
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1525
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1526
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1527
+ for (const hour of hours) {
1528
+ for (const minute of minutes) {
1529
+ for (const second of seconds) {
1530
+ const candidate = import_polyfill.Temporal.PlainTime.from({
1531
+ hour,
1532
+ minute,
1533
+ second,
1534
+ millisecond: base.millisecond,
1535
+ microsecond: base.microsecond,
1536
+ nanosecond: base.nanosecond
1537
+ });
1538
+ if (import_polyfill.Temporal.PlainTime.compare(candidate, startTime) >= 0 && import_polyfill.Temporal.PlainTime.compare(candidate, endTime) < 0) {
1539
+ return true;
1540
+ }
1541
+ }
1542
+ }
1543
+ }
1544
+ return false;
1545
+ }
1510
1546
  /**
1511
1547
  * Returns all occurrences of the rule within a specified time window.
1512
1548
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1550,39 +1586,44 @@ var _RRuleTemporal = class _RRuleTemporal {
1550
1586
  default:
1551
1587
  unit = "seconds";
1552
1588
  }
1553
- const dtstartNormalized = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1554
- const alignedNormalized = import_polyfill.Temporal.ZonedDateTime.from(
1555
- aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1589
+ const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1590
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1591
+ const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1592
+ aligned.withPlainTime(this.originalDtstart.toPlainTime())
1556
1593
  ).withTimeZone(dtstartNormalized.timeZoneId);
1557
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1594
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1595
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1558
1596
  const unitsBetween = diffDur[unit];
1559
- const steps = Math.floor(unitsBetween / interval);
1560
- let toAdd;
1561
- const jump = steps * interval;
1562
- switch (unit) {
1563
- case "years":
1564
- toAdd = { years: jump };
1565
- break;
1566
- case "months":
1567
- toAdd = { months: jump };
1568
- break;
1569
- case "weeks":
1570
- toAdd = { weeks: jump };
1571
- break;
1572
- case "days":
1573
- toAdd = { days: jump };
1574
- break;
1575
- case "hours":
1576
- toAdd = { hours: jump };
1577
- break;
1578
- case "minutes":
1579
- toAdd = { minutes: jump };
1580
- break;
1581
- default:
1582
- toAdd = { seconds: jump };
1597
+ let steps = Math.floor(unitsBetween / interval);
1598
+ const durationForJump = (jump) => {
1599
+ switch (unit) {
1600
+ case "years":
1601
+ return { years: jump };
1602
+ case "months":
1603
+ return { months: jump };
1604
+ case "weeks":
1605
+ return { weeks: jump };
1606
+ case "days":
1607
+ return { days: jump };
1608
+ case "hours":
1609
+ return { hours: jump };
1610
+ case "minutes":
1611
+ return { minutes: jump };
1612
+ default:
1613
+ return { seconds: jump };
1614
+ }
1615
+ };
1616
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1617
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1618
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1619
+ if (sameDate && import_polyfill.Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1620
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1621
+ steps -= 1;
1622
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1623
+ }
1624
+ }
1583
1625
  }
1584
- let candidate = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1585
- const dtstartForCompare = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1626
+ const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1586
1627
  if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1587
1628
  candidate = dtstartForCompare;
1588
1629
  }
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-BN57WTKY.js";
3
+ } from "./chunk-5IREWES7.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Recurrence rule (rrule) processing using Temporal PlainDate/PlainDateTime, with cross-timezone and cross-calendar rrule support",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",