rrule-temporal 1.2.7 → 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-SWKVAJTZ.js → chunk-76UOKZYT.js} +178 -1
- package/dist/index.cjs +178 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +1 -1
- package/dist/totext.cjs +178 -1
- 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. |
|
|
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
20
32
|
|
|
21
33
|
// src/index.ts
|
|
22
34
|
import { Temporal } from "@js-temporal/polyfill";
|
|
@@ -188,7 +200,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
188
200
|
}
|
|
189
201
|
return opts;
|
|
190
202
|
}
|
|
191
|
-
var
|
|
203
|
+
var _RRuleTemporal = class _RRuleTemporal {
|
|
192
204
|
constructor(params) {
|
|
193
205
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
194
206
|
let manual;
|
|
@@ -203,6 +215,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
203
215
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
204
216
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
205
217
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
218
|
+
strict: params.strict,
|
|
206
219
|
maxIterations: params.maxIterations,
|
|
207
220
|
includeDtstart: params.includeDtstart,
|
|
208
221
|
tzid: this.tzid
|
|
@@ -252,6 +265,33 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
252
265
|
}
|
|
253
266
|
return days.length > 0 ? days : void 0;
|
|
254
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
|
+
}
|
|
255
295
|
sanitizeOpts(opts) {
|
|
256
296
|
var _a;
|
|
257
297
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -277,6 +317,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
277
317
|
}
|
|
278
318
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
279
319
|
}
|
|
320
|
+
this.enforceStrictRfc(opts);
|
|
280
321
|
return opts;
|
|
281
322
|
}
|
|
282
323
|
rawAdvance(zdt) {
|
|
@@ -678,6 +719,99 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
678
719
|
options() {
|
|
679
720
|
return this.opts;
|
|
680
721
|
}
|
|
722
|
+
cloneOptions() {
|
|
723
|
+
const _a = this.opts, {
|
|
724
|
+
byHour,
|
|
725
|
+
byMinute,
|
|
726
|
+
bySecond,
|
|
727
|
+
byDay,
|
|
728
|
+
byMonth,
|
|
729
|
+
byMonthDay,
|
|
730
|
+
byYearDay,
|
|
731
|
+
byWeekNo,
|
|
732
|
+
bySetPos,
|
|
733
|
+
rDate,
|
|
734
|
+
exDate
|
|
735
|
+
} = _a, rest = __objRest(_a, [
|
|
736
|
+
"byHour",
|
|
737
|
+
"byMinute",
|
|
738
|
+
"bySecond",
|
|
739
|
+
"byDay",
|
|
740
|
+
"byMonth",
|
|
741
|
+
"byMonthDay",
|
|
742
|
+
"byYearDay",
|
|
743
|
+
"byWeekNo",
|
|
744
|
+
"bySetPos",
|
|
745
|
+
"rDate",
|
|
746
|
+
"exDate"
|
|
747
|
+
]);
|
|
748
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
749
|
+
byHour: byHour ? [...byHour] : void 0,
|
|
750
|
+
byMinute: byMinute ? [...byMinute] : void 0,
|
|
751
|
+
bySecond: bySecond ? [...bySecond] : void 0,
|
|
752
|
+
byDay: byDay ? [...byDay] : void 0,
|
|
753
|
+
byMonth: byMonth ? [...byMonth] : void 0,
|
|
754
|
+
byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
|
|
755
|
+
byYearDay: byYearDay ? [...byYearDay] : void 0,
|
|
756
|
+
byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
|
|
757
|
+
bySetPos: bySetPos ? [...bySetPos] : void 0,
|
|
758
|
+
rDate: rDate ? [...rDate] : void 0,
|
|
759
|
+
exDate: exDate ? [...exDate] : void 0
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
cloneUpdateOptions(updates) {
|
|
763
|
+
const cloned = {};
|
|
764
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
|
|
765
|
+
cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
|
|
766
|
+
}
|
|
767
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
|
|
768
|
+
cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
|
|
769
|
+
}
|
|
770
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
|
|
771
|
+
cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
|
|
772
|
+
}
|
|
773
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
|
|
774
|
+
cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
|
|
775
|
+
}
|
|
776
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
|
|
777
|
+
cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
|
|
778
|
+
}
|
|
779
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
|
|
780
|
+
cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
|
|
781
|
+
}
|
|
782
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
|
|
783
|
+
cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
|
|
784
|
+
}
|
|
785
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
|
|
786
|
+
cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
|
|
787
|
+
}
|
|
788
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
|
|
789
|
+
cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
|
|
790
|
+
}
|
|
791
|
+
if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
|
|
792
|
+
cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
|
|
793
|
+
}
|
|
794
|
+
if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
|
|
795
|
+
cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
|
|
796
|
+
}
|
|
797
|
+
return cloned;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* const updated = rule.with({byMonthDay: [3]});
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
with(updates) {
|
|
808
|
+
var _a, _b;
|
|
809
|
+
const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
|
|
810
|
+
tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
|
|
811
|
+
dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
|
|
812
|
+
});
|
|
813
|
+
return new _RRuleTemporal(merged);
|
|
814
|
+
}
|
|
681
815
|
addDtstartIfNeeded(dates, iterator) {
|
|
682
816
|
if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
|
|
683
817
|
if (iterator && this.isExcluded(this.originalDtstart)) {
|
|
@@ -1413,6 +1547,25 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1413
1547
|
return afterStart && beforeEnd;
|
|
1414
1548
|
});
|
|
1415
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
|
+
}
|
|
1416
1569
|
/**
|
|
1417
1570
|
* Returns the next occurrence of the rule after a specified date.
|
|
1418
1571
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
@@ -1850,6 +2003,27 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1850
2003
|
const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
|
|
1851
2004
|
return map[r] || null;
|
|
1852
2005
|
}
|
|
2006
|
+
assertRscaleCalendarSupported(calId) {
|
|
2007
|
+
if (calId === "gregory" || calId === "iso8601") return;
|
|
2008
|
+
const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
|
|
2009
|
+
if (cached === true) return;
|
|
2010
|
+
if (cached === false) {
|
|
2011
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2012
|
+
}
|
|
2013
|
+
let supported = true;
|
|
2014
|
+
try {
|
|
2015
|
+
const probe = Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
|
|
2016
|
+
void probe.year;
|
|
2017
|
+
void probe.monthCode;
|
|
2018
|
+
void probe.day;
|
|
2019
|
+
} catch (e) {
|
|
2020
|
+
supported = false;
|
|
2021
|
+
}
|
|
2022
|
+
_RRuleTemporal.rscaleCalendarSupport[calId] = supported;
|
|
2023
|
+
if (!supported) {
|
|
2024
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
1853
2027
|
pad2(n) {
|
|
1854
2028
|
return String(n).padStart(2, "0");
|
|
1855
2029
|
}
|
|
@@ -2021,6 +2195,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2021
2195
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2022
2196
|
const calId = this.getRscaleCalendarId();
|
|
2023
2197
|
if (!calId) return this._allFallback(iterator);
|
|
2198
|
+
this.assertRscaleCalendarSupported(calId);
|
|
2024
2199
|
const dates = [];
|
|
2025
2200
|
let iterationCount = 0;
|
|
2026
2201
|
const start = this.originalDtstart;
|
|
@@ -2249,6 +2424,8 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2249
2424
|
return this._allFallback(iterator);
|
|
2250
2425
|
}
|
|
2251
2426
|
};
|
|
2427
|
+
_RRuleTemporal.rscaleCalendarSupport = {};
|
|
2428
|
+
var RRuleTemporal = _RRuleTemporal;
|
|
2252
2429
|
|
|
2253
2430
|
export {
|
|
2254
2431
|
RRuleTemporal
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
|
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
23
35
|
var __export = (target, all) => {
|
|
24
36
|
for (var name in all)
|
|
25
37
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -209,7 +221,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
209
221
|
}
|
|
210
222
|
return opts;
|
|
211
223
|
}
|
|
212
|
-
var
|
|
224
|
+
var _RRuleTemporal = class _RRuleTemporal {
|
|
213
225
|
constructor(params) {
|
|
214
226
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
215
227
|
let manual;
|
|
@@ -224,6 +236,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
224
236
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
225
237
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
226
238
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
239
|
+
strict: params.strict,
|
|
227
240
|
maxIterations: params.maxIterations,
|
|
228
241
|
includeDtstart: params.includeDtstart,
|
|
229
242
|
tzid: this.tzid
|
|
@@ -273,6 +286,33 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
273
286
|
}
|
|
274
287
|
return days.length > 0 ? days : void 0;
|
|
275
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
|
+
}
|
|
276
316
|
sanitizeOpts(opts) {
|
|
277
317
|
var _a;
|
|
278
318
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -298,6 +338,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
298
338
|
}
|
|
299
339
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
300
340
|
}
|
|
341
|
+
this.enforceStrictRfc(opts);
|
|
301
342
|
return opts;
|
|
302
343
|
}
|
|
303
344
|
rawAdvance(zdt) {
|
|
@@ -699,6 +740,99 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
699
740
|
options() {
|
|
700
741
|
return this.opts;
|
|
701
742
|
}
|
|
743
|
+
cloneOptions() {
|
|
744
|
+
const _a = this.opts, {
|
|
745
|
+
byHour,
|
|
746
|
+
byMinute,
|
|
747
|
+
bySecond,
|
|
748
|
+
byDay,
|
|
749
|
+
byMonth,
|
|
750
|
+
byMonthDay,
|
|
751
|
+
byYearDay,
|
|
752
|
+
byWeekNo,
|
|
753
|
+
bySetPos,
|
|
754
|
+
rDate,
|
|
755
|
+
exDate
|
|
756
|
+
} = _a, rest = __objRest(_a, [
|
|
757
|
+
"byHour",
|
|
758
|
+
"byMinute",
|
|
759
|
+
"bySecond",
|
|
760
|
+
"byDay",
|
|
761
|
+
"byMonth",
|
|
762
|
+
"byMonthDay",
|
|
763
|
+
"byYearDay",
|
|
764
|
+
"byWeekNo",
|
|
765
|
+
"bySetPos",
|
|
766
|
+
"rDate",
|
|
767
|
+
"exDate"
|
|
768
|
+
]);
|
|
769
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
770
|
+
byHour: byHour ? [...byHour] : void 0,
|
|
771
|
+
byMinute: byMinute ? [...byMinute] : void 0,
|
|
772
|
+
bySecond: bySecond ? [...bySecond] : void 0,
|
|
773
|
+
byDay: byDay ? [...byDay] : void 0,
|
|
774
|
+
byMonth: byMonth ? [...byMonth] : void 0,
|
|
775
|
+
byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
|
|
776
|
+
byYearDay: byYearDay ? [...byYearDay] : void 0,
|
|
777
|
+
byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
|
|
778
|
+
bySetPos: bySetPos ? [...bySetPos] : void 0,
|
|
779
|
+
rDate: rDate ? [...rDate] : void 0,
|
|
780
|
+
exDate: exDate ? [...exDate] : void 0
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
cloneUpdateOptions(updates) {
|
|
784
|
+
const cloned = {};
|
|
785
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
|
|
786
|
+
cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
|
|
787
|
+
}
|
|
788
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
|
|
789
|
+
cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
|
|
790
|
+
}
|
|
791
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
|
|
792
|
+
cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
|
|
793
|
+
}
|
|
794
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
|
|
795
|
+
cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
|
|
796
|
+
}
|
|
797
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
|
|
798
|
+
cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
|
|
799
|
+
}
|
|
800
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
|
|
801
|
+
cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
|
|
802
|
+
}
|
|
803
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
|
|
804
|
+
cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
|
|
805
|
+
}
|
|
806
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
|
|
807
|
+
cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
|
|
808
|
+
}
|
|
809
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
|
|
810
|
+
cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
|
|
811
|
+
}
|
|
812
|
+
if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
|
|
813
|
+
cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
|
|
814
|
+
}
|
|
815
|
+
if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
|
|
816
|
+
cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
|
|
817
|
+
}
|
|
818
|
+
return cloned;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```ts
|
|
825
|
+
* const updated = rule.with({byMonthDay: [3]});
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
with(updates) {
|
|
829
|
+
var _a, _b;
|
|
830
|
+
const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
|
|
831
|
+
tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
|
|
832
|
+
dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
|
|
833
|
+
});
|
|
834
|
+
return new _RRuleTemporal(merged);
|
|
835
|
+
}
|
|
702
836
|
addDtstartIfNeeded(dates, iterator) {
|
|
703
837
|
if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
|
|
704
838
|
if (iterator && this.isExcluded(this.originalDtstart)) {
|
|
@@ -1434,6 +1568,25 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1434
1568
|
return afterStart && beforeEnd;
|
|
1435
1569
|
});
|
|
1436
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
|
+
}
|
|
1437
1590
|
/**
|
|
1438
1591
|
* Returns the next occurrence of the rule after a specified date.
|
|
1439
1592
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
@@ -1871,6 +2024,27 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1871
2024
|
const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
|
|
1872
2025
|
return map[r] || null;
|
|
1873
2026
|
}
|
|
2027
|
+
assertRscaleCalendarSupported(calId) {
|
|
2028
|
+
if (calId === "gregory" || calId === "iso8601") return;
|
|
2029
|
+
const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
|
|
2030
|
+
if (cached === true) return;
|
|
2031
|
+
if (cached === false) {
|
|
2032
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2033
|
+
}
|
|
2034
|
+
let supported = true;
|
|
2035
|
+
try {
|
|
2036
|
+
const probe = import_polyfill.Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
|
|
2037
|
+
void probe.year;
|
|
2038
|
+
void probe.monthCode;
|
|
2039
|
+
void probe.day;
|
|
2040
|
+
} catch (e) {
|
|
2041
|
+
supported = false;
|
|
2042
|
+
}
|
|
2043
|
+
_RRuleTemporal.rscaleCalendarSupport[calId] = supported;
|
|
2044
|
+
if (!supported) {
|
|
2045
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
1874
2048
|
pad2(n) {
|
|
1875
2049
|
return String(n).padStart(2, "0");
|
|
1876
2050
|
}
|
|
@@ -2042,6 +2216,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2042
2216
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2043
2217
|
const calId = this.getRscaleCalendarId();
|
|
2044
2218
|
if (!calId) return this._allFallback(iterator);
|
|
2219
|
+
this.assertRscaleCalendarSupported(calId);
|
|
2045
2220
|
const dates = [];
|
|
2046
2221
|
let iterationCount = 0;
|
|
2047
2222
|
const start = this.originalDtstart;
|
|
@@ -2270,6 +2445,8 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2270
2445
|
return this._allFallback(iterator);
|
|
2271
2446
|
}
|
|
2272
2447
|
};
|
|
2448
|
+
_RRuleTemporal.rscaleCalendarSupport = {};
|
|
2449
|
+
var RRuleTemporal = _RRuleTemporal;
|
|
2273
2450
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2274
2451
|
0 && (module.exports = {
|
|
2275
2452
|
RRuleTemporal
|
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). */
|
|
@@ -73,9 +75,11 @@ declare class RRuleTemporal {
|
|
|
73
75
|
private readonly opts;
|
|
74
76
|
private readonly maxIterations;
|
|
75
77
|
private readonly includeDtstart;
|
|
78
|
+
private static readonly rscaleCalendarSupport;
|
|
76
79
|
constructor(params: RRuleOptions);
|
|
77
80
|
private sanitizeNumericArray;
|
|
78
81
|
private sanitizeByDay;
|
|
82
|
+
private enforceStrictRfc;
|
|
79
83
|
private sanitizeOpts;
|
|
80
84
|
private rawAdvance;
|
|
81
85
|
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
|
|
@@ -98,6 +102,17 @@ declare class RRuleTemporal {
|
|
|
98
102
|
private getIsoWeekInfo;
|
|
99
103
|
private matchesByWeekNo;
|
|
100
104
|
options(): ManualOpts;
|
|
105
|
+
private cloneOptions;
|
|
106
|
+
private cloneUpdateOptions;
|
|
107
|
+
/**
|
|
108
|
+
* Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const updated = rule.with({byMonthDay: [3]});
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
with(updates: Partial<ManualOpts>): RRuleTemporal;
|
|
101
116
|
private addDtstartIfNeeded;
|
|
102
117
|
private processOccurrences;
|
|
103
118
|
/**
|
|
@@ -166,6 +181,16 @@ declare class RRuleTemporal {
|
|
|
166
181
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
|
|
167
182
|
*/
|
|
168
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;
|
|
169
194
|
/**
|
|
170
195
|
* Returns the next occurrence of the rule after a specified date.
|
|
171
196
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
@@ -211,6 +236,7 @@ declare class RRuleTemporal {
|
|
|
211
236
|
*/
|
|
212
237
|
private generateOccurrencesForWeekInYear;
|
|
213
238
|
private getRscaleCalendarId;
|
|
239
|
+
private assertRscaleCalendarSupported;
|
|
214
240
|
private pad2;
|
|
215
241
|
private monthMatchesToken;
|
|
216
242
|
private monthsOfYear;
|
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). */
|
|
@@ -73,9 +75,11 @@ declare class RRuleTemporal {
|
|
|
73
75
|
private readonly opts;
|
|
74
76
|
private readonly maxIterations;
|
|
75
77
|
private readonly includeDtstart;
|
|
78
|
+
private static readonly rscaleCalendarSupport;
|
|
76
79
|
constructor(params: RRuleOptions);
|
|
77
80
|
private sanitizeNumericArray;
|
|
78
81
|
private sanitizeByDay;
|
|
82
|
+
private enforceStrictRfc;
|
|
79
83
|
private sanitizeOpts;
|
|
80
84
|
private rawAdvance;
|
|
81
85
|
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
|
|
@@ -98,6 +102,17 @@ declare class RRuleTemporal {
|
|
|
98
102
|
private getIsoWeekInfo;
|
|
99
103
|
private matchesByWeekNo;
|
|
100
104
|
options(): ManualOpts;
|
|
105
|
+
private cloneOptions;
|
|
106
|
+
private cloneUpdateOptions;
|
|
107
|
+
/**
|
|
108
|
+
* Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const updated = rule.with({byMonthDay: [3]});
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
with(updates: Partial<ManualOpts>): RRuleTemporal;
|
|
101
116
|
private addDtstartIfNeeded;
|
|
102
117
|
private processOccurrences;
|
|
103
118
|
/**
|
|
@@ -166,6 +181,16 @@ declare class RRuleTemporal {
|
|
|
166
181
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
|
|
167
182
|
*/
|
|
168
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;
|
|
169
194
|
/**
|
|
170
195
|
* Returns the next occurrence of the rule after a specified date.
|
|
171
196
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
@@ -211,6 +236,7 @@ declare class RRuleTemporal {
|
|
|
211
236
|
*/
|
|
212
237
|
private generateOccurrencesForWeekInYear;
|
|
213
238
|
private getRscaleCalendarId;
|
|
239
|
+
private assertRscaleCalendarSupported;
|
|
214
240
|
private pad2;
|
|
215
241
|
private monthMatchesToken;
|
|
216
242
|
private monthsOfYear;
|
package/dist/index.js
CHANGED
package/dist/totext.cjs
CHANGED
|
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
|
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
23
35
|
var __export = (target, all) => {
|
|
24
36
|
for (var name in all)
|
|
25
37
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -211,7 +223,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
211
223
|
}
|
|
212
224
|
return opts;
|
|
213
225
|
}
|
|
214
|
-
var
|
|
226
|
+
var _RRuleTemporal = class _RRuleTemporal {
|
|
215
227
|
constructor(params) {
|
|
216
228
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
217
229
|
let manual;
|
|
@@ -226,6 +238,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
226
238
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
227
239
|
count: (_c = params.count) != null ? _c : parsed.count,
|
|
228
240
|
until: (_d = params.until) != null ? _d : parsed.until,
|
|
241
|
+
strict: params.strict,
|
|
229
242
|
maxIterations: params.maxIterations,
|
|
230
243
|
includeDtstart: params.includeDtstart,
|
|
231
244
|
tzid: this.tzid
|
|
@@ -275,6 +288,33 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
275
288
|
}
|
|
276
289
|
return days.length > 0 ? days : void 0;
|
|
277
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
|
+
}
|
|
278
318
|
sanitizeOpts(opts) {
|
|
279
319
|
var _a;
|
|
280
320
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
@@ -300,6 +340,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
300
340
|
}
|
|
301
341
|
opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
|
|
302
342
|
}
|
|
343
|
+
this.enforceStrictRfc(opts);
|
|
303
344
|
return opts;
|
|
304
345
|
}
|
|
305
346
|
rawAdvance(zdt) {
|
|
@@ -701,6 +742,99 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
701
742
|
options() {
|
|
702
743
|
return this.opts;
|
|
703
744
|
}
|
|
745
|
+
cloneOptions() {
|
|
746
|
+
const _a = this.opts, {
|
|
747
|
+
byHour,
|
|
748
|
+
byMinute,
|
|
749
|
+
bySecond,
|
|
750
|
+
byDay,
|
|
751
|
+
byMonth,
|
|
752
|
+
byMonthDay,
|
|
753
|
+
byYearDay,
|
|
754
|
+
byWeekNo,
|
|
755
|
+
bySetPos,
|
|
756
|
+
rDate,
|
|
757
|
+
exDate
|
|
758
|
+
} = _a, rest = __objRest(_a, [
|
|
759
|
+
"byHour",
|
|
760
|
+
"byMinute",
|
|
761
|
+
"bySecond",
|
|
762
|
+
"byDay",
|
|
763
|
+
"byMonth",
|
|
764
|
+
"byMonthDay",
|
|
765
|
+
"byYearDay",
|
|
766
|
+
"byWeekNo",
|
|
767
|
+
"bySetPos",
|
|
768
|
+
"rDate",
|
|
769
|
+
"exDate"
|
|
770
|
+
]);
|
|
771
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
772
|
+
byHour: byHour ? [...byHour] : void 0,
|
|
773
|
+
byMinute: byMinute ? [...byMinute] : void 0,
|
|
774
|
+
bySecond: bySecond ? [...bySecond] : void 0,
|
|
775
|
+
byDay: byDay ? [...byDay] : void 0,
|
|
776
|
+
byMonth: byMonth ? [...byMonth] : void 0,
|
|
777
|
+
byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
|
|
778
|
+
byYearDay: byYearDay ? [...byYearDay] : void 0,
|
|
779
|
+
byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
|
|
780
|
+
bySetPos: bySetPos ? [...bySetPos] : void 0,
|
|
781
|
+
rDate: rDate ? [...rDate] : void 0,
|
|
782
|
+
exDate: exDate ? [...exDate] : void 0
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
cloneUpdateOptions(updates) {
|
|
786
|
+
const cloned = {};
|
|
787
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
|
|
788
|
+
cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
|
|
789
|
+
}
|
|
790
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
|
|
791
|
+
cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
|
|
792
|
+
}
|
|
793
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
|
|
794
|
+
cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
|
|
795
|
+
}
|
|
796
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
|
|
797
|
+
cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
|
|
798
|
+
}
|
|
799
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
|
|
800
|
+
cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
|
|
801
|
+
}
|
|
802
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
|
|
803
|
+
cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
|
|
804
|
+
}
|
|
805
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
|
|
806
|
+
cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
|
|
807
|
+
}
|
|
808
|
+
if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
|
|
809
|
+
cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
|
|
810
|
+
}
|
|
811
|
+
if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
|
|
812
|
+
cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
|
|
813
|
+
}
|
|
814
|
+
if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
|
|
815
|
+
cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
|
|
816
|
+
}
|
|
817
|
+
if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
|
|
818
|
+
cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
|
|
819
|
+
}
|
|
820
|
+
return cloned;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```ts
|
|
827
|
+
* const updated = rule.with({byMonthDay: [3]});
|
|
828
|
+
* ```
|
|
829
|
+
*/
|
|
830
|
+
with(updates) {
|
|
831
|
+
var _a, _b;
|
|
832
|
+
const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
|
|
833
|
+
tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
|
|
834
|
+
dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
|
|
835
|
+
});
|
|
836
|
+
return new _RRuleTemporal(merged);
|
|
837
|
+
}
|
|
704
838
|
addDtstartIfNeeded(dates, iterator) {
|
|
705
839
|
if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
|
|
706
840
|
if (iterator && this.isExcluded(this.originalDtstart)) {
|
|
@@ -1436,6 +1570,25 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1436
1570
|
return afterStart && beforeEnd;
|
|
1437
1571
|
});
|
|
1438
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
|
+
}
|
|
1439
1592
|
/**
|
|
1440
1593
|
* Returns the next occurrence of the rule after a specified date.
|
|
1441
1594
|
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
@@ -1873,6 +2026,27 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1873
2026
|
const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
|
|
1874
2027
|
return map[r] || null;
|
|
1875
2028
|
}
|
|
2029
|
+
assertRscaleCalendarSupported(calId) {
|
|
2030
|
+
if (calId === "gregory" || calId === "iso8601") return;
|
|
2031
|
+
const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
|
|
2032
|
+
if (cached === true) return;
|
|
2033
|
+
if (cached === false) {
|
|
2034
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2035
|
+
}
|
|
2036
|
+
let supported = true;
|
|
2037
|
+
try {
|
|
2038
|
+
const probe = import_polyfill.Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
|
|
2039
|
+
void probe.year;
|
|
2040
|
+
void probe.monthCode;
|
|
2041
|
+
void probe.day;
|
|
2042
|
+
} catch (e) {
|
|
2043
|
+
supported = false;
|
|
2044
|
+
}
|
|
2045
|
+
_RRuleTemporal.rscaleCalendarSupport[calId] = supported;
|
|
2046
|
+
if (!supported) {
|
|
2047
|
+
throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
1876
2050
|
pad2(n) {
|
|
1877
2051
|
return String(n).padStart(2, "0");
|
|
1878
2052
|
}
|
|
@@ -2044,6 +2218,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2044
2218
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2045
2219
|
const calId = this.getRscaleCalendarId();
|
|
2046
2220
|
if (!calId) return this._allFallback(iterator);
|
|
2221
|
+
this.assertRscaleCalendarSupported(calId);
|
|
2047
2222
|
const dates = [];
|
|
2048
2223
|
let iterationCount = 0;
|
|
2049
2224
|
const start = this.originalDtstart;
|
|
@@ -2272,6 +2447,8 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
2272
2447
|
return this._allFallback(iterator);
|
|
2273
2448
|
}
|
|
2274
2449
|
};
|
|
2450
|
+
_RRuleTemporal.rscaleCalendarSupport = {};
|
|
2451
|
+
var RRuleTemporal = _RRuleTemporal;
|
|
2275
2452
|
|
|
2276
2453
|
// src/totext.ts
|
|
2277
2454
|
var en = {
|
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",
|