rrule-temporal 0.2.7 → 0.3.2
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 +520 -92
- package/dist/index.d.cts +43 -4
- package/dist/index.d.ts +43 -4
- package/dist/index.js +520 -92
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -78,32 +78,79 @@ function formatByDayToken(tok) {
|
|
|
78
78
|
if (ord === -1) return `last ${name}`;
|
|
79
79
|
return `${ordinal(ord)} ${name}`;
|
|
80
80
|
}
|
|
81
|
+
function unfoldLine(foldedLine) {
|
|
82
|
+
return foldedLine.replace(/\r?\n[ \t]/g, "");
|
|
83
|
+
}
|
|
84
|
+
function parseDateValues(dateValues, tzid) {
|
|
85
|
+
const dates = [];
|
|
86
|
+
for (const dateValue of dateValues) {
|
|
87
|
+
if (/Z$/.test(dateValue)) {
|
|
88
|
+
const iso = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9, 15)}Z`;
|
|
89
|
+
dates.push(import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(
|
|
90
|
+
tzid || "UTC"
|
|
91
|
+
));
|
|
92
|
+
} else {
|
|
93
|
+
const isoDate = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9)}`;
|
|
94
|
+
dates.push(import_polyfill.Temporal.PlainDateTime.from(isoDate).toZonedDateTime(tzid));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return dates;
|
|
98
|
+
}
|
|
81
99
|
function parseRRuleString(input, fallbackDtstart) {
|
|
100
|
+
const unfoldedInput = unfoldLine(input);
|
|
82
101
|
let dtstart;
|
|
83
102
|
let tzid = "UTC";
|
|
84
103
|
let rruleLine;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
let exDate = [];
|
|
105
|
+
let rDate = [];
|
|
106
|
+
if (/^DTSTART/mi.test(unfoldedInput)) {
|
|
107
|
+
const lines = unfoldedInput.split(/\r?\n/);
|
|
108
|
+
const dtLine = lines[0];
|
|
109
|
+
const rrLine = lines.find((line) => line.match(/^RRULE:/i));
|
|
110
|
+
const exLines = lines.filter((line) => line.match(/^EXDATE/i));
|
|
111
|
+
const rLines = lines.filter((line) => line.match(/^RDATE/i));
|
|
112
|
+
const m = dtLine?.match(/DTSTART(?:;TZID=([^:]+))?:(\d{8}T\d{6})/i);
|
|
88
113
|
if (!m) throw new Error("Invalid DTSTART in ICS snippet");
|
|
89
114
|
tzid = m[1] || tzid;
|
|
90
115
|
const isoDate = `${m[2].slice(0, 4)}-${m[2].slice(4, 6)}-${m[2].slice(6, 8)}T${m[2].slice(9)}`;
|
|
91
116
|
dtstart = import_polyfill.Temporal.PlainDateTime.from(isoDate).toZonedDateTime(tzid);
|
|
92
117
|
rruleLine = rrLine;
|
|
118
|
+
for (const exLine of exLines) {
|
|
119
|
+
const exMatch = exLine.match(/EXDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
120
|
+
if (exMatch) {
|
|
121
|
+
const exTzid = exMatch[1] || tzid;
|
|
122
|
+
const dateValues = exMatch[2].split(",");
|
|
123
|
+
exDate.push(...parseDateValues(dateValues, exTzid));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const rLine of rLines) {
|
|
127
|
+
const rMatch = rLine.match(/RDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
128
|
+
if (rMatch) {
|
|
129
|
+
const rTzid = rMatch[1] || tzid;
|
|
130
|
+
const dateValues = rMatch[2].split(",");
|
|
131
|
+
rDate.push(...parseDateValues(dateValues, rTzid));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
93
134
|
} else {
|
|
94
135
|
if (!fallbackDtstart)
|
|
95
136
|
throw new Error("dtstart required when parsing RRULE alone");
|
|
96
137
|
dtstart = fallbackDtstart;
|
|
97
138
|
tzid = fallbackDtstart.timeZoneId;
|
|
98
|
-
rruleLine =
|
|
139
|
+
rruleLine = unfoldedInput.replace(/^RRULE:/i, "RRULE:");
|
|
99
140
|
}
|
|
100
|
-
const parts = rruleLine.replace(/^RRULE
|
|
101
|
-
const opts = {
|
|
141
|
+
const parts = rruleLine ? rruleLine.replace(/^RRULE:/i, "").split(";") : [];
|
|
142
|
+
const opts = {
|
|
143
|
+
dtstart,
|
|
144
|
+
tzid,
|
|
145
|
+
exDate: exDate.length > 0 ? exDate : void 0,
|
|
146
|
+
rDate: rDate.length > 0 ? rDate : void 0
|
|
147
|
+
};
|
|
102
148
|
for (const part of parts) {
|
|
103
149
|
const [key, val] = part.split("=");
|
|
104
|
-
|
|
150
|
+
if (!key) continue;
|
|
151
|
+
switch (key.toUpperCase()) {
|
|
105
152
|
case "FREQ":
|
|
106
|
-
opts.freq = val;
|
|
153
|
+
opts.freq = val.toUpperCase();
|
|
107
154
|
break;
|
|
108
155
|
case "INTERVAL":
|
|
109
156
|
opts.interval = parseInt(val, 10);
|
|
@@ -140,6 +187,21 @@ function parseRRuleString(input, fallbackDtstart) {
|
|
|
140
187
|
case "BYMONTHDAY":
|
|
141
188
|
opts.byMonthDay = val.split(",").map((n) => parseInt(n, 10));
|
|
142
189
|
break;
|
|
190
|
+
case "BYSECOND":
|
|
191
|
+
opts.bySecond = val.split(",").map((n) => parseInt(n, 10)).sort((a, b) => a - b);
|
|
192
|
+
break;
|
|
193
|
+
case "BYYEARDAY":
|
|
194
|
+
opts.byYearDay = val.split(",").map((n) => parseInt(n, 10));
|
|
195
|
+
break;
|
|
196
|
+
case "BYWEEKNO":
|
|
197
|
+
opts.byWeekNo = val.split(",").map((n) => parseInt(n, 10));
|
|
198
|
+
break;
|
|
199
|
+
case "BYSETPOS":
|
|
200
|
+
opts.bySetPos = val.split(",").map((n) => parseInt(n, 10));
|
|
201
|
+
break;
|
|
202
|
+
case "WKST":
|
|
203
|
+
opts.wkst = val;
|
|
204
|
+
break;
|
|
143
205
|
}
|
|
144
206
|
}
|
|
145
207
|
return opts;
|
|
@@ -165,6 +227,7 @@ var RRuleTemporal = class {
|
|
|
165
227
|
tzid;
|
|
166
228
|
originalDtstart;
|
|
167
229
|
opts;
|
|
230
|
+
maxIterations;
|
|
168
231
|
constructor(params) {
|
|
169
232
|
let manual;
|
|
170
233
|
if ("rruleString" in params) {
|
|
@@ -182,7 +245,54 @@ var RRuleTemporal = class {
|
|
|
182
245
|
}
|
|
183
246
|
if (!manual.freq) throw new Error("RRULE must include FREQ");
|
|
184
247
|
manual.interval = manual.interval ?? 1;
|
|
185
|
-
|
|
248
|
+
if (manual.interval <= 0) {
|
|
249
|
+
throw new Error("Cannot create RRule: interval must be greater than 0");
|
|
250
|
+
}
|
|
251
|
+
if (manual.until && !(manual.until instanceof import_polyfill.Temporal.ZonedDateTime)) {
|
|
252
|
+
throw new Error("Manual until must be a ZonedDateTime");
|
|
253
|
+
}
|
|
254
|
+
this.opts = this.sanitizeOpts(manual);
|
|
255
|
+
this.maxIterations = manual.maxIterations ?? 1e4;
|
|
256
|
+
}
|
|
257
|
+
sanitizeOpts(opts) {
|
|
258
|
+
const validDay = /^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/;
|
|
259
|
+
if (opts.byDay) {
|
|
260
|
+
opts.byDay = opts.byDay.filter((d) => validDay.test(d));
|
|
261
|
+
if (opts.byDay.length === 0) delete opts.byDay;
|
|
262
|
+
}
|
|
263
|
+
if (opts.byMonth) {
|
|
264
|
+
opts.byMonth = opts.byMonth.filter((n) => Number.isInteger(n) && n >= 1 && n <= 12);
|
|
265
|
+
if (opts.byMonth.length === 0) delete opts.byMonth;
|
|
266
|
+
}
|
|
267
|
+
if (opts.byMonthDay) {
|
|
268
|
+
opts.byMonthDay = opts.byMonthDay.filter((n) => Number.isInteger(n) && n !== 0 && n >= -31 && n <= 31);
|
|
269
|
+
if (opts.byMonthDay.length === 0) delete opts.byMonthDay;
|
|
270
|
+
}
|
|
271
|
+
if (opts.byYearDay) {
|
|
272
|
+
opts.byYearDay = opts.byYearDay.filter((n) => Number.isInteger(n) && n !== 0 && n >= -366 && n <= 366);
|
|
273
|
+
if (opts.byYearDay.length === 0) delete opts.byYearDay;
|
|
274
|
+
}
|
|
275
|
+
if (opts.byWeekNo) {
|
|
276
|
+
opts.byWeekNo = opts.byWeekNo.filter((n) => Number.isInteger(n) && n !== 0 && n >= -53 && n <= 53);
|
|
277
|
+
if (opts.byWeekNo.length === 0) delete opts.byWeekNo;
|
|
278
|
+
}
|
|
279
|
+
if (opts.byHour) {
|
|
280
|
+
opts.byHour = opts.byHour.filter((n) => Number.isInteger(n) && n >= 0 && n <= 23).sort((a, b) => a - b);
|
|
281
|
+
if (opts.byHour.length === 0) delete opts.byHour;
|
|
282
|
+
}
|
|
283
|
+
if (opts.byMinute) {
|
|
284
|
+
opts.byMinute = opts.byMinute.filter((n) => Number.isInteger(n) && n >= 0 && n <= 59).sort((a, b) => a - b);
|
|
285
|
+
if (opts.byMinute.length === 0) delete opts.byMinute;
|
|
286
|
+
}
|
|
287
|
+
if (opts.bySecond) {
|
|
288
|
+
opts.bySecond = opts.bySecond.filter((n) => Number.isInteger(n) && n >= 0 && n <= 59).sort((a, b) => a - b);
|
|
289
|
+
if (opts.bySecond.length === 0) delete opts.bySecond;
|
|
290
|
+
}
|
|
291
|
+
if (opts.bySetPos) {
|
|
292
|
+
opts.bySetPos = opts.bySetPos.filter((n) => Number.isInteger(n) && n !== 0);
|
|
293
|
+
if (opts.bySetPos.length === 0) delete opts.bySetPos;
|
|
294
|
+
}
|
|
295
|
+
return opts;
|
|
186
296
|
}
|
|
187
297
|
rawAdvance(zdt) {
|
|
188
298
|
const { freq, interval } = this.opts;
|
|
@@ -205,38 +315,64 @@ var RRuleTemporal = class {
|
|
|
205
315
|
throw new Error(`Unsupported FREQ: ${freq}`);
|
|
206
316
|
}
|
|
207
317
|
}
|
|
208
|
-
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE
|
|
209
|
-
* keeping chronological order.
|
|
210
|
-
* original date is returned unchanged.
|
|
318
|
+
/** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
|
|
319
|
+
* combinations, keeping chronological order. If the options are not
|
|
320
|
+
* present the original date is returned unchanged.
|
|
211
321
|
*/
|
|
212
|
-
|
|
322
|
+
expandByTime(base) {
|
|
213
323
|
const hours = this.opts.byHour ?? [base.hour];
|
|
214
324
|
const minutes = this.opts.byMinute ?? [base.minute];
|
|
325
|
+
const seconds = this.opts.bySecond ?? [base.second];
|
|
215
326
|
const out = [];
|
|
216
327
|
for (const h of hours) {
|
|
217
328
|
for (const m of minutes) {
|
|
218
|
-
|
|
329
|
+
for (const s of seconds) {
|
|
330
|
+
out.push(base.with({ hour: h, minute: m, second: s }));
|
|
331
|
+
}
|
|
219
332
|
}
|
|
220
333
|
}
|
|
221
334
|
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
222
335
|
}
|
|
223
336
|
nextCandidateSameDate(zdt) {
|
|
224
|
-
const { freq, interval = 1, byHour, byMinute } = this.opts;
|
|
337
|
+
const { freq, interval = 1, byHour, byMinute, bySecond } = this.opts;
|
|
225
338
|
if (freq === "HOURLY" && byHour && byHour.length === 1) {
|
|
226
339
|
return this.applyTimeOverride(zdt.add({ days: interval }));
|
|
227
340
|
}
|
|
228
341
|
if (freq === "MINUTELY" && byMinute && byMinute.length === 1) {
|
|
229
342
|
return this.applyTimeOverride(zdt.add({ hours: interval }));
|
|
230
343
|
}
|
|
344
|
+
if (freq === "MINUTELY" && byHour && byHour.length > 1 && !byMinute && interval > 1) {
|
|
345
|
+
const next = zdt.add({ minutes: interval });
|
|
346
|
+
if (byHour.includes(next.hour)) {
|
|
347
|
+
return next;
|
|
348
|
+
}
|
|
349
|
+
const nextHour = byHour.find((h) => h > zdt.hour) || byHour[0];
|
|
350
|
+
if (nextHour && nextHour > zdt.hour) {
|
|
351
|
+
return zdt.with({ hour: nextHour, minute: 0 });
|
|
352
|
+
}
|
|
353
|
+
return this.applyTimeOverride(zdt.add({ days: 1 }));
|
|
354
|
+
}
|
|
355
|
+
if (freq === "SECONDLY" && bySecond && bySecond.length === 1) {
|
|
356
|
+
return this.applyTimeOverride(zdt.add({ minutes: interval })).with({ second: bySecond[0] });
|
|
357
|
+
}
|
|
231
358
|
if (freq === "SECONDLY" && byMinute && byMinute.length === 1) {
|
|
232
359
|
const next = zdt.add({ seconds: interval });
|
|
233
360
|
if (next.minute === byMinute[0]) return next;
|
|
234
361
|
return this.applyTimeOverride(zdt.add({ hours: interval })).with({ second: 0 });
|
|
235
362
|
}
|
|
363
|
+
if (bySecond && bySecond.length > 1) {
|
|
364
|
+
const idx = bySecond.indexOf(zdt.second);
|
|
365
|
+
if (idx !== -1 && idx < bySecond.length - 1) {
|
|
366
|
+
return zdt.with({ second: bySecond[idx + 1] });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
236
369
|
if (byMinute && byMinute.length > 1) {
|
|
237
370
|
const idx = byMinute.indexOf(zdt.minute);
|
|
238
371
|
if (idx !== -1 && idx < byMinute.length - 1) {
|
|
239
|
-
return zdt.with({
|
|
372
|
+
return zdt.with({
|
|
373
|
+
minute: byMinute[idx + 1],
|
|
374
|
+
second: bySecond ? bySecond[0] : zdt.second
|
|
375
|
+
});
|
|
240
376
|
}
|
|
241
377
|
}
|
|
242
378
|
if (byHour && byHour.length > 1) {
|
|
@@ -244,17 +380,19 @@ var RRuleTemporal = class {
|
|
|
244
380
|
if (idx !== -1 && idx < byHour.length - 1) {
|
|
245
381
|
return zdt.with({
|
|
246
382
|
hour: byHour[idx + 1],
|
|
247
|
-
minute: byMinute ? byMinute[0] : zdt.minute
|
|
383
|
+
minute: byMinute ? byMinute[0] : zdt.minute,
|
|
384
|
+
second: bySecond ? bySecond[0] : zdt.second
|
|
248
385
|
});
|
|
249
386
|
}
|
|
250
387
|
}
|
|
251
388
|
return this.applyTimeOverride(this.rawAdvance(zdt));
|
|
252
389
|
}
|
|
253
390
|
applyTimeOverride(zdt) {
|
|
254
|
-
const { byHour, byMinute } = this.opts;
|
|
391
|
+
const { byHour, byMinute, bySecond } = this.opts;
|
|
255
392
|
let dt = zdt;
|
|
256
393
|
if (byHour) dt = dt.with({ hour: byHour[0] });
|
|
257
394
|
if (byMinute) dt = dt.with({ minute: byMinute[0] });
|
|
395
|
+
if (bySecond) dt = dt.with({ second: bySecond[0] });
|
|
258
396
|
return dt;
|
|
259
397
|
}
|
|
260
398
|
computeFirst() {
|
|
@@ -284,8 +422,8 @@ var RRuleTemporal = class {
|
|
|
284
422
|
zdt = zdt.add({ days: Math.min(...deltas) });
|
|
285
423
|
}
|
|
286
424
|
}
|
|
287
|
-
const { byHour, byMinute } = this.opts;
|
|
288
|
-
if (byHour || byMinute) {
|
|
425
|
+
const { byHour, byMinute, bySecond } = this.opts;
|
|
426
|
+
if (byHour || byMinute || bySecond) {
|
|
289
427
|
zdt = this.applyTimeOverride(zdt);
|
|
290
428
|
if (import_polyfill.Temporal.Instant.compare(
|
|
291
429
|
zdt.toInstant(),
|
|
@@ -312,7 +450,7 @@ var RRuleTemporal = class {
|
|
|
312
450
|
const targetDow = dayMap[tok];
|
|
313
451
|
const delta = (targetDow - sample.dayOfWeek + 7) % 7;
|
|
314
452
|
const sameDate = sample.add({ days: delta });
|
|
315
|
-
return this.
|
|
453
|
+
return this.expandByTime(sameDate);
|
|
316
454
|
});
|
|
317
455
|
return occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
318
456
|
}
|
|
@@ -331,7 +469,7 @@ var RRuleTemporal = class {
|
|
|
331
469
|
SU: 7
|
|
332
470
|
};
|
|
333
471
|
for (const token of byDay) {
|
|
334
|
-
const m = token.match(/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
472
|
+
const m = token.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
335
473
|
if (!m) continue;
|
|
336
474
|
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
337
475
|
const weekday = m[2];
|
|
@@ -367,7 +505,28 @@ var RRuleTemporal = class {
|
|
|
367
505
|
);
|
|
368
506
|
}
|
|
369
507
|
matchesAll(zdt) {
|
|
370
|
-
return this.matchesByDay(zdt) && this.matchesByMonth(zdt) && this.matchesByMonthDay(zdt);
|
|
508
|
+
return this.matchesByDay(zdt) && this.matchesByMonth(zdt) && this.matchesByMonthDay(zdt) && this.matchesByYearDay(zdt) && this.matchesByWeekNo(zdt);
|
|
509
|
+
}
|
|
510
|
+
matchesByYearDay(zdt) {
|
|
511
|
+
const { byYearDay } = this.opts;
|
|
512
|
+
if (!byYearDay) return true;
|
|
513
|
+
const dayOfYear = zdt.dayOfYear;
|
|
514
|
+
const last = zdt.with({ month: 12, day: 31 }).dayOfYear;
|
|
515
|
+
return byYearDay.some((d) => d > 0 ? dayOfYear === d : dayOfYear === last + d + 1);
|
|
516
|
+
}
|
|
517
|
+
matchesByWeekNo(zdt) {
|
|
518
|
+
const { byWeekNo, wkst } = this.opts;
|
|
519
|
+
if (!byWeekNo) return true;
|
|
520
|
+
const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
521
|
+
const startDow = dayMap[wkst ?? "MO"];
|
|
522
|
+
const jan1 = zdt.with({ month: 1, day: 1 });
|
|
523
|
+
const delta = (jan1.dayOfWeek - startDow + 7) % 7;
|
|
524
|
+
const firstWeekStart = jan1.subtract({ days: delta });
|
|
525
|
+
const diffDays = zdt.toPlainDate().since(firstWeekStart.toPlainDate()).days;
|
|
526
|
+
const week = Math.floor(diffDays / 7) + 1;
|
|
527
|
+
const lastWeekDiff = zdt.with({ month: 12, day: 31 }).toPlainDate().since(firstWeekStart.toPlainDate()).days;
|
|
528
|
+
const lastWeek = Math.floor(lastWeekDiff / 7) + 1;
|
|
529
|
+
return byWeekNo.some((n) => n > 0 ? week === n : week === lastWeek + n + 1);
|
|
371
530
|
}
|
|
372
531
|
options() {
|
|
373
532
|
return this.opts;
|
|
@@ -382,11 +541,15 @@ var RRuleTemporal = class {
|
|
|
382
541
|
throw new Error("all() requires iterator when no COUNT/UNTIL");
|
|
383
542
|
}
|
|
384
543
|
const dates = [];
|
|
544
|
+
let iterationCount = 0;
|
|
385
545
|
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
386
546
|
const start = this.originalDtstart;
|
|
387
547
|
let monthCursor = start.with({ day: 1 });
|
|
388
548
|
let matchCount2 = 0;
|
|
389
549
|
outer_month: while (true) {
|
|
550
|
+
if (++iterationCount > this.maxIterations) {
|
|
551
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
552
|
+
}
|
|
390
553
|
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
391
554
|
if (monthCursor.month === start.month && occs.some((o) => import_polyfill.Temporal.ZonedDateTime.compare(o, start) < 0)) {
|
|
392
555
|
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
@@ -397,18 +560,18 @@ var RRuleTemporal = class {
|
|
|
397
560
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
398
561
|
break outer_month;
|
|
399
562
|
}
|
|
400
|
-
if (this.opts.count !== void 0 && matchCount2 >= this.opts.count) {
|
|
401
|
-
break outer_month;
|
|
402
|
-
}
|
|
403
563
|
if (iterator && !iterator(occ, matchCount2)) {
|
|
404
564
|
break outer_month;
|
|
405
565
|
}
|
|
406
566
|
dates.push(occ);
|
|
407
567
|
matchCount2++;
|
|
568
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
569
|
+
break outer_month;
|
|
570
|
+
}
|
|
408
571
|
}
|
|
409
572
|
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
410
573
|
}
|
|
411
|
-
return dates;
|
|
574
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
412
575
|
}
|
|
413
576
|
if (this.opts.freq === "WEEKLY") {
|
|
414
577
|
const start = this.originalDtstart;
|
|
@@ -427,105 +590,215 @@ var RRuleTemporal = class {
|
|
|
427
590
|
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
428
591
|
return start.add({ days: delta });
|
|
429
592
|
});
|
|
430
|
-
let
|
|
593
|
+
let firstOccurrence = firstWeekDates.reduce(
|
|
431
594
|
(a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b
|
|
432
595
|
);
|
|
596
|
+
const wkstDay = dayMap[this.opts.wkst || "MO"] ?? 1;
|
|
597
|
+
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
598
|
+
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
433
599
|
let matchCount2 = 0;
|
|
434
600
|
outer_week: while (true) {
|
|
435
|
-
|
|
601
|
+
if (++iterationCount > this.maxIterations) {
|
|
602
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
603
|
+
}
|
|
436
604
|
const occs = dows.flatMap((dw) => {
|
|
437
|
-
const delta = dw -
|
|
605
|
+
const delta = (dw - wkstDay + 7) % 7;
|
|
438
606
|
const sameDate = weekCursor.add({ days: delta });
|
|
439
|
-
return this.
|
|
607
|
+
return this.expandByTime(sameDate);
|
|
440
608
|
}).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
441
609
|
for (const occ of occs) {
|
|
442
610
|
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
443
611
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
444
612
|
break outer_week;
|
|
445
613
|
}
|
|
446
|
-
if (this.opts.count !== void 0 && matchCount2 >= this.opts.count) {
|
|
447
|
-
break outer_week;
|
|
448
|
-
}
|
|
449
614
|
if (iterator && !iterator(occ, matchCount2)) {
|
|
450
615
|
break outer_week;
|
|
451
616
|
}
|
|
452
617
|
dates.push(occ);
|
|
453
618
|
matchCount2++;
|
|
619
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
620
|
+
break outer_week;
|
|
621
|
+
}
|
|
454
622
|
}
|
|
455
623
|
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
456
624
|
}
|
|
457
|
-
return dates;
|
|
625
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
458
626
|
}
|
|
459
627
|
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
460
628
|
const start = this.originalDtstart;
|
|
461
629
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
462
|
-
let
|
|
630
|
+
let yearOffset = 0;
|
|
631
|
+
let matchCount2 = 0;
|
|
463
632
|
while (true) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
let occ = start.with({ year, month });
|
|
467
|
-
occ = this.applyTimeOverride(occ);
|
|
468
|
-
if (i === 0 && import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
469
|
-
i++;
|
|
470
|
-
continue;
|
|
633
|
+
if (++iterationCount > this.maxIterations) {
|
|
634
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
471
635
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
636
|
+
const year = start.year + yearOffset * this.opts.interval;
|
|
637
|
+
for (const month of months) {
|
|
638
|
+
let occ = start.with({ year, month });
|
|
639
|
+
occ = this.applyTimeOverride(occ);
|
|
640
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
644
|
+
return dates;
|
|
645
|
+
}
|
|
646
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
647
|
+
return dates;
|
|
648
|
+
}
|
|
649
|
+
dates.push(occ);
|
|
650
|
+
matchCount2++;
|
|
651
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
652
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
653
|
+
}
|
|
480
654
|
}
|
|
481
|
-
|
|
482
|
-
i++;
|
|
655
|
+
yearOffset++;
|
|
483
656
|
}
|
|
484
|
-
return dates;
|
|
657
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
485
658
|
}
|
|
486
659
|
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
487
660
|
const start = this.originalDtstart;
|
|
488
661
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
489
662
|
let matchCount2 = 0;
|
|
490
663
|
outer_year: while (true) {
|
|
664
|
+
if (++iterationCount > this.maxIterations) {
|
|
665
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
666
|
+
}
|
|
491
667
|
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
492
668
|
for (const occ of occs) {
|
|
493
669
|
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
494
670
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
495
671
|
break outer_year;
|
|
496
672
|
}
|
|
497
|
-
if (
|
|
673
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
498
674
|
break outer_year;
|
|
499
675
|
}
|
|
500
|
-
|
|
676
|
+
dates.push(occ);
|
|
677
|
+
matchCount2++;
|
|
678
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
501
679
|
break outer_year;
|
|
502
680
|
}
|
|
681
|
+
}
|
|
682
|
+
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
683
|
+
}
|
|
684
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
685
|
+
}
|
|
686
|
+
if (this.opts.freq === "YEARLY" && (this.opts.byYearDay || this.opts.byWeekNo)) {
|
|
687
|
+
const start = this.originalDtstart;
|
|
688
|
+
let yearCursor = start.with({ month: 1, day: 1 });
|
|
689
|
+
let matchCount2 = 0;
|
|
690
|
+
outer_year2: while (true) {
|
|
691
|
+
if (++iterationCount > this.maxIterations) {
|
|
692
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
693
|
+
}
|
|
694
|
+
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
695
|
+
for (const occ of occs) {
|
|
696
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
697
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
698
|
+
break outer_year2;
|
|
699
|
+
}
|
|
700
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
701
|
+
break outer_year2;
|
|
702
|
+
}
|
|
503
703
|
dates.push(occ);
|
|
504
704
|
matchCount2++;
|
|
705
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
706
|
+
break outer_year2;
|
|
707
|
+
}
|
|
505
708
|
}
|
|
506
709
|
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
507
710
|
}
|
|
508
|
-
return dates;
|
|
711
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
509
712
|
}
|
|
510
713
|
let current = this.computeFirst();
|
|
511
714
|
let matchCount = 0;
|
|
512
715
|
while (true) {
|
|
716
|
+
if (++iterationCount > this.maxIterations) {
|
|
717
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
718
|
+
}
|
|
513
719
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
514
720
|
break;
|
|
515
721
|
}
|
|
516
722
|
if (this.matchesAll(current)) {
|
|
517
|
-
if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
723
|
if (iterator && !iterator(current, matchCount)) {
|
|
521
724
|
break;
|
|
522
725
|
}
|
|
523
726
|
dates.push(current);
|
|
524
727
|
matchCount++;
|
|
728
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
525
731
|
}
|
|
526
732
|
current = this.nextCandidateSameDate(current);
|
|
527
733
|
}
|
|
528
|
-
return dates;
|
|
734
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Converts rDate entries to ZonedDateTime and merges with existing dates.
|
|
738
|
+
* @param dates - Array of dates to merge with
|
|
739
|
+
* @returns Merged and deduplicated array of dates
|
|
740
|
+
*/
|
|
741
|
+
mergeAndDeduplicateRDates(dates) {
|
|
742
|
+
if (!this.opts.rDate) return dates;
|
|
743
|
+
dates.push(...this.opts.rDate);
|
|
744
|
+
dates.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
745
|
+
const dedup = [];
|
|
746
|
+
for (const d of dates) {
|
|
747
|
+
if (dedup.length === 0 || import_polyfill.Temporal.ZonedDateTime.compare(d, dedup[dedup.length - 1]) !== 0) {
|
|
748
|
+
dedup.push(d);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return dedup;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Excludes exDate entries from the given array of dates.
|
|
755
|
+
* @param dates - Array of dates to filter
|
|
756
|
+
* @returns Filtered array with exDate entries removed
|
|
757
|
+
*/
|
|
758
|
+
excludeExDates(dates) {
|
|
759
|
+
if (!this.opts.exDate || this.opts.exDate.length === 0) return dates;
|
|
760
|
+
return dates.filter((date) => {
|
|
761
|
+
return !this.opts.exDate.some(
|
|
762
|
+
(exDate) => import_polyfill.Temporal.ZonedDateTime.compare(date, exDate) === 0
|
|
763
|
+
);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Applies count limit and merges rDates with the rule-generated dates.
|
|
768
|
+
* @param dates - Array of dates generated by the rule
|
|
769
|
+
* @param iterator - Optional iterator function
|
|
770
|
+
* @returns Final array of dates after merging and applying count limit
|
|
771
|
+
*/
|
|
772
|
+
applyCountLimitAndMergeRDates(dates, iterator) {
|
|
773
|
+
const merged = this.mergeAndDeduplicateRDates(dates);
|
|
774
|
+
const excluded = this.excludeExDates(merged);
|
|
775
|
+
if (this.opts.count !== void 0) {
|
|
776
|
+
let finalCount = 0;
|
|
777
|
+
const finalDates = [];
|
|
778
|
+
for (const d of excluded) {
|
|
779
|
+
if (finalCount >= this.opts.count) break;
|
|
780
|
+
if (iterator && !iterator(d, finalCount)) break;
|
|
781
|
+
finalDates.push(d);
|
|
782
|
+
finalCount++;
|
|
783
|
+
}
|
|
784
|
+
return finalDates;
|
|
785
|
+
}
|
|
786
|
+
return excluded;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Checks if the count limit should break the loop based on rDate presence.
|
|
790
|
+
* @param matchCount - Current number of matches
|
|
791
|
+
* @returns true if the loop should break
|
|
792
|
+
*/
|
|
793
|
+
shouldBreakForCountLimit(matchCount) {
|
|
794
|
+
if (this.opts.count === void 0) return false;
|
|
795
|
+
if (!this.opts.rDate) {
|
|
796
|
+
return matchCount >= this.opts.count;
|
|
797
|
+
}
|
|
798
|
+
const rDateCount = this.opts.rDate.length;
|
|
799
|
+
const targetRuleCount = Math.max(this.opts.count - rDateCount, 0);
|
|
800
|
+
const safetyMargin = Math.min(targetRuleCount, 10);
|
|
801
|
+
return matchCount >= targetRuleCount + safetyMargin;
|
|
529
802
|
}
|
|
530
803
|
/**
|
|
531
804
|
* Returns all occurrences of the rule within a specified time window.
|
|
@@ -538,60 +811,96 @@ var RRuleTemporal = class {
|
|
|
538
811
|
const startInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
539
812
|
const endInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
540
813
|
const results = [];
|
|
814
|
+
let iterationCount = 0;
|
|
541
815
|
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
542
816
|
let monthCursor = this.computeFirst().with({ day: 1 });
|
|
543
817
|
outer: while (true) {
|
|
818
|
+
if (++iterationCount > this.maxIterations) {
|
|
819
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
820
|
+
}
|
|
544
821
|
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
545
822
|
for (const occ of occs) {
|
|
546
823
|
const inst = occ.toInstant();
|
|
547
824
|
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
548
825
|
break outer;
|
|
549
826
|
}
|
|
550
|
-
|
|
827
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
828
|
+
if (startOk) {
|
|
551
829
|
results.push(occ);
|
|
552
830
|
}
|
|
553
831
|
}
|
|
554
832
|
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
555
833
|
}
|
|
556
|
-
return results;
|
|
834
|
+
return this.mergeRDates(results, startInst, endInst, inc);
|
|
557
835
|
}
|
|
558
836
|
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
559
837
|
const start = this.originalDtstart;
|
|
560
838
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
561
|
-
let
|
|
839
|
+
let yearOffset = 0;
|
|
562
840
|
outer: while (true) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
let occ = start.with({ year, month });
|
|
566
|
-
occ = this.applyTimeOverride(occ);
|
|
567
|
-
const inst = occ.toInstant();
|
|
568
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
569
|
-
break;
|
|
841
|
+
if (++iterationCount > this.maxIterations) {
|
|
842
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
570
843
|
}
|
|
571
|
-
|
|
572
|
-
|
|
844
|
+
const year = start.year + yearOffset * this.opts.interval;
|
|
845
|
+
for (const month of months) {
|
|
846
|
+
let occ = start.with({ year, month });
|
|
847
|
+
occ = this.applyTimeOverride(occ);
|
|
848
|
+
const inst = occ.toInstant();
|
|
849
|
+
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
850
|
+
break outer;
|
|
851
|
+
}
|
|
852
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
853
|
+
if (startOk) {
|
|
854
|
+
results.push(occ);
|
|
855
|
+
}
|
|
573
856
|
}
|
|
574
|
-
|
|
857
|
+
yearOffset++;
|
|
575
858
|
}
|
|
576
|
-
return results;
|
|
859
|
+
return this.mergeRDates(results, startInst, endInst, inc);
|
|
577
860
|
}
|
|
578
861
|
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
579
862
|
const start = this.originalDtstart;
|
|
580
863
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
581
864
|
outer_year: while (true) {
|
|
865
|
+
if (++iterationCount > this.maxIterations) {
|
|
866
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
867
|
+
}
|
|
582
868
|
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
583
869
|
for (const occ of occs) {
|
|
584
870
|
const inst = occ.toInstant();
|
|
585
871
|
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
586
872
|
break outer_year;
|
|
587
873
|
}
|
|
588
|
-
|
|
874
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
875
|
+
if (startOk) {
|
|
876
|
+
results.push(occ);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
880
|
+
}
|
|
881
|
+
return this.mergeRDates(results, startInst, endInst, inc);
|
|
882
|
+
}
|
|
883
|
+
if (this.opts.freq === "YEARLY" && (this.opts.byYearDay || this.opts.byWeekNo)) {
|
|
884
|
+
const start = this.originalDtstart;
|
|
885
|
+
let yearCursor = start.with({ month: 1, day: 1 });
|
|
886
|
+
outer_year2: while (true) {
|
|
887
|
+
if (++iterationCount > this.maxIterations) {
|
|
888
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
889
|
+
}
|
|
890
|
+
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
891
|
+
for (const occ of occs) {
|
|
892
|
+
const inst = occ.toInstant();
|
|
893
|
+
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
894
|
+
break outer_year2;
|
|
895
|
+
}
|
|
896
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
897
|
+
if (startOk) {
|
|
589
898
|
results.push(occ);
|
|
590
899
|
}
|
|
591
900
|
}
|
|
592
901
|
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
593
902
|
}
|
|
594
|
-
return results;
|
|
903
|
+
return this.mergeRDates(results, startInst, endInst, inc);
|
|
595
904
|
}
|
|
596
905
|
if (this.opts.freq === "WEEKLY") {
|
|
597
906
|
const startInst2 = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
@@ -599,34 +908,42 @@ var RRuleTemporal = class {
|
|
|
599
908
|
let weekCursor = this.computeFirst();
|
|
600
909
|
const results2 = [];
|
|
601
910
|
outer: while (true) {
|
|
911
|
+
if (++iterationCount > this.maxIterations) {
|
|
912
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
913
|
+
}
|
|
602
914
|
const occs = this.generateWeeklyOccurrences(weekCursor);
|
|
603
915
|
for (const occ of occs) {
|
|
604
916
|
const inst = occ.toInstant();
|
|
605
917
|
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst2) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst2) >= 0) {
|
|
606
918
|
break outer;
|
|
607
919
|
}
|
|
608
|
-
|
|
920
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst2) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst2) > 0;
|
|
921
|
+
if (startOk) {
|
|
609
922
|
results2.push(occ);
|
|
610
923
|
}
|
|
611
924
|
}
|
|
612
925
|
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
613
926
|
}
|
|
614
|
-
return results2;
|
|
927
|
+
return this.mergeRDates(results2, startInst2, endInst2, inc);
|
|
615
928
|
}
|
|
616
929
|
let current = this.computeFirst();
|
|
617
930
|
while (true) {
|
|
931
|
+
if (++iterationCount > this.maxIterations) {
|
|
932
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
933
|
+
}
|
|
618
934
|
const inst = current.toInstant();
|
|
619
935
|
if (inc) {
|
|
620
936
|
if (import_polyfill.Temporal.Instant.compare(inst, endInst) > 0) break;
|
|
621
937
|
} else {
|
|
622
938
|
if (import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) break;
|
|
623
939
|
}
|
|
624
|
-
|
|
940
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
941
|
+
if (startOk && this.matchesAll(current)) {
|
|
625
942
|
results.push(current);
|
|
626
943
|
}
|
|
627
944
|
current = this.nextCandidateSameDate(current);
|
|
628
945
|
}
|
|
629
|
-
return results;
|
|
946
|
+
return this.mergeRDates(results, startInst, endInst, inc);
|
|
630
947
|
}
|
|
631
948
|
/**
|
|
632
949
|
* Returns the next occurrence of the rule after a specified date.
|
|
@@ -782,12 +1099,15 @@ var RRuleTemporal = class {
|
|
|
782
1099
|
if (byMonthDay && byMonthDay.length > 0) {
|
|
783
1100
|
byMonthDayHits = byMonthDay.map((d) => d > 0 ? d : lastDay + d + 1).filter((d) => d >= 1 && d <= lastDay);
|
|
784
1101
|
}
|
|
785
|
-
if (!byDay &&
|
|
1102
|
+
if (!byDay && byMonthDay && byMonthDay.length > 0) {
|
|
1103
|
+
if (byMonthDayHits.length === 0) {
|
|
1104
|
+
return [];
|
|
1105
|
+
}
|
|
786
1106
|
const dates = byMonthDayHits.map((d) => sample.with({ day: d }));
|
|
787
|
-
return dates.flatMap((z) => this.
|
|
1107
|
+
return dates.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
788
1108
|
}
|
|
789
1109
|
if (!byDay) {
|
|
790
|
-
return this.
|
|
1110
|
+
return this.expandByTime(sample);
|
|
791
1111
|
}
|
|
792
1112
|
const dayMap = {
|
|
793
1113
|
MO: 1,
|
|
@@ -799,7 +1119,7 @@ var RRuleTemporal = class {
|
|
|
799
1119
|
SU: 7
|
|
800
1120
|
};
|
|
801
1121
|
const tokens = byDay.map((tok) => {
|
|
802
|
-
const m = tok.match(/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
1122
|
+
const m = tok.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
803
1123
|
if (!m) return null;
|
|
804
1124
|
return { ord: m[1] ? parseInt(m[1], 10) : 0, wd: dayMap[m[2]] };
|
|
805
1125
|
}).filter((x) => x !== null);
|
|
@@ -823,11 +1143,16 @@ var RRuleTemporal = class {
|
|
|
823
1143
|
}
|
|
824
1144
|
}
|
|
825
1145
|
let finalDays = byDayHits;
|
|
826
|
-
if (
|
|
1146
|
+
if (byMonthDay && byMonthDay.length > 0) {
|
|
1147
|
+
if (byMonthDayHits.length === 0) {
|
|
1148
|
+
return [];
|
|
1149
|
+
}
|
|
827
1150
|
finalDays = finalDays.filter((d) => byMonthDayHits.includes(d));
|
|
828
1151
|
}
|
|
829
1152
|
const hits = finalDays.map((d) => sample.with({ day: d }));
|
|
830
|
-
|
|
1153
|
+
let expanded = hits.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1154
|
+
expanded = this.applyBySetPos(expanded);
|
|
1155
|
+
return expanded;
|
|
831
1156
|
}
|
|
832
1157
|
/**
|
|
833
1158
|
* Given any date in a year, return all ZonedDateTimes in that year matching
|
|
@@ -836,11 +1161,114 @@ var RRuleTemporal = class {
|
|
|
836
1161
|
*/
|
|
837
1162
|
generateYearlyOccurrences(sample) {
|
|
838
1163
|
const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : [this.originalDtstart.month];
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
1164
|
+
let occs = [];
|
|
1165
|
+
if (this.opts.byDay && this.opts.byDay.some((t) => /\d{2}/.test(t))) {
|
|
1166
|
+
const dayMap = {
|
|
1167
|
+
MO: 1,
|
|
1168
|
+
TU: 2,
|
|
1169
|
+
WE: 3,
|
|
1170
|
+
TH: 4,
|
|
1171
|
+
FR: 5,
|
|
1172
|
+
SA: 6,
|
|
1173
|
+
SU: 7
|
|
1174
|
+
};
|
|
1175
|
+
for (const tok of this.opts.byDay) {
|
|
1176
|
+
const m = tok.match(/^([+-]?\d{1,2})(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
1177
|
+
if (!m) continue;
|
|
1178
|
+
const ord = parseInt(m[1], 10);
|
|
1179
|
+
const wd = dayMap[m[2]];
|
|
1180
|
+
let dt;
|
|
1181
|
+
if (ord > 0) {
|
|
1182
|
+
const jan1 = sample.with({ month: 1, day: 1 });
|
|
1183
|
+
const delta = (wd - jan1.dayOfWeek + 7) % 7;
|
|
1184
|
+
dt = jan1.add({ days: delta + 7 * (ord - 1) });
|
|
1185
|
+
} else {
|
|
1186
|
+
const dec31 = sample.with({ month: 12, day: 31 });
|
|
1187
|
+
const delta = (dec31.dayOfWeek - wd + 7) % 7;
|
|
1188
|
+
dt = dec31.subtract({ days: delta + 7 * (-ord - 1) });
|
|
1189
|
+
}
|
|
1190
|
+
if (!this.opts.byMonth || this.opts.byMonth.includes(dt.month)) {
|
|
1191
|
+
occs.push(...this.expandByTime(dt));
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
} else if (!this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
1195
|
+
occs = months.flatMap((m) => {
|
|
1196
|
+
const monthSample = sample.with({ month: m, day: 1 });
|
|
1197
|
+
return this.generateMonthlyOccurrences(monthSample);
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
if (this.opts.byYearDay) {
|
|
1201
|
+
const last = sample.with({ month: 12, day: 31 }).dayOfYear;
|
|
1202
|
+
for (const d of this.opts.byYearDay) {
|
|
1203
|
+
const dayNum = d > 0 ? d : last + d + 1;
|
|
1204
|
+
const dt = sample.with({ month: 1, day: 1 }).add({ days: dayNum - 1 });
|
|
1205
|
+
if (!this.opts.byMonth || this.opts.byMonth.includes(dt.month)) {
|
|
1206
|
+
occs.push(...this.expandByTime(dt));
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (this.opts.byWeekNo) {
|
|
1211
|
+
const dayMap = {
|
|
1212
|
+
MO: 1,
|
|
1213
|
+
TU: 2,
|
|
1214
|
+
WE: 3,
|
|
1215
|
+
TH: 4,
|
|
1216
|
+
FR: 5,
|
|
1217
|
+
SA: 6,
|
|
1218
|
+
SU: 7
|
|
1219
|
+
};
|
|
1220
|
+
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
1221
|
+
const jan1 = sample.with({ month: 1, day: 1 });
|
|
1222
|
+
const delta = (jan1.dayOfWeek - wkst + 7) % 7;
|
|
1223
|
+
const firstWeekStart = jan1.subtract({ days: delta });
|
|
1224
|
+
const lastWeekDiff = sample.with({ month: 12, day: 31 }).toPlainDate().since(firstWeekStart.toPlainDate()).days;
|
|
1225
|
+
const lastWeek = Math.floor(lastWeekDiff / 7) + 1;
|
|
1226
|
+
const tokens = this.opts.byDay?.length ? this.opts.byDay.map((tok) => tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)?.[1]) : [this.opts.wkst || "MO"];
|
|
1227
|
+
for (const weekNo of this.opts.byWeekNo) {
|
|
1228
|
+
const weekIndex = weekNo > 0 ? weekNo - 1 : lastWeek + weekNo;
|
|
1229
|
+
const weekStart = firstWeekStart.add({ weeks: weekIndex });
|
|
1230
|
+
for (const tok of tokens) {
|
|
1231
|
+
if (!tok) continue;
|
|
1232
|
+
const targetDow = dayMap[tok];
|
|
1233
|
+
const inst = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
|
|
1234
|
+
if (!this.opts.byMonth || this.opts.byMonth.includes(inst.month)) {
|
|
1235
|
+
occs.push(...this.expandByTime(inst));
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
occs = occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1241
|
+
occs = this.applyBySetPos(occs);
|
|
1242
|
+
return occs;
|
|
1243
|
+
}
|
|
1244
|
+
applyBySetPos(list2) {
|
|
1245
|
+
const { bySetPos } = this.opts;
|
|
1246
|
+
if (!bySetPos || !bySetPos.length) return list2;
|
|
1247
|
+
const sorted = [...list2].sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1248
|
+
const out = [];
|
|
1249
|
+
const len = sorted.length;
|
|
1250
|
+
for (const pos of bySetPos) {
|
|
1251
|
+
const idx = pos > 0 ? pos - 1 : len + pos;
|
|
1252
|
+
if (idx >= 0 && idx < len) out.push(sorted[idx]);
|
|
1253
|
+
}
|
|
1254
|
+
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1255
|
+
}
|
|
1256
|
+
mergeRDates(list2, startInst, endInst, inc) {
|
|
1257
|
+
if (!this.opts.rDate) return this.excludeExDates(list2);
|
|
1258
|
+
for (const z of this.opts.rDate) {
|
|
1259
|
+
const inst = z.toInstant();
|
|
1260
|
+
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1261
|
+
const endOk = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1262
|
+
if (startOk && endOk) list2.push(z);
|
|
1263
|
+
}
|
|
1264
|
+
list2.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1265
|
+
const dedup = [];
|
|
1266
|
+
for (const d of list2) {
|
|
1267
|
+
if (dedup.length === 0 || import_polyfill.Temporal.ZonedDateTime.compare(d, dedup[dedup.length - 1]) !== 0) {
|
|
1268
|
+
dedup.push(d);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return this.excludeExDates(dedup);
|
|
844
1272
|
}
|
|
845
1273
|
};
|
|
846
1274
|
// Annotate the CommonJS export names for ESM import in node:
|