rrule-temporal-polyfill 1.3.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.
@@ -0,0 +1,247 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+
3
+ type Freq = 'YEARLY' | 'MONTHLY' | 'WEEKLY' | 'DAILY' | 'HOURLY' | 'MINUTELY' | 'SECONDLY';
4
+ /**
5
+ * Shared options for all rule constructors.
6
+ */
7
+ interface BaseOpts {
8
+ /** Time zone identifier as defined in RFC 5545 §3.2.19. */
9
+ tzid?: string;
10
+ /** Safety cap when generating occurrences. */
11
+ maxIterations?: number;
12
+ /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
13
+ includeDtstart?: boolean;
14
+ /** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
15
+ rscale?: string;
16
+ /** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
17
+ skip?: 'OMIT' | 'BACKWARD' | 'FORWARD';
18
+ }
19
+ /**
20
+ * Manual rule definition following the recurrence rule parts defined in
21
+ * RFC 5545 §3.3.10.
22
+ */
23
+ interface ManualOpts extends BaseOpts {
24
+ /** FREQ: recurrence frequency */
25
+ freq: Freq;
26
+ /** INTERVAL between each occurrence of {@link freq} */
27
+ interval?: number;
28
+ /** COUNT: total number of occurrences */
29
+ count?: number;
30
+ /** UNTIL: last possible occurrence */
31
+ until?: Temporal.ZonedDateTime;
32
+ /** BYHOUR: hours to include (0-23) */
33
+ byHour?: number[];
34
+ /** BYMINUTE: minutes to include (0-59) */
35
+ byMinute?: number[];
36
+ /** BYSECOND: seconds to include (0-59) */
37
+ bySecond?: number[];
38
+ /** BYDAY: list of weekdays e.g. ["MO","WE","FR"] */
39
+ byDay?: string[];
40
+ /** BYMONTH: months of the year (1-12). With RSCALE (RFC 7529) may contain values like "5L". */
41
+ byMonth?: Array<number | string>;
42
+ /** BYMONTHDAY: days of the month (1..31 or negative from end) */
43
+ byMonthDay?: number[];
44
+ /** BYYEARDAY: days of the year (1..366 or negative from end) */
45
+ byYearDay?: number[];
46
+ /** BYWEEKNO: ISO week numbers (1..53 or negative from end) */
47
+ byWeekNo?: number[];
48
+ /** BYSETPOS: select n-th occurrence(s) after other filters */
49
+ bySetPos?: number[];
50
+ /** WKST: weekday on which the week starts ("MO".."SU") */
51
+ wkst?: string;
52
+ /** RDATE: additional dates to include */
53
+ rDate?: Temporal.ZonedDateTime[];
54
+ /** EXDATE: exception dates to exclude */
55
+ exDate?: Temporal.ZonedDateTime[];
56
+ /** DTSTART: first occurrence */
57
+ dtstart: Temporal.ZonedDateTime;
58
+ }
59
+ interface IcsOpts extends BaseOpts {
60
+ rruleString: string;
61
+ dtstart?: Temporal.ZonedDateTime;
62
+ /** COUNT: total number of occurrences, used when missing from rruleString */
63
+ count?: number;
64
+ /** UNTIL: last possible occurrence, used when missing from rruleString */
65
+ until?: Temporal.ZonedDateTime;
66
+ }
67
+ type RRuleOptions = ManualOpts | IcsOpts;
68
+ type RRuleTemporalIterator = (date: Temporal.ZonedDateTime, i: number) => boolean;
69
+ type DateFilter = Date | Temporal.ZonedDateTime;
70
+ declare class RRuleTemporal {
71
+ private readonly tzid;
72
+ private readonly originalDtstart;
73
+ private readonly opts;
74
+ private readonly maxIterations;
75
+ private readonly includeDtstart;
76
+ private static readonly rscaleCalendarSupport;
77
+ constructor(params: RRuleOptions);
78
+ private sanitizeNumericArray;
79
+ private sanitizeByDay;
80
+ private sanitizeOpts;
81
+ private rawAdvance;
82
+ /** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
83
+ * combinations, keeping chronological order. If the options are not
84
+ * present the original date is returned unchanged.
85
+ */
86
+ private expandByTime;
87
+ private nextCandidateSameDate;
88
+ private applyTimeOverride;
89
+ private computeFirst;
90
+ private matchesByDay;
91
+ private matchesByMonth;
92
+ private matchesNumericConstraint;
93
+ private matchesByMonthDay;
94
+ private matchesByHour;
95
+ private matchesByMinute;
96
+ private matchesBySecond;
97
+ private matchesAll;
98
+ private matchesByYearDay;
99
+ private getIsoWeekInfo;
100
+ private matchesByWeekNo;
101
+ options(): ManualOpts;
102
+ private cloneOptions;
103
+ private cloneUpdateOptions;
104
+ /**
105
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const updated = rule.with({byMonthDay: [3]});
110
+ * ```
111
+ */
112
+ with(updates: Partial<ManualOpts>): RRuleTemporal;
113
+ private addDtstartIfNeeded;
114
+ private processOccurrences;
115
+ /**
116
+ * Returns all occurrences of the rule.
117
+ * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
118
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
119
+ */
120
+ private _allMonthlyByDayOrMonthDay;
121
+ private _allWeekly;
122
+ private _allMonthlyByMonth;
123
+ private _allYearlyByMonth;
124
+ private _allYearlyComplex;
125
+ private _allMinutelySecondlyComplex;
126
+ private _allMonthlyByWeekNo;
127
+ private _allMonthlyByYearDay;
128
+ private _allDailyMinutelyHourlyWithBySetPos;
129
+ private _allFallback;
130
+ /**
131
+ * Returns all occurrences of the rule.
132
+ * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
133
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
134
+ */
135
+ all(iterator?: RRuleTemporalIterator): Temporal.ZonedDateTime[];
136
+ /**
137
+ * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
138
+ * Handles month-to-month stepping from DTSTART's year/month aiming for DTSTART's day-of-month.
139
+ * Applies SKIP=OMIT (skip invalid months), BACKWARD (clamp to last day), FORWARD (first day of next month).
140
+ */
141
+ private _allMonthlyRscaleSimple;
142
+ /**
143
+ * Converts rDate entries to ZonedDateTime and merges with existing dates.
144
+ * @param dates - Array of dates to merge with
145
+ * @returns Merged and deduplicated array of dates
146
+ */
147
+ private mergeAndDeduplicateRDates;
148
+ /**
149
+ * Checks if a date is in the exDate list.
150
+ * @param date - Date to check
151
+ * @returns True if the date is excluded
152
+ */
153
+ private isExcluded;
154
+ /**
155
+ * Excludes exDate entries from the given array of dates.
156
+ * @param dates - Array of dates to filter
157
+ * @returns Filtered array with exDate entries removed
158
+ */
159
+ private excludeExDates;
160
+ /**
161
+ * Applies count limit and merges rDates with the rule-generated dates.
162
+ * @param dates - Array of dates generated by the rule
163
+ * @param iterator - Optional iterator function
164
+ * @returns Final array of dates after merging and applying count limit
165
+ */
166
+ private applyCountLimitAndMergeRDates;
167
+ /**
168
+ * Checks if the count limit should break the loop based on rDate presence.
169
+ * @param matchCount - Current number of matches
170
+ * @returns true if the loop should break
171
+ */
172
+ private shouldBreakForCountLimit;
173
+ /**
174
+ * Returns all occurrences of the rule within a specified time window.
175
+ * @param after - The start date or Temporal.ZonedDateTime object.
176
+ * @param before - The end date or Temporal.ZonedDateTime object.
177
+ * @param inc - Optional boolean flag to include the end date in the results.
178
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
179
+ */
180
+ between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
181
+ /**
182
+ * Returns the next occurrence of the rule after a specified date.
183
+ * @param after - The start date or Temporal.ZonedDateTime object.
184
+ * @param inc - Optional boolean flag to include occurrences on the start date.
185
+ * @returns The next occurrence of the rule after the specified date or null if no occurrences are found.
186
+ */
187
+ next(after?: DateFilter, inc?: boolean): Temporal.ZonedDateTime | null;
188
+ /**
189
+ * Returns the previous occurrence of the rule before a specified date.
190
+ * @param before - The end date or Temporal.ZonedDateTime object.
191
+ * @param inc - Optional boolean flag to include occurrences on the end date.
192
+ * @returns The previous occurrence of the rule before the specified date or null if no occurrences are found.
193
+ */
194
+ previous(before?: DateFilter, inc?: boolean): Temporal.ZonedDateTime | null;
195
+ toString(): string;
196
+ private formatIcsDateTime;
197
+ private joinDates;
198
+ /**
199
+ * Given any date in a month, return all the ZonedDateTimes in that month
200
+ * matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
201
+ */
202
+ private generateMonthlyOccurrences;
203
+ /**
204
+ * Given any date in a year, return all ZonedDateTimes in that year matching
205
+ * the BYDAY/BYMONTHDAY/BYMONTH constraints. Months default to DTSTART's month
206
+ * if BYMONTH is not specified.
207
+ */
208
+ private generateYearlyOccurrences;
209
+ private addByDay;
210
+ /**
211
+ * Helper to find the next valid value from a sorted array
212
+ */
213
+ private findNextValidValue;
214
+ /**
215
+ * Efficiently find the next valid date for MINUTELY and SECONDLY frequency by jumping over
216
+ * large gaps when BYXXX constraints don't match.
217
+ */
218
+ private findNextValidDate;
219
+ private applyBySetPos;
220
+ private isoWeekByDay;
221
+ /**
222
+ * Generate occurrences for a specific week number in a given year
223
+ */
224
+ private generateOccurrencesForWeekInYear;
225
+ private getRscaleCalendarId;
226
+ private assertRscaleCalendarSupported;
227
+ private pad2;
228
+ private monthMatchesToken;
229
+ private monthsOfYear;
230
+ private startOfYear;
231
+ private endOfYear;
232
+ private rscaleFirstWeekStart;
233
+ private rscaleLastWeekCount;
234
+ private lastDayOfMonth;
235
+ private buildZdtFromPlainDate;
236
+ private rscaleMatchesByYearDay;
237
+ private rscaleMatchesByWeekNo;
238
+ private rscaleMatchesByMonth;
239
+ private rscaleMatchesByMonthDay;
240
+ private rscaleMatchesByDayBasic;
241
+ private rscaleDateMatches;
242
+ private applySkipForDay;
243
+ private generateMonthlyOccurrencesRscale;
244
+ private _allRscaleNonGregorian;
245
+ }
246
+
247
+ export { type RRuleOptions, RRuleTemporal };
@@ -0,0 +1,247 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+
3
+ type Freq = 'YEARLY' | 'MONTHLY' | 'WEEKLY' | 'DAILY' | 'HOURLY' | 'MINUTELY' | 'SECONDLY';
4
+ /**
5
+ * Shared options for all rule constructors.
6
+ */
7
+ interface BaseOpts {
8
+ /** Time zone identifier as defined in RFC&nbsp;5545 §3.2.19. */
9
+ tzid?: string;
10
+ /** Safety cap when generating occurrences. */
11
+ maxIterations?: number;
12
+ /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
13
+ includeDtstart?: boolean;
14
+ /** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
15
+ rscale?: string;
16
+ /** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
17
+ skip?: 'OMIT' | 'BACKWARD' | 'FORWARD';
18
+ }
19
+ /**
20
+ * Manual rule definition following the recurrence rule parts defined in
21
+ * RFC 5545 §3.3.10.
22
+ */
23
+ interface ManualOpts extends BaseOpts {
24
+ /** FREQ: recurrence frequency */
25
+ freq: Freq;
26
+ /** INTERVAL between each occurrence of {@link freq} */
27
+ interval?: number;
28
+ /** COUNT: total number of occurrences */
29
+ count?: number;
30
+ /** UNTIL: last possible occurrence */
31
+ until?: Temporal.ZonedDateTime;
32
+ /** BYHOUR: hours to include (0-23) */
33
+ byHour?: number[];
34
+ /** BYMINUTE: minutes to include (0-59) */
35
+ byMinute?: number[];
36
+ /** BYSECOND: seconds to include (0-59) */
37
+ bySecond?: number[];
38
+ /** BYDAY: list of weekdays e.g. ["MO","WE","FR"] */
39
+ byDay?: string[];
40
+ /** BYMONTH: months of the year (1-12). With RSCALE (RFC 7529) may contain values like "5L". */
41
+ byMonth?: Array<number | string>;
42
+ /** BYMONTHDAY: days of the month (1..31 or negative from end) */
43
+ byMonthDay?: number[];
44
+ /** BYYEARDAY: days of the year (1..366 or negative from end) */
45
+ byYearDay?: number[];
46
+ /** BYWEEKNO: ISO week numbers (1..53 or negative from end) */
47
+ byWeekNo?: number[];
48
+ /** BYSETPOS: select n-th occurrence(s) after other filters */
49
+ bySetPos?: number[];
50
+ /** WKST: weekday on which the week starts ("MO".."SU") */
51
+ wkst?: string;
52
+ /** RDATE: additional dates to include */
53
+ rDate?: Temporal.ZonedDateTime[];
54
+ /** EXDATE: exception dates to exclude */
55
+ exDate?: Temporal.ZonedDateTime[];
56
+ /** DTSTART: first occurrence */
57
+ dtstart: Temporal.ZonedDateTime;
58
+ }
59
+ interface IcsOpts extends BaseOpts {
60
+ rruleString: string;
61
+ dtstart?: Temporal.ZonedDateTime;
62
+ /** COUNT: total number of occurrences, used when missing from rruleString */
63
+ count?: number;
64
+ /** UNTIL: last possible occurrence, used when missing from rruleString */
65
+ until?: Temporal.ZonedDateTime;
66
+ }
67
+ type RRuleOptions = ManualOpts | IcsOpts;
68
+ type RRuleTemporalIterator = (date: Temporal.ZonedDateTime, i: number) => boolean;
69
+ type DateFilter = Date | Temporal.ZonedDateTime;
70
+ declare class RRuleTemporal {
71
+ private readonly tzid;
72
+ private readonly originalDtstart;
73
+ private readonly opts;
74
+ private readonly maxIterations;
75
+ private readonly includeDtstart;
76
+ private static readonly rscaleCalendarSupport;
77
+ constructor(params: RRuleOptions);
78
+ private sanitizeNumericArray;
79
+ private sanitizeByDay;
80
+ private sanitizeOpts;
81
+ private rawAdvance;
82
+ /** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
83
+ * combinations, keeping chronological order. If the options are not
84
+ * present the original date is returned unchanged.
85
+ */
86
+ private expandByTime;
87
+ private nextCandidateSameDate;
88
+ private applyTimeOverride;
89
+ private computeFirst;
90
+ private matchesByDay;
91
+ private matchesByMonth;
92
+ private matchesNumericConstraint;
93
+ private matchesByMonthDay;
94
+ private matchesByHour;
95
+ private matchesByMinute;
96
+ private matchesBySecond;
97
+ private matchesAll;
98
+ private matchesByYearDay;
99
+ private getIsoWeekInfo;
100
+ private matchesByWeekNo;
101
+ options(): ManualOpts;
102
+ private cloneOptions;
103
+ private cloneUpdateOptions;
104
+ /**
105
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const updated = rule.with({byMonthDay: [3]});
110
+ * ```
111
+ */
112
+ with(updates: Partial<ManualOpts>): RRuleTemporal;
113
+ private addDtstartIfNeeded;
114
+ private processOccurrences;
115
+ /**
116
+ * Returns all occurrences of the rule.
117
+ * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
118
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
119
+ */
120
+ private _allMonthlyByDayOrMonthDay;
121
+ private _allWeekly;
122
+ private _allMonthlyByMonth;
123
+ private _allYearlyByMonth;
124
+ private _allYearlyComplex;
125
+ private _allMinutelySecondlyComplex;
126
+ private _allMonthlyByWeekNo;
127
+ private _allMonthlyByYearDay;
128
+ private _allDailyMinutelyHourlyWithBySetPos;
129
+ private _allFallback;
130
+ /**
131
+ * Returns all occurrences of the rule.
132
+ * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
133
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
134
+ */
135
+ all(iterator?: RRuleTemporalIterator): Temporal.ZonedDateTime[];
136
+ /**
137
+ * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
138
+ * Handles month-to-month stepping from DTSTART's year/month aiming for DTSTART's day-of-month.
139
+ * Applies SKIP=OMIT (skip invalid months), BACKWARD (clamp to last day), FORWARD (first day of next month).
140
+ */
141
+ private _allMonthlyRscaleSimple;
142
+ /**
143
+ * Converts rDate entries to ZonedDateTime and merges with existing dates.
144
+ * @param dates - Array of dates to merge with
145
+ * @returns Merged and deduplicated array of dates
146
+ */
147
+ private mergeAndDeduplicateRDates;
148
+ /**
149
+ * Checks if a date is in the exDate list.
150
+ * @param date - Date to check
151
+ * @returns True if the date is excluded
152
+ */
153
+ private isExcluded;
154
+ /**
155
+ * Excludes exDate entries from the given array of dates.
156
+ * @param dates - Array of dates to filter
157
+ * @returns Filtered array with exDate entries removed
158
+ */
159
+ private excludeExDates;
160
+ /**
161
+ * Applies count limit and merges rDates with the rule-generated dates.
162
+ * @param dates - Array of dates generated by the rule
163
+ * @param iterator - Optional iterator function
164
+ * @returns Final array of dates after merging and applying count limit
165
+ */
166
+ private applyCountLimitAndMergeRDates;
167
+ /**
168
+ * Checks if the count limit should break the loop based on rDate presence.
169
+ * @param matchCount - Current number of matches
170
+ * @returns true if the loop should break
171
+ */
172
+ private shouldBreakForCountLimit;
173
+ /**
174
+ * Returns all occurrences of the rule within a specified time window.
175
+ * @param after - The start date or Temporal.ZonedDateTime object.
176
+ * @param before - The end date or Temporal.ZonedDateTime object.
177
+ * @param inc - Optional boolean flag to include the end date in the results.
178
+ * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
179
+ */
180
+ between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
181
+ /**
182
+ * Returns the next occurrence of the rule after a specified date.
183
+ * @param after - The start date or Temporal.ZonedDateTime object.
184
+ * @param inc - Optional boolean flag to include occurrences on the start date.
185
+ * @returns The next occurrence of the rule after the specified date or null if no occurrences are found.
186
+ */
187
+ next(after?: DateFilter, inc?: boolean): Temporal.ZonedDateTime | null;
188
+ /**
189
+ * Returns the previous occurrence of the rule before a specified date.
190
+ * @param before - The end date or Temporal.ZonedDateTime object.
191
+ * @param inc - Optional boolean flag to include occurrences on the end date.
192
+ * @returns The previous occurrence of the rule before the specified date or null if no occurrences are found.
193
+ */
194
+ previous(before?: DateFilter, inc?: boolean): Temporal.ZonedDateTime | null;
195
+ toString(): string;
196
+ private formatIcsDateTime;
197
+ private joinDates;
198
+ /**
199
+ * Given any date in a month, return all the ZonedDateTimes in that month
200
+ * matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
201
+ */
202
+ private generateMonthlyOccurrences;
203
+ /**
204
+ * Given any date in a year, return all ZonedDateTimes in that year matching
205
+ * the BYDAY/BYMONTHDAY/BYMONTH constraints. Months default to DTSTART's month
206
+ * if BYMONTH is not specified.
207
+ */
208
+ private generateYearlyOccurrences;
209
+ private addByDay;
210
+ /**
211
+ * Helper to find the next valid value from a sorted array
212
+ */
213
+ private findNextValidValue;
214
+ /**
215
+ * Efficiently find the next valid date for MINUTELY and SECONDLY frequency by jumping over
216
+ * large gaps when BYXXX constraints don't match.
217
+ */
218
+ private findNextValidDate;
219
+ private applyBySetPos;
220
+ private isoWeekByDay;
221
+ /**
222
+ * Generate occurrences for a specific week number in a given year
223
+ */
224
+ private generateOccurrencesForWeekInYear;
225
+ private getRscaleCalendarId;
226
+ private assertRscaleCalendarSupported;
227
+ private pad2;
228
+ private monthMatchesToken;
229
+ private monthsOfYear;
230
+ private startOfYear;
231
+ private endOfYear;
232
+ private rscaleFirstWeekStart;
233
+ private rscaleLastWeekCount;
234
+ private lastDayOfMonth;
235
+ private buildZdtFromPlainDate;
236
+ private rscaleMatchesByYearDay;
237
+ private rscaleMatchesByWeekNo;
238
+ private rscaleMatchesByMonth;
239
+ private rscaleMatchesByMonthDay;
240
+ private rscaleMatchesByDayBasic;
241
+ private rscaleDateMatches;
242
+ private applySkipForDay;
243
+ private generateMonthlyOccurrencesRscale;
244
+ private _allRscaleNonGregorian;
245
+ }
246
+
247
+ export { type RRuleOptions, RRuleTemporal };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ RRuleTemporal
3
+ } from "./chunk-XKNVKDJ3.js";
4
+ export {
5
+ RRuleTemporal
6
+ };