rrule-temporal 1.3.0 → 1.4.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.
- package/README.md +3 -0
- package/dist/{chunk-R242V3P5.js → chunk-76UOKZYT.js} +48 -0
- package/dist/index.cjs +48 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -1
- package/dist/totext.cjs +48 -0
- package/dist/totext.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,7 @@ below. These correspond to the recurrence rule parts defined in RFC 5545:
|
|
|
105
105
|
| `tzid` | Time zone identifier for interpreting dates. |
|
|
106
106
|
| `maxIterations` | Safety cap when generating occurrences. |
|
|
107
107
|
| `includeDtstart` | Include `DTSTART` even if it does not match the pattern. |
|
|
108
|
+
| `strict` | Enforce RFC 5545 constraints strictly (defaults to false). |
|
|
108
109
|
| `dtstart` | First occurrence as `Temporal.ZonedDateTime`. |
|
|
109
110
|
|
|
110
111
|
## Querying occurrences
|
|
@@ -267,6 +268,8 @@ Notes
|
|
|
267
268
|
| `new RRuleTemporal(opts)` | Create a rule from an ICS snippet or manual options. |
|
|
268
269
|
| `all(iterator?)` | Return every occurrence. When the rule has no end the optional iterator is required. |
|
|
269
270
|
| `between(after, before, inclusive?)` | Occurrences within a time range. |
|
|
271
|
+
| `matches(date)` | Convenience helper: true if the exact instant is an occurrence (accepts `Date` or `Temporal.ZonedDateTime`). |
|
|
272
|
+
| `occursOn(date)` | Convenience helper: true if any occurrence falls on the given `Temporal.PlainDate` in the rule's time zone (date-only, ignores time). |
|
|
270
273
|
| `next(after?, inclusive?)` | Next occurrence after a given date. |
|
|
271
274
|
| `previous(before?, inclusive?)` | Previous occurrence before a date. |
|
|
272
275
|
| `toString()` | Convert the rule back into `DTSTART` and `RRULE` lines. |
|
|
@@ -215,6 +215,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
215
215
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
216
216
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
217
217
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
218
|
+
strict: params.strict,
|
|
218
219
|
maxIterations: params.maxIterations,
|
|
219
220
|
includeDtstart: params.includeDtstart,
|
|
220
221
|
tzid: this.tzid
|
|
@@ -264,6 +265,33 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
264
265
|
}
|
|
265
266
|
return days.length > 0 ? days : void 0;
|
|
266
267
|
}
|
|
268
|
+
enforceStrictRfc(opts) {
|
|
269
|
+
var _a;
|
|
270
|
+
if (!opts.strict) return;
|
|
271
|
+
const freq = opts.freq;
|
|
272
|
+
if (opts.byWeekNo && freq !== "YEARLY") {
|
|
273
|
+
throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
|
|
274
|
+
}
|
|
275
|
+
if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
|
|
276
|
+
throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
|
|
277
|
+
}
|
|
278
|
+
if (opts.byMonthDay && freq === "WEEKLY") {
|
|
279
|
+
throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
|
|
280
|
+
}
|
|
281
|
+
const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
|
|
282
|
+
if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
|
|
283
|
+
throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
|
|
284
|
+
}
|
|
285
|
+
if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
|
|
286
|
+
throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
|
|
287
|
+
}
|
|
288
|
+
const hasOtherBy = Boolean(
|
|
289
|
+
opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
|
|
290
|
+
);
|
|
291
|
+
if (opts.bySetPos && !hasOtherBy) {
|
|
292
|
+
throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
267
295
|
sanitizeOpts(opts) {
|
|
268
296
|
var _a;
|
|
269
297
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -289,6 +317,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
289
317
|
}
|
|
290
318
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
291
319
|
}
|
|
320
|
+
this.enforceStrictRfc(opts);
|
|
292
321
|
return opts;
|
|
293
322
|
}
|
|
294
323
|
rawAdvance(zdt) {
|
|
@@ -1518,6 +1547,25 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1518
1547
|
return afterStart && beforeEnd;
|
|
1519
1548
|
});
|
|
1520
1549
|
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Convenience helper: true if the exact instant is an occurrence of the rule.
|
|
1552
|
+
* This checks full date-time equality (including time and time zone).
|
|
1553
|
+
*/
|
|
1554
|
+
matches(date) {
|
|
1555
|
+
return this.between(date, date, true).length > 0;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Convenience helper: true if any occurrence falls on the given calendar day
|
|
1559
|
+
* in the rule's time zone. This ignores time-of-day granularity.
|
|
1560
|
+
*/
|
|
1561
|
+
occursOn(date) {
|
|
1562
|
+
const startOfDay = date.toZonedDateTime({
|
|
1563
|
+
timeZone: this.tzid,
|
|
1564
|
+
plainTime: Temporal.PlainTime.from("00:00")
|
|
1565
|
+
});
|
|
1566
|
+
const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
|
|
1567
|
+
return this.between(startOfDay, endOfDay, true).length > 0;
|
|
1568
|
+
}
|
|
1521
1569
|
/**
|
|
1522
1570
|
* Returns the next occurrence of the rule after a specified date.
|
|
1523
1571
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
package/dist/index.cjs
CHANGED
|
@@ -236,6 +236,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
236
236
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
237
237
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
238
238
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
239
|
+
strict: params.strict,
|
|
239
240
|
maxIterations: params.maxIterations,
|
|
240
241
|
includeDtstart: params.includeDtstart,
|
|
241
242
|
tzid: this.tzid
|
|
@@ -285,6 +286,33 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
285
286
|
}
|
|
286
287
|
return days.length > 0 ? days : void 0;
|
|
287
288
|
}
|
|
289
|
+
enforceStrictRfc(opts) {
|
|
290
|
+
var _a;
|
|
291
|
+
if (!opts.strict) return;
|
|
292
|
+
const freq = opts.freq;
|
|
293
|
+
if (opts.byWeekNo && freq !== "YEARLY") {
|
|
294
|
+
throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
|
|
295
|
+
}
|
|
296
|
+
if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
|
|
297
|
+
throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
|
|
298
|
+
}
|
|
299
|
+
if (opts.byMonthDay && freq === "WEEKLY") {
|
|
300
|
+
throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
|
|
301
|
+
}
|
|
302
|
+
const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
|
|
303
|
+
if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
|
|
304
|
+
throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
|
|
305
|
+
}
|
|
306
|
+
if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
|
|
307
|
+
throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
|
|
308
|
+
}
|
|
309
|
+
const hasOtherBy = Boolean(
|
|
310
|
+
opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
|
|
311
|
+
);
|
|
312
|
+
if (opts.bySetPos && !hasOtherBy) {
|
|
313
|
+
throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
|
|
314
|
+
}
|
|
315
|
+
}
|
|
288
316
|
sanitizeOpts(opts) {
|
|
289
317
|
var _a;
|
|
290
318
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -310,6 +338,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
310
338
|
}
|
|
311
339
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
312
340
|
}
|
|
341
|
+
this.enforceStrictRfc(opts);
|
|
313
342
|
return opts;
|
|
314
343
|
}
|
|
315
344
|
rawAdvance(zdt) {
|
|
@@ -1539,6 +1568,25 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1539
1568
|
return afterStart && beforeEnd;
|
|
1540
1569
|
});
|
|
1541
1570
|
}
|
|
1571
|
+
/**
|
|
1572
|
+
* Convenience helper: true if the exact instant is an occurrence of the rule.
|
|
1573
|
+
* This checks full date-time equality (including time and time zone).
|
|
1574
|
+
*/
|
|
1575
|
+
matches(date) {
|
|
1576
|
+
return this.between(date, date, true).length > 0;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Convenience helper: true if any occurrence falls on the given calendar day
|
|
1580
|
+
* in the rule's time zone. This ignores time-of-day granularity.
|
|
1581
|
+
*/
|
|
1582
|
+
occursOn(date) {
|
|
1583
|
+
const startOfDay = date.toZonedDateTime({
|
|
1584
|
+
timeZone: this.tzid,
|
|
1585
|
+
plainTime: import_polyfill.Temporal.PlainTime.from("00:00")
|
|
1586
|
+
});
|
|
1587
|
+
const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
|
|
1588
|
+
return this.between(startOfDay, endOfDay, true).length > 0;
|
|
1589
|
+
}
|
|
1542
1590
|
/**
|
|
1543
1591
|
* Returns the next occurrence of the rule after a specified date.
|
|
1544
1592
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,8 @@ interface BaseOpts {
|
|
|
11
11
|
maxIterations?: number;
|
|
12
12
|
/** Include DTSTART as an occurrence even if it does not match the rule pattern. */
|
|
13
13
|
includeDtstart?: boolean;
|
|
14
|
+
/** Enforce RFC 5545 constraints strictly (defaults to false). */
|
|
15
|
+
strict?: boolean;
|
|
14
16
|
/** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
|
|
15
17
|
rscale?: string;
|
|
16
18
|
/** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
|
|
@@ -77,6 +79,7 @@ declare class RRuleTemporal {
|
|
|
77
79
|
constructor(params: RRuleOptions);
|
|
78
80
|
private sanitizeNumericArray;
|
|
79
81
|
private sanitizeByDay;
|
|
82
|
+
private enforceStrictRfc;
|
|
80
83
|
private sanitizeOpts;
|
|
81
84
|
private rawAdvance;
|
|
82
85
|
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
|
|
@@ -178,6 +181,16 @@ declare class RRuleTemporal {
|
|
|
178
181
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
|
|
179
182
|
*/
|
|
180
183
|
between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
|
|
184
|
+
/**
|
|
185
|
+
* Convenience helper: true if the exact instant is an occurrence of the rule.
|
|
186
|
+
* This checks full date-time equality (including time and time zone).
|
|
187
|
+
*/
|
|
188
|
+
matches(date: DateFilter): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Convenience helper: true if any occurrence falls on the given calendar day
|
|
191
|
+
* in the rule's time zone. This ignores time-of-day granularity.
|
|
192
|
+
*/
|
|
193
|
+
occursOn(date: Temporal.PlainDate): boolean;
|
|
181
194
|
/**
|
|
182
195
|
* Returns the next occurrence of the rule after a specified date.
|
|
183
196
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface BaseOpts {
|
|
|
11
11
|
maxIterations?: number;
|
|
12
12
|
/** Include DTSTART as an occurrence even if it does not match the rule pattern. */
|
|
13
13
|
includeDtstart?: boolean;
|
|
14
|
+
/** Enforce RFC 5545 constraints strictly (defaults to false). */
|
|
15
|
+
strict?: boolean;
|
|
14
16
|
/** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
|
|
15
17
|
rscale?: string;
|
|
16
18
|
/** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
|
|
@@ -77,6 +79,7 @@ declare class RRuleTemporal {
|
|
|
77
79
|
constructor(params: RRuleOptions);
|
|
78
80
|
private sanitizeNumericArray;
|
|
79
81
|
private sanitizeByDay;
|
|
82
|
+
private enforceStrictRfc;
|
|
80
83
|
private sanitizeOpts;
|
|
81
84
|
private rawAdvance;
|
|
82
85
|
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
|
|
@@ -178,6 +181,16 @@ declare class RRuleTemporal {
|
|
|
178
181
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
|
|
179
182
|
*/
|
|
180
183
|
between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
|
|
184
|
+
/**
|
|
185
|
+
* Convenience helper: true if the exact instant is an occurrence of the rule.
|
|
186
|
+
* This checks full date-time equality (including time and time zone).
|
|
187
|
+
*/
|
|
188
|
+
matches(date: DateFilter): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Convenience helper: true if any occurrence falls on the given calendar day
|
|
191
|
+
* in the rule's time zone. This ignores time-of-day granularity.
|
|
192
|
+
*/
|
|
193
|
+
occursOn(date: Temporal.PlainDate): boolean;
|
|
181
194
|
/**
|
|
182
195
|
* Returns the next occurrence of the rule after a specified date.
|
|
183
196
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
package/dist/index.js
CHANGED
package/dist/totext.cjs
CHANGED
|
@@ -238,6 +238,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
238
238
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
239
239
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
240
240
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
241
|
+
strict: params.strict,
|
|
241
242
|
maxIterations: params.maxIterations,
|
|
242
243
|
includeDtstart: params.includeDtstart,
|
|
243
244
|
tzid: this.tzid
|
|
@@ -287,6 +288,33 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
287
288
|
}
|
|
288
289
|
return days.length > 0 ? days : void 0;
|
|
289
290
|
}
|
|
291
|
+
enforceStrictRfc(opts) {
|
|
292
|
+
var _a;
|
|
293
|
+
if (!opts.strict) return;
|
|
294
|
+
const freq = opts.freq;
|
|
295
|
+
if (opts.byWeekNo && freq !== "YEARLY") {
|
|
296
|
+
throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
|
|
297
|
+
}
|
|
298
|
+
if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
|
|
299
|
+
throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
|
|
300
|
+
}
|
|
301
|
+
if (opts.byMonthDay && freq === "WEEKLY") {
|
|
302
|
+
throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
|
|
303
|
+
}
|
|
304
|
+
const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
|
|
305
|
+
if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
|
|
306
|
+
throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
|
|
307
|
+
}
|
|
308
|
+
if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
|
|
309
|
+
throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
|
|
310
|
+
}
|
|
311
|
+
const hasOtherBy = Boolean(
|
|
312
|
+
opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
|
|
313
|
+
);
|
|
314
|
+
if (opts.bySetPos && !hasOtherBy) {
|
|
315
|
+
throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
290
318
|
sanitizeOpts(opts) {
|
|
291
319
|
var _a;
|
|
292
320
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -312,6 +340,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
312
340
|
}
|
|
313
341
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
314
342
|
}
|
|
343
|
+
this.enforceStrictRfc(opts);
|
|
315
344
|
return opts;
|
|
316
345
|
}
|
|
317
346
|
rawAdvance(zdt) {
|
|
@@ -1541,6 +1570,25 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1541
1570
|
return afterStart && beforeEnd;
|
|
1542
1571
|
});
|
|
1543
1572
|
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Convenience helper: true if the exact instant is an occurrence of the rule.
|
|
1575
|
+
* This checks full date-time equality (including time and time zone).
|
|
1576
|
+
*/
|
|
1577
|
+
matches(date) {
|
|
1578
|
+
return this.between(date, date, true).length > 0;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Convenience helper: true if any occurrence falls on the given calendar day
|
|
1582
|
+
* in the rule's time zone. This ignores time-of-day granularity.
|
|
1583
|
+
*/
|
|
1584
|
+
occursOn(date) {
|
|
1585
|
+
const startOfDay = date.toZonedDateTime({
|
|
1586
|
+
timeZone: this.tzid,
|
|
1587
|
+
plainTime: import_polyfill.Temporal.PlainTime.from("00:00")
|
|
1588
|
+
});
|
|
1589
|
+
const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
|
|
1590
|
+
return this.between(startOfDay, endOfDay, true).length > 0;
|
|
1591
|
+
}
|
|
1544
1592
|
/**
|
|
1545
1593
|
* Returns the next occurrence of the rule after a specified date.
|
|
1546
1594
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
package/dist/totext.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-temporal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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",
|