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.
- package/dist/{chunk-BN57WTKY.js → chunk-5IREWES7.js} +73 -32
- package/dist/index.cjs +73 -32
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/totext.cjs +73 -32
- package/dist/totext.js +1 -1
- package/package.json +1 -1
|
@@ -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 =
|
|
1531
|
-
const
|
|
1532
|
-
|
|
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
|
|
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
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
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
|
-
|
|
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 =
|
|
1552
|
-
const
|
|
1553
|
-
|
|
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
|
|
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
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
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
|
-
|
|
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
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 =
|
|
1554
|
-
const
|
|
1555
|
-
|
|
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
|
|
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
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
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
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-temporal",
|
|
3
|
-
"version": "1.4.
|
|
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",
|