rrule-temporal 0.1.2 → 0.1.4
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/index.cjs +577 -0
- package/dist/index.d.cts +72 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +522 -513
- package/dist/tests/rrule-temporal.test.js +44 -0
- package/package.json +10 -4
package/dist/index.js
CHANGED
|
@@ -1,543 +1,552 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/index.ts
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
-
/**
|
|
4
|
-
* Parse either a full ICS snippet or an RRULE line into ManualOpts
|
|
5
|
-
*/
|
|
6
3
|
function parseRRuleString(input, fallbackDtstart) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
opts.until = Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC");
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-` +
|
|
54
|
-
`${val.slice(6, 8)}T${val.slice(9, 15)}`;
|
|
55
|
-
opts.until = Temporal.PlainDateTime.from(iso).toZonedDateTime(tzid || "UTC");
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case "BYHOUR":
|
|
60
|
-
opts.byHour = val.split(",").map((n) => parseInt(n, 10));
|
|
61
|
-
break;
|
|
62
|
-
case "BYMINUTE":
|
|
63
|
-
opts.byMinute = val.split(",").map((n) => parseInt(n, 10));
|
|
64
|
-
break;
|
|
65
|
-
case "BYDAY":
|
|
66
|
-
opts.byDay = val.split(","); // e.g. ["MO","2FR","-1SU"]
|
|
67
|
-
break;
|
|
68
|
-
case "BYMONTH":
|
|
69
|
-
opts.byMonth = val.split(",").map((n) => parseInt(n, 10));
|
|
70
|
-
break;
|
|
4
|
+
let dtstart;
|
|
5
|
+
let tzid = "";
|
|
6
|
+
let rruleLine;
|
|
7
|
+
if (/^DTSTART/m.test(input)) {
|
|
8
|
+
const [dtLine, rrLine] = input.split(/\r?\n/);
|
|
9
|
+
const m = dtLine?.match(/DTSTART(?:;TZID=([^:]+))?:(\d{8}T\d{6})/);
|
|
10
|
+
if (!m) throw new Error("Invalid DTSTART in ICS snippet");
|
|
11
|
+
tzid = m[1] || tzid;
|
|
12
|
+
const isoDate = `${m[2].slice(0, 4)}-${m[2].slice(4, 6)}-${m[2].slice(6, 8)}T${m[2].slice(9)}`;
|
|
13
|
+
dtstart = Temporal.PlainDateTime.from(isoDate).toZonedDateTime(tzid);
|
|
14
|
+
rruleLine = rrLine;
|
|
15
|
+
} else {
|
|
16
|
+
if (!fallbackDtstart)
|
|
17
|
+
throw new Error("dtstart required when parsing RRULE alone");
|
|
18
|
+
dtstart = fallbackDtstart;
|
|
19
|
+
tzid = fallbackDtstart.timeZoneId;
|
|
20
|
+
rruleLine = input.replace(/^RRULE:/, "RRULE:");
|
|
21
|
+
}
|
|
22
|
+
const parts = rruleLine.replace(/^RRULE:/, "").split(";");
|
|
23
|
+
const opts = { dtstart, tzid };
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
const [key, val] = part.split("=");
|
|
26
|
+
switch (key) {
|
|
27
|
+
case "FREQ":
|
|
28
|
+
opts.freq = val;
|
|
29
|
+
break;
|
|
30
|
+
case "INTERVAL":
|
|
31
|
+
opts.interval = parseInt(val, 10);
|
|
32
|
+
break;
|
|
33
|
+
case "COUNT":
|
|
34
|
+
opts.count = parseInt(val, 10);
|
|
35
|
+
break;
|
|
36
|
+
case "UNTIL": {
|
|
37
|
+
if (/Z$/.test(val)) {
|
|
38
|
+
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}Z`;
|
|
39
|
+
opts.until = Temporal.Instant.from(iso).toZonedDateTimeISO(
|
|
40
|
+
tzid || "UTC"
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}`;
|
|
44
|
+
opts.until = Temporal.PlainDateTime.from(iso).toZonedDateTime(
|
|
45
|
+
tzid || "UTC"
|
|
46
|
+
);
|
|
71
47
|
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "BYHOUR":
|
|
51
|
+
opts.byHour = val.split(",").map((n) => parseInt(n, 10));
|
|
52
|
+
break;
|
|
53
|
+
case "BYMINUTE":
|
|
54
|
+
opts.byMinute = val.split(",").map((n) => parseInt(n, 10));
|
|
55
|
+
break;
|
|
56
|
+
case "BYDAY":
|
|
57
|
+
opts.byDay = val.split(",");
|
|
58
|
+
break;
|
|
59
|
+
case "BYMONTH":
|
|
60
|
+
opts.byMonth = val.split(",").map((n) => parseInt(n, 10));
|
|
61
|
+
break;
|
|
72
62
|
}
|
|
73
|
-
|
|
63
|
+
}
|
|
64
|
+
return opts;
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.originalDtstart = manual.dtstart;
|
|
94
|
-
}
|
|
95
|
-
if (!manual.freq)
|
|
96
|
-
throw new Error("RRULE must include FREQ");
|
|
97
|
-
manual.interval = manual.interval ?? 1;
|
|
98
|
-
this.opts = manual;
|
|
66
|
+
var RRuleTemporal = class {
|
|
67
|
+
tzid;
|
|
68
|
+
originalDtstart;
|
|
69
|
+
opts;
|
|
70
|
+
constructor(params) {
|
|
71
|
+
let manual;
|
|
72
|
+
if ("rruleString" in params) {
|
|
73
|
+
manual = parseRRuleString(params.rruleString);
|
|
74
|
+
this.tzid = manual.tzid || "UTC";
|
|
75
|
+
this.originalDtstart = manual.dtstart;
|
|
76
|
+
} else {
|
|
77
|
+
manual = { ...params };
|
|
78
|
+
if (typeof manual.dtstart === "string") {
|
|
79
|
+
throw new Error("Manual dtstart must be a ZonedDateTime");
|
|
80
|
+
}
|
|
81
|
+
manual.tzid = manual.tzid || manual.dtstart.timeZoneId;
|
|
82
|
+
this.tzid = manual.tzid;
|
|
83
|
+
this.originalDtstart = manual.dtstart;
|
|
99
84
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
85
|
+
if (!manual.freq) throw new Error("RRULE must include FREQ");
|
|
86
|
+
manual.interval = manual.interval ?? 1;
|
|
87
|
+
this.opts = manual;
|
|
88
|
+
}
|
|
89
|
+
rawAdvance(zdt) {
|
|
90
|
+
const { freq, interval } = this.opts;
|
|
91
|
+
switch (freq) {
|
|
92
|
+
case "DAILY":
|
|
93
|
+
return zdt.add({ days: interval });
|
|
94
|
+
case "WEEKLY":
|
|
95
|
+
return zdt.add({ weeks: interval });
|
|
96
|
+
case "MONTHLY":
|
|
97
|
+
return zdt.add({ months: interval });
|
|
98
|
+
case "YEARLY":
|
|
99
|
+
return zdt.add({ years: interval });
|
|
100
|
+
case "HOURLY":
|
|
101
|
+
return zdt.add({ hours: interval });
|
|
102
|
+
case "MINUTELY":
|
|
103
|
+
return zdt.add({ minutes: interval });
|
|
104
|
+
case "SECONDLY":
|
|
105
|
+
return zdt.add({ seconds: interval });
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unsupported FREQ: ${freq}`);
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
109
|
+
}
|
|
110
|
+
applyTimeOverride(zdt) {
|
|
111
|
+
const { byHour, byMinute } = this.opts;
|
|
112
|
+
let dt = zdt;
|
|
113
|
+
if (byHour) dt = dt.with({ hour: byHour[0] });
|
|
114
|
+
if (byMinute) dt = dt.with({ minute: byMinute[0] });
|
|
115
|
+
return dt;
|
|
116
|
+
}
|
|
117
|
+
computeFirst() {
|
|
118
|
+
let zdt = this.originalDtstart;
|
|
119
|
+
if (this.opts.freq === "WEEKLY" && this.opts.byDay?.length) {
|
|
120
|
+
const dayMap = {
|
|
121
|
+
MO: 1,
|
|
122
|
+
TU: 2,
|
|
123
|
+
WE: 3,
|
|
124
|
+
TH: 4,
|
|
125
|
+
FR: 5,
|
|
126
|
+
SA: 6,
|
|
127
|
+
SU: 7
|
|
128
|
+
};
|
|
129
|
+
const targetDow = dayMap[this.opts.byDay[0]];
|
|
130
|
+
const delta = (targetDow - zdt.dayOfWeek + 7) % 7;
|
|
131
|
+
zdt = zdt.add({ days: delta });
|
|
129
132
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return candidate;
|
|
133
|
+
const { byHour, byMinute } = this.opts;
|
|
134
|
+
if (byHour || byMinute) {
|
|
135
|
+
zdt = this.applyTimeOverride(zdt);
|
|
136
|
+
if (Temporal.Instant.compare(
|
|
137
|
+
zdt.toInstant(),
|
|
138
|
+
this.originalDtstart.toInstant()
|
|
139
|
+
) < 0) {
|
|
140
|
+
zdt = this.applyTimeOverride(this.rawAdvance(this.originalDtstart));
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
143
|
+
return zdt;
|
|
144
|
+
}
|
|
145
|
+
// inside class RRuleTemporal:
|
|
146
|
+
generateWeeklyOccurrences(sample) {
|
|
147
|
+
const { byDay } = this.opts;
|
|
148
|
+
const dayMap = {
|
|
149
|
+
MO: 1,
|
|
150
|
+
TU: 2,
|
|
151
|
+
WE: 3,
|
|
152
|
+
TH: 4,
|
|
153
|
+
FR: 5,
|
|
154
|
+
SA: 6,
|
|
155
|
+
SU: 7
|
|
156
|
+
};
|
|
157
|
+
const tokens = byDay && byDay.length ? byDay : [Object.entries(dayMap).find(([, d]) => d === sample.dayOfWeek)[0]];
|
|
158
|
+
const occs = tokens.map((tok) => {
|
|
159
|
+
const targetDow = dayMap[tok];
|
|
160
|
+
const delta = (targetDow - sample.dayOfWeek + 7) % 7;
|
|
161
|
+
return this.applyTimeOverride(sample.add({ days: delta }));
|
|
162
|
+
});
|
|
163
|
+
return occs.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
164
|
+
}
|
|
165
|
+
// --- NEW: constraint checks ---
|
|
166
|
+
// 2) Replace your matchesByDay with this:
|
|
167
|
+
matchesByDay(zdt) {
|
|
168
|
+
const { byDay } = this.opts;
|
|
169
|
+
if (!byDay) return true;
|
|
170
|
+
const dayMap = {
|
|
171
|
+
MO: 1,
|
|
172
|
+
TU: 2,
|
|
173
|
+
WE: 3,
|
|
174
|
+
TH: 4,
|
|
175
|
+
FR: 5,
|
|
176
|
+
SA: 6,
|
|
177
|
+
SU: 7
|
|
178
|
+
};
|
|
179
|
+
for (const token of byDay) {
|
|
180
|
+
const m = token.match(/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
181
|
+
if (!m) continue;
|
|
182
|
+
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
183
|
+
const weekday = m[2];
|
|
184
|
+
if (!weekday) continue;
|
|
185
|
+
const wd = dayMap[weekday];
|
|
186
|
+
if (ord === 0) {
|
|
187
|
+
if (zdt.dayOfWeek === wd) return true;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const year = zdt.year;
|
|
191
|
+
const month = zdt.month;
|
|
192
|
+
let dt = zdt.with({ day: 1 });
|
|
193
|
+
const candidates = [];
|
|
194
|
+
while (dt.month === month) {
|
|
195
|
+
if (dt.dayOfWeek === wd) candidates.push(dt.day);
|
|
196
|
+
dt = dt.add({ days: 1 });
|
|
197
|
+
}
|
|
198
|
+
const idx = ord > 0 ? ord - 1 : candidates.length + ord;
|
|
199
|
+
if (candidates[idx] === zdt.day) return true;
|
|
190
200
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
matchesByMonth(zdt) {
|
|
204
|
+
const { byMonth } = this.opts;
|
|
205
|
+
if (!byMonth) return true;
|
|
206
|
+
return byMonth.includes(zdt.month);
|
|
207
|
+
}
|
|
208
|
+
matchesAll(zdt) {
|
|
209
|
+
return this.matchesByDay(zdt) && this.matchesByMonth(zdt);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns all occurrences of the rule.
|
|
213
|
+
* @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
|
|
214
|
+
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
|
|
215
|
+
*/
|
|
216
|
+
all(iterator) {
|
|
217
|
+
if (!this.opts.count && !this.opts.until && !iterator) {
|
|
218
|
+
throw new Error("all() requires iterator when no COUNT/UNTIL");
|
|
196
219
|
}
|
|
197
|
-
|
|
198
|
-
|
|
220
|
+
const dates = [];
|
|
221
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byDay) {
|
|
222
|
+
const start = this.originalDtstart;
|
|
223
|
+
let monthCursor = start.with({ day: 1 });
|
|
224
|
+
let matchCount2 = 0;
|
|
225
|
+
outer_month: while (true) {
|
|
226
|
+
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
227
|
+
for (const occ of occs) {
|
|
228
|
+
if (Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
229
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
230
|
+
break outer_month;
|
|
231
|
+
}
|
|
232
|
+
if (this.opts.count !== void 0 && matchCount2 >= this.opts.count) {
|
|
233
|
+
break outer_month;
|
|
234
|
+
}
|
|
235
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
236
|
+
break outer_month;
|
|
237
|
+
}
|
|
238
|
+
dates.push(occ);
|
|
239
|
+
matchCount2++;
|
|
240
|
+
}
|
|
241
|
+
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
242
|
+
}
|
|
243
|
+
return dates;
|
|
244
|
+
}
|
|
245
|
+
if (this.opts.freq === "WEEKLY") {
|
|
246
|
+
const start = this.originalDtstart;
|
|
247
|
+
const dayMap = {
|
|
248
|
+
MO: 1,
|
|
249
|
+
TU: 2,
|
|
250
|
+
WE: 3,
|
|
251
|
+
TH: 4,
|
|
252
|
+
FR: 5,
|
|
253
|
+
SA: 6,
|
|
254
|
+
SU: 7
|
|
255
|
+
};
|
|
256
|
+
const tokens = this.opts.byDay ? [...this.opts.byDay] : [Object.entries(dayMap).find(([, d]) => d === start.dayOfWeek)[0]];
|
|
257
|
+
const dows = tokens.map((tok) => dayMap[tok]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
258
|
+
const firstWeekDates = dows.map((dw) => {
|
|
259
|
+
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
260
|
+
return start.add({ days: delta });
|
|
261
|
+
});
|
|
262
|
+
let weekCursor = firstWeekDates.reduce(
|
|
263
|
+
(a, b) => Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b
|
|
264
|
+
);
|
|
265
|
+
let matchCount2 = 0;
|
|
266
|
+
outer_week: while (true) {
|
|
267
|
+
const baseDow = weekCursor.dayOfWeek;
|
|
268
|
+
const occs = dows.map((dw) => {
|
|
269
|
+
const delta = dw - baseDow;
|
|
270
|
+
return this.applyTimeOverride(weekCursor.add({ days: delta }));
|
|
271
|
+
}).sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
272
|
+
for (const occ of occs) {
|
|
273
|
+
if (Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
274
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
275
|
+
break outer_week;
|
|
276
|
+
}
|
|
277
|
+
if (this.opts.count !== void 0 && matchCount2 >= this.opts.count) {
|
|
278
|
+
break outer_week;
|
|
279
|
+
}
|
|
280
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
281
|
+
break outer_week;
|
|
282
|
+
}
|
|
283
|
+
dates.push(occ);
|
|
284
|
+
matchCount2++;
|
|
285
|
+
}
|
|
286
|
+
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
287
|
+
}
|
|
288
|
+
return dates;
|
|
199
289
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
290
|
+
if (this.opts.freq === "YEARLY" && this.opts.byMonth) {
|
|
291
|
+
const start = this.originalDtstart;
|
|
292
|
+
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
293
|
+
let i = 0;
|
|
294
|
+
while (true) {
|
|
295
|
+
const year = start.year + i * this.opts.interval;
|
|
296
|
+
const month = months[i % months.length];
|
|
297
|
+
let occ = start.with({ year, month });
|
|
298
|
+
occ = this.applyTimeOverride(occ);
|
|
299
|
+
if (i === 0 && Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
300
|
+
i++;
|
|
301
|
+
continue;
|
|
208
302
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (this.opts.freq === "MONTHLY" && this.opts.byDay) {
|
|
212
|
-
const start = this.originalDtstart;
|
|
213
|
-
let monthCursor = start.with({ day: 1 });
|
|
214
|
-
let matchCount = 0;
|
|
215
|
-
outer: while (true) {
|
|
216
|
-
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
217
|
-
for (const occ of occs) {
|
|
218
|
-
// skip anything before the very first DTSTART
|
|
219
|
-
if (Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
// stop on UNTIL
|
|
223
|
-
if (this.opts.until &&
|
|
224
|
-
Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
225
|
-
break outer;
|
|
226
|
-
}
|
|
227
|
-
// stop on COUNT
|
|
228
|
-
if (this.opts.count !== undefined && matchCount >= this.opts.count) {
|
|
229
|
-
break outer;
|
|
230
|
-
}
|
|
231
|
-
// iterator callback
|
|
232
|
-
if (iterator && !iterator(occ, matchCount)) {
|
|
233
|
-
break outer;
|
|
234
|
-
}
|
|
235
|
-
dates.push(occ);
|
|
236
|
-
matchCount++;
|
|
237
|
-
}
|
|
238
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
239
|
-
}
|
|
240
|
-
return dates;
|
|
303
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
304
|
+
break;
|
|
241
305
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const start = this.originalDtstart;
|
|
245
|
-
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
246
|
-
let i = 0;
|
|
247
|
-
while (true) {
|
|
248
|
-
const year = start.year + i * this.opts.interval;
|
|
249
|
-
const month = months[i % months.length];
|
|
250
|
-
let occ = start.with({ year, month });
|
|
251
|
-
occ = this.applyTimeOverride(occ);
|
|
252
|
-
// skip the very first if it's before dtstart
|
|
253
|
-
if (i === 0 && Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
254
|
-
i++;
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
// stop on UNTIL
|
|
258
|
-
if (this.opts.until &&
|
|
259
|
-
Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
// stop on COUNT
|
|
263
|
-
if (this.opts.count !== undefined && i >= this.opts.count) {
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
// iterator callback
|
|
267
|
-
if (iterator && !iterator(occ, i)) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
dates.push(occ);
|
|
271
|
-
i++;
|
|
272
|
-
}
|
|
273
|
-
return dates;
|
|
306
|
+
if (this.opts.count !== void 0 && i >= this.opts.count) {
|
|
307
|
+
break;
|
|
274
308
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
let matchCount = 0;
|
|
278
|
-
while (true) {
|
|
279
|
-
if (this.opts.until &&
|
|
280
|
-
Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
if (this.matchesAll(current)) {
|
|
284
|
-
if (this.opts.count !== undefined && matchCount >= this.opts.count) {
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
if (iterator && !iterator(current, matchCount)) {
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
dates.push(current);
|
|
291
|
-
matchCount++;
|
|
292
|
-
}
|
|
293
|
-
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
309
|
+
if (iterator && !iterator(occ, i)) {
|
|
310
|
+
break;
|
|
294
311
|
}
|
|
295
|
-
|
|
312
|
+
dates.push(occ);
|
|
313
|
+
i++;
|
|
314
|
+
}
|
|
315
|
+
return dates;
|
|
296
316
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
? Temporal.Instant.from(after.toISOString())
|
|
307
|
-
: after.toInstant();
|
|
308
|
-
const endInst = before instanceof Date
|
|
309
|
-
? Temporal.Instant.from(before.toISOString())
|
|
310
|
-
: before.toInstant();
|
|
311
|
-
const results = [];
|
|
312
|
-
// 1) MONTHLY + BYDAY
|
|
313
|
-
if (this.opts.freq === "MONTHLY" && this.opts.byDay) {
|
|
314
|
-
let monthCursor = this.computeFirst().with({ day: 1 });
|
|
315
|
-
outer: while (true) {
|
|
316
|
-
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
317
|
-
for (const occ of occs) {
|
|
318
|
-
const inst = occ.toInstant();
|
|
319
|
-
if (inc
|
|
320
|
-
? Temporal.Instant.compare(inst, endInst) > 0
|
|
321
|
-
: Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
322
|
-
break outer;
|
|
323
|
-
}
|
|
324
|
-
if (Temporal.Instant.compare(inst, startInst) >= 0) {
|
|
325
|
-
results.push(occ);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
329
|
-
}
|
|
330
|
-
return results;
|
|
317
|
+
let current = this.computeFirst();
|
|
318
|
+
let matchCount = 0;
|
|
319
|
+
while (true) {
|
|
320
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
if (this.matchesAll(current)) {
|
|
324
|
+
if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
|
|
325
|
+
break;
|
|
331
326
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const start = this.originalDtstart;
|
|
335
|
-
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
336
|
-
let i = 0;
|
|
337
|
-
outer: while (true) {
|
|
338
|
-
const year = start.year + i * this.opts.interval;
|
|
339
|
-
const month = months[i % months.length];
|
|
340
|
-
let occ = start.with({ year, month });
|
|
341
|
-
occ = this.applyTimeOverride(occ);
|
|
342
|
-
const inst = occ.toInstant();
|
|
343
|
-
if (inc
|
|
344
|
-
? Temporal.Instant.compare(inst, endInst) > 0
|
|
345
|
-
: Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
if (Temporal.Instant.compare(inst, startInst) >= 0) {
|
|
349
|
-
results.push(occ);
|
|
350
|
-
}
|
|
351
|
-
i++;
|
|
352
|
-
}
|
|
353
|
-
return results;
|
|
327
|
+
if (iterator && !iterator(current, matchCount)) {
|
|
328
|
+
break;
|
|
354
329
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
330
|
+
dates.push(current);
|
|
331
|
+
matchCount++;
|
|
332
|
+
}
|
|
333
|
+
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
334
|
+
}
|
|
335
|
+
return dates;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Returns all occurrences of the rule within a specified time window.
|
|
339
|
+
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
340
|
+
* @param before - The end date or Temporal.ZonedDateTime object.
|
|
341
|
+
* @param inc - Optional boolean flag to include the end date in the results.
|
|
342
|
+
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
|
|
343
|
+
*/
|
|
344
|
+
between(after, before, inc = false) {
|
|
345
|
+
const startInst = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
346
|
+
const endInst = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
347
|
+
const results = [];
|
|
348
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byDay) {
|
|
349
|
+
let monthCursor = this.computeFirst().with({ day: 1 });
|
|
350
|
+
outer: while (true) {
|
|
351
|
+
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
352
|
+
for (const occ of occs) {
|
|
353
|
+
const inst = occ.toInstant();
|
|
354
|
+
if (inc ? Temporal.Instant.compare(inst, endInst) > 0 : Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
355
|
+
break outer;
|
|
356
|
+
}
|
|
357
|
+
if (Temporal.Instant.compare(inst, startInst) >= 0) {
|
|
358
|
+
results.push(occ);
|
|
359
|
+
}
|
|
372
360
|
}
|
|
373
|
-
|
|
361
|
+
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
362
|
+
}
|
|
363
|
+
return results;
|
|
374
364
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (this.matchesAll(current)) {
|
|
391
|
-
const ok = inc
|
|
392
|
-
? Temporal.Instant.compare(inst, afterInst) >= 0
|
|
393
|
-
: Temporal.Instant.compare(inst, afterInst) > 0;
|
|
394
|
-
if (ok)
|
|
395
|
-
return current;
|
|
396
|
-
// count it toward COUNT
|
|
397
|
-
matchCount++;
|
|
398
|
-
if (this.opts.count !== undefined && matchCount >= this.opts.count) {
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
// stop on UNTIL
|
|
403
|
-
if (this.opts.until &&
|
|
404
|
-
Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
365
|
+
if (this.opts.freq === "YEARLY" && this.opts.byMonth) {
|
|
366
|
+
const start = this.originalDtstart;
|
|
367
|
+
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
368
|
+
let i = 0;
|
|
369
|
+
outer: while (true) {
|
|
370
|
+
const year = start.year + i * this.opts.interval;
|
|
371
|
+
const month = months[i % months.length];
|
|
372
|
+
let occ = start.with({ year, month });
|
|
373
|
+
occ = this.applyTimeOverride(occ);
|
|
374
|
+
const inst = occ.toInstant();
|
|
375
|
+
if (inc ? Temporal.Instant.compare(inst, endInst) > 0 : Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
if (Temporal.Instant.compare(inst, startInst) >= 0) {
|
|
379
|
+
results.push(occ);
|
|
408
380
|
}
|
|
381
|
+
i++;
|
|
382
|
+
}
|
|
383
|
+
return results;
|
|
409
384
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (inc
|
|
426
|
-
? Temporal.Instant.compare(inst, beforeInst) > 0
|
|
427
|
-
: Temporal.Instant.compare(inst, beforeInst) >= 0) {
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
// track it if it matches constraints
|
|
431
|
-
if (this.matchesAll(current)) {
|
|
432
|
-
prev = current;
|
|
433
|
-
}
|
|
434
|
-
if (this.opts.until &&
|
|
435
|
-
Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
385
|
+
if (this.opts.freq === "WEEKLY") {
|
|
386
|
+
const startInst2 = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
387
|
+
const endInst2 = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
388
|
+
let weekCursor = this.computeFirst();
|
|
389
|
+
const results2 = [];
|
|
390
|
+
outer: while (true) {
|
|
391
|
+
const occs = this.generateWeeklyOccurrences(weekCursor);
|
|
392
|
+
for (const occ of occs) {
|
|
393
|
+
const inst = occ.toInstant();
|
|
394
|
+
if (inc ? Temporal.Instant.compare(inst, endInst2) > 0 : Temporal.Instant.compare(inst, endInst2) >= 0) {
|
|
395
|
+
break outer;
|
|
396
|
+
}
|
|
397
|
+
if (Temporal.Instant.compare(inst, startInst2) >= 0) {
|
|
398
|
+
results2.push(occ);
|
|
399
|
+
}
|
|
439
400
|
}
|
|
440
|
-
|
|
401
|
+
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
402
|
+
}
|
|
403
|
+
return results2;
|
|
441
404
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (byHour)
|
|
455
|
-
parts.push(`BYHOUR=${byHour.join(",")}`);
|
|
456
|
-
if (byMinute)
|
|
457
|
-
parts.push(`BYMINUTE=${byMinute.join(",")}`);
|
|
458
|
-
if (byDay)
|
|
459
|
-
parts.push(`BYDAY=${byDay.join(",")}`);
|
|
460
|
-
if (byMonth)
|
|
461
|
-
parts.push(`BYMONTH=${byMonth.join(",")}`);
|
|
462
|
-
return [dtLine, `RRULE:${parts.join(";")}`].join("\n");
|
|
405
|
+
let current = this.computeFirst();
|
|
406
|
+
while (true) {
|
|
407
|
+
const inst = current.toInstant();
|
|
408
|
+
if (inc) {
|
|
409
|
+
if (Temporal.Instant.compare(inst, endInst) > 0) break;
|
|
410
|
+
} else {
|
|
411
|
+
if (Temporal.Instant.compare(inst, endInst) >= 0) break;
|
|
412
|
+
}
|
|
413
|
+
if (Temporal.Instant.compare(inst, startInst) >= 0 && this.matchesAll(current)) {
|
|
414
|
+
results.push(current);
|
|
415
|
+
}
|
|
416
|
+
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
463
417
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
418
|
+
return results;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Returns the next occurrence of the rule after a specified date.
|
|
422
|
+
* @param after - The start date or Temporal.ZonedDateTime object.
|
|
423
|
+
* @param inc - Optional boolean flag to include occurrences on the start date.
|
|
424
|
+
* @returns The next occurrence of the rule after the specified date or null if no occurrences are found.
|
|
425
|
+
*/
|
|
426
|
+
next(after = /* @__PURE__ */ new Date(), inc = false) {
|
|
427
|
+
const afterInst = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
428
|
+
let current = this.computeFirst();
|
|
429
|
+
let matchCount = 0;
|
|
430
|
+
while (true) {
|
|
431
|
+
const inst = current.toInstant();
|
|
432
|
+
if (this.matchesAll(current)) {
|
|
433
|
+
const ok = inc ? Temporal.Instant.compare(inst, afterInst) >= 0 : Temporal.Instant.compare(inst, afterInst) > 0;
|
|
434
|
+
if (ok) return current;
|
|
435
|
+
matchCount++;
|
|
436
|
+
if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
|
|
437
|
+
return null;
|
|
477
438
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
439
|
+
}
|
|
440
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Returns the previous occurrence of the rule before a specified date.
|
|
448
|
+
* @param before - The end date or Temporal.ZonedDateTime object.
|
|
449
|
+
* @param inc - Optional boolean flag to include occurrences on the end date.
|
|
450
|
+
* @returns The previous occurrence of the rule before the specified date or null if no occurrences are found.
|
|
451
|
+
*/
|
|
452
|
+
previous(before = /* @__PURE__ */ new Date(), inc = false) {
|
|
453
|
+
const beforeInst = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
454
|
+
let current = this.computeFirst();
|
|
455
|
+
let prev = null;
|
|
456
|
+
while (true) {
|
|
457
|
+
const inst = current.toInstant();
|
|
458
|
+
if (inc ? Temporal.Instant.compare(inst, beforeInst) > 0 : Temporal.Instant.compare(inst, beforeInst) >= 0) {
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
if (this.matchesAll(current)) {
|
|
462
|
+
prev = current;
|
|
463
|
+
}
|
|
464
|
+
if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
current = this.applyTimeOverride(this.rawAdvance(current));
|
|
468
|
+
}
|
|
469
|
+
return prev;
|
|
470
|
+
}
|
|
471
|
+
toString() {
|
|
472
|
+
const iso = this.originalDtstart.toString({ smallestUnit: "second" }).replace(/[-:]/g, "");
|
|
473
|
+
const dtLine = `DTSTART;TZID=${this.tzid}:${iso.slice(0, 15)}`;
|
|
474
|
+
const parts = [];
|
|
475
|
+
const { freq, interval, count, byHour, byMinute, byDay, byMonth } = this.opts;
|
|
476
|
+
parts.push(`FREQ=${freq}`);
|
|
477
|
+
if (interval !== 1) parts.push(`INTERVAL=${interval}`);
|
|
478
|
+
if (count !== void 0) parts.push(`COUNT=${count}`);
|
|
479
|
+
if (byHour) parts.push(`BYHOUR=${byHour.join(",")}`);
|
|
480
|
+
if (byMinute) parts.push(`BYMINUTE=${byMinute.join(",")}`);
|
|
481
|
+
if (byDay) parts.push(`BYDAY=${byDay.join(",")}`);
|
|
482
|
+
if (byMonth) parts.push(`BYMONTH=${byMonth.join(",")}`);
|
|
483
|
+
return [dtLine, `RRULE:${parts.join(";")}`].join("\n");
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Given any date in a month, return all the ZonedDateTimes in that month
|
|
487
|
+
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
488
|
+
*/
|
|
489
|
+
generateMonthlyOccurrences(sample) {
|
|
490
|
+
const { byDay, byMonth, tzid } = this.opts;
|
|
491
|
+
if (byMonth && !byMonth.includes(sample.month)) {
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
if (!byDay || byDay.length === 0) {
|
|
495
|
+
return [sample];
|
|
496
|
+
}
|
|
497
|
+
const dayMap = {
|
|
498
|
+
MO: 1,
|
|
499
|
+
TU: 2,
|
|
500
|
+
WE: 3,
|
|
501
|
+
TH: 4,
|
|
502
|
+
FR: 5,
|
|
503
|
+
SA: 6,
|
|
504
|
+
SU: 7
|
|
505
|
+
};
|
|
506
|
+
const tokens = byDay.map((tok) => {
|
|
507
|
+
const m = tok.match(/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
508
|
+
if (!m) return null;
|
|
509
|
+
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
510
|
+
const wd = dayMap[m[2]];
|
|
511
|
+
return { ord, wd };
|
|
512
|
+
}).filter((x) => x !== null);
|
|
513
|
+
const year = sample.year;
|
|
514
|
+
const month = sample.month;
|
|
515
|
+
let cursor = Temporal.ZonedDateTime.from({
|
|
516
|
+
year,
|
|
517
|
+
month,
|
|
518
|
+
day: 1,
|
|
519
|
+
hour: sample.hour,
|
|
520
|
+
minute: sample.minute,
|
|
521
|
+
second: sample.second,
|
|
522
|
+
timeZone: tzid
|
|
523
|
+
});
|
|
524
|
+
const weekdayBuckets = {};
|
|
525
|
+
while (cursor.month === month) {
|
|
526
|
+
const dow = cursor.dayOfWeek;
|
|
527
|
+
weekdayBuckets[dow] = weekdayBuckets[dow] || [];
|
|
528
|
+
weekdayBuckets[dow].push(cursor.day);
|
|
529
|
+
cursor = cursor.add({ days: 1 });
|
|
530
|
+
}
|
|
531
|
+
const results = [];
|
|
532
|
+
for (const { ord, wd } of tokens) {
|
|
533
|
+
const days = weekdayBuckets[wd] || [];
|
|
534
|
+
if (!days.length) continue;
|
|
535
|
+
if (ord === 0) {
|
|
536
|
+
for (const d of days) {
|
|
537
|
+
results.push(sample.with({ day: d }));
|
|
516
538
|
}
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
continue;
|
|
523
|
-
if (ord === 0) {
|
|
524
|
-
// simple weekday: include *all* Fridays, e.g.
|
|
525
|
-
for (const d of days) {
|
|
526
|
-
results.push(sample.with({ day: d }));
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
// ordinal: 2FR → days[1], -1FR → days[days.length-1], etc.
|
|
531
|
-
const idx = ord > 0 ? ord - 1 : days.length + ord;
|
|
532
|
-
const dayNum = days[idx];
|
|
533
|
-
if (dayNum) {
|
|
534
|
-
results.push(sample.with({ day: dayNum }));
|
|
535
|
-
}
|
|
536
|
-
}
|
|
539
|
+
} else {
|
|
540
|
+
const idx = ord > 0 ? ord - 1 : days.length + ord;
|
|
541
|
+
const dayNum = days[idx];
|
|
542
|
+
if (dayNum) {
|
|
543
|
+
results.push(sample.with({ day: dayNum }));
|
|
537
544
|
}
|
|
538
|
-
|
|
539
|
-
return results
|
|
540
|
-
.map((zdt) => this.applyTimeOverride(zdt))
|
|
541
|
-
.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
545
|
+
}
|
|
542
546
|
}
|
|
543
|
-
|
|
547
|
+
return results.map((zdt) => this.applyTimeOverride(zdt)).sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
export {
|
|
551
|
+
RRuleTemporal
|
|
552
|
+
};
|