rrule-temporal 1.1.3 → 1.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/chunk-KT55S4C7.js +1590 -0
- package/dist/index.cjs +553 -358
- package/dist/index.d.cts +33 -9
- package/dist/index.d.ts +33 -9
- package/dist/index.js +1 -1
- package/dist/totext.cjs +553 -358
- package/dist/totext.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43,25 +43,18 @@ function unfoldLine(foldedLine) {
|
|
|
43
43
|
}
|
|
44
44
|
function parseIcsDateTime(dateStr, tzid, valueType) {
|
|
45
45
|
const isDate = valueType === "DATE" || !dateStr.includes("T");
|
|
46
|
+
const isoDate = `${dateStr.slice(0, 4)}-${dateStr.slice(4, 6)}-${dateStr.slice(6, 8)}`;
|
|
46
47
|
if (isDate) {
|
|
47
|
-
const isoDate = `${dateStr.slice(0, 4)}-${dateStr.slice(4, 6)}-${dateStr.slice(6, 8)}`;
|
|
48
48
|
return import_polyfill.Temporal.PlainDate.from(isoDate).toZonedDateTime({ timeZone: tzid });
|
|
49
49
|
}
|
|
50
|
-
if (
|
|
51
|
-
const iso = `${
|
|
50
|
+
if (dateStr.endsWith("Z")) {
|
|
51
|
+
const iso = `${isoDate}T${dateStr.slice(9, 15)}Z`;
|
|
52
52
|
return import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC");
|
|
53
53
|
} else {
|
|
54
|
-
const
|
|
55
|
-
return import_polyfill.Temporal.PlainDateTime.from(
|
|
54
|
+
const iso = `${isoDate}T${dateStr.slice(9)}`;
|
|
55
|
+
return import_polyfill.Temporal.PlainDateTime.from(iso).toZonedDateTime(tzid);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
function parseDateValues(dateValues, tzid, valueType) {
|
|
59
|
-
const dates = [];
|
|
60
|
-
for (const dateValue of dateValues) {
|
|
61
|
-
dates.push(parseIcsDateTime(dateValue, tzid, valueType));
|
|
62
|
-
}
|
|
63
|
-
return dates;
|
|
64
|
-
}
|
|
65
58
|
function parseDateLines(lines, linePrefix, defaultTzid) {
|
|
66
59
|
const dates = [];
|
|
67
60
|
const regex = new RegExp(`^${linePrefix}(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)`, "i");
|
|
@@ -71,11 +64,18 @@ function parseDateLines(lines, linePrefix, defaultTzid) {
|
|
|
71
64
|
const [, valueType, tzid, dateValuesStr] = match;
|
|
72
65
|
const timezone = tzid || defaultTzid;
|
|
73
66
|
const dateValues = dateValuesStr.split(",");
|
|
74
|
-
dates.push(...
|
|
67
|
+
dates.push(...dateValues.map((dateValue) => parseIcsDateTime(dateValue, timezone, valueType)));
|
|
75
68
|
}
|
|
76
69
|
}
|
|
77
70
|
return dates;
|
|
78
71
|
}
|
|
72
|
+
function parseNumberArray(val, sort = false) {
|
|
73
|
+
const arr = val.split(",").map((n) => parseInt(n, 10));
|
|
74
|
+
if (sort) {
|
|
75
|
+
return arr.sort((a, b) => a - b);
|
|
76
|
+
}
|
|
77
|
+
return arr;
|
|
78
|
+
}
|
|
79
79
|
function parseRRuleString(input, targetTimezone) {
|
|
80
80
|
var _a;
|
|
81
81
|
const unfoldedInput = unfoldLine(input).trim();
|
|
@@ -123,37 +123,37 @@ function parseRRuleString(input, targetTimezone) {
|
|
|
123
123
|
break;
|
|
124
124
|
case "UNTIL": {
|
|
125
125
|
opts.until = parseIcsDateTime(val, tzid || "UTC");
|
|
126
|
-
if (
|
|
126
|
+
if (!val.endsWith("Z") && tzid !== "UTC") {
|
|
127
127
|
throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
|
|
128
128
|
}
|
|
129
129
|
break;
|
|
130
130
|
}
|
|
131
131
|
case "BYHOUR":
|
|
132
|
-
opts.byHour = val
|
|
132
|
+
opts.byHour = parseNumberArray(val, true);
|
|
133
133
|
break;
|
|
134
134
|
case "BYMINUTE":
|
|
135
|
-
opts.byMinute = val
|
|
135
|
+
opts.byMinute = parseNumberArray(val, true);
|
|
136
|
+
break;
|
|
137
|
+
case "BYSECOND":
|
|
138
|
+
opts.bySecond = parseNumberArray(val, true);
|
|
136
139
|
break;
|
|
137
140
|
case "BYDAY":
|
|
138
141
|
opts.byDay = val.split(",");
|
|
139
142
|
break;
|
|
140
143
|
case "BYMONTH":
|
|
141
|
-
opts.byMonth = val
|
|
144
|
+
opts.byMonth = parseNumberArray(val);
|
|
142
145
|
break;
|
|
143
146
|
case "BYMONTHDAY":
|
|
144
|
-
opts.byMonthDay = val
|
|
145
|
-
break;
|
|
146
|
-
case "BYSECOND":
|
|
147
|
-
opts.bySecond = val.split(",").map((n) => parseInt(n, 10)).sort((a, b) => a - b);
|
|
147
|
+
opts.byMonthDay = parseNumberArray(val);
|
|
148
148
|
break;
|
|
149
149
|
case "BYYEARDAY":
|
|
150
|
-
opts.byYearDay = val
|
|
150
|
+
opts.byYearDay = parseNumberArray(val);
|
|
151
151
|
break;
|
|
152
152
|
case "BYWEEKNO":
|
|
153
|
-
opts.byWeekNo = val
|
|
153
|
+
opts.byWeekNo = parseNumberArray(val);
|
|
154
154
|
break;
|
|
155
155
|
case "BYSETPOS":
|
|
156
|
-
opts.bySetPos = val
|
|
156
|
+
opts.bySetPos = parseNumberArray(val);
|
|
157
157
|
break;
|
|
158
158
|
case "WKST":
|
|
159
159
|
opts.wkst = val;
|
|
@@ -198,12 +198,26 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
198
198
|
if (sanitized.length === 0) return void 0;
|
|
199
199
|
return sort ? sanitized.sort((a, b) => a - b) : sanitized;
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
sanitizeByDay(byDay) {
|
|
202
202
|
const validDay = /^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
const days = (byDay != null ? byDay : []).filter((day) => day && typeof day === "string");
|
|
204
|
+
for (const day of days) {
|
|
205
|
+
const match = day.match(validDay);
|
|
206
|
+
if (!match) {
|
|
207
|
+
throw new Error(`Invalid BYDAY value: ${day}`);
|
|
208
|
+
}
|
|
209
|
+
const ord = match[1];
|
|
210
|
+
if (ord) {
|
|
211
|
+
const ordInt = parseInt(ord, 10);
|
|
212
|
+
if (ordInt === 0) {
|
|
213
|
+
throw new Error(`Invalid BYDAY value: ${day}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
206
216
|
}
|
|
217
|
+
return days.length > 0 ? days : void 0;
|
|
218
|
+
}
|
|
219
|
+
sanitizeOpts(opts) {
|
|
220
|
+
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
207
221
|
opts.byMonth = this.sanitizeNumericArray(opts.byMonth, 1, 12, false, false);
|
|
208
222
|
opts.byMonthDay = this.sanitizeNumericArray(opts.byMonthDay, -31, 31, false, false);
|
|
209
223
|
opts.byYearDay = this.sanitizeNumericArray(opts.byYearDay, -366, 366, false, false);
|
|
@@ -291,37 +305,39 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
291
305
|
return this.applyTimeOverride(zdt.add({ days: 1 }));
|
|
292
306
|
}
|
|
293
307
|
if (freq === "SECONDLY") {
|
|
294
|
-
let
|
|
308
|
+
let candidate = zdt;
|
|
295
309
|
if (bySecond && bySecond.length > 0) {
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
} else {
|
|
300
|
-
next = zdt.add({ minutes: 1 }).with({ second: bySecond[0] });
|
|
310
|
+
const nextSecondInList = bySecond.find((s) => s > candidate.second);
|
|
311
|
+
if (nextSecondInList !== void 0) {
|
|
312
|
+
return candidate.with({ second: nextSecondInList });
|
|
301
313
|
}
|
|
314
|
+
candidate = candidate.with({ second: bySecond[0] }).add({ minutes: 1 });
|
|
315
|
+
} else {
|
|
316
|
+
candidate = candidate.add({ seconds: interval });
|
|
302
317
|
}
|
|
303
|
-
if (byMinute && byMinute.length > 0
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const nextHour = byHour ? byHour.find((h) => h > next.hour) : void 0;
|
|
309
|
-
if (nextHour !== void 0) {
|
|
310
|
-
next = next.with({ hour: nextHour, minute: byMinute[0], second: bySecond ? bySecond[0] : 0 });
|
|
311
|
-
} else {
|
|
312
|
-
next = this.applyTimeOverride(next.add({ days: 1 }));
|
|
318
|
+
if (byMinute && byMinute.length > 0) {
|
|
319
|
+
if (!byMinute.includes(candidate.minute) || candidate.minute === zdt.minute && candidate.second < zdt.second) {
|
|
320
|
+
const nextMinuteInList = byMinute.find((m) => m > candidate.minute);
|
|
321
|
+
if (nextMinuteInList !== void 0) {
|
|
322
|
+
return candidate.with({ minute: nextMinuteInList, second: bySecond ? bySecond[0] : 0 });
|
|
313
323
|
}
|
|
324
|
+
candidate = candidate.with({ minute: byMinute[0], second: bySecond ? bySecond[0] : 0 }).add({ hours: 1 });
|
|
314
325
|
}
|
|
315
326
|
}
|
|
316
|
-
if (byHour && byHour.length > 0
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
327
|
+
if (byHour && byHour.length > 0) {
|
|
328
|
+
if (!byHour.includes(candidate.hour) || candidate.hour === zdt.hour && candidate.minute < zdt.minute) {
|
|
329
|
+
const nextHourInList = byHour.find((h) => h > candidate.hour);
|
|
330
|
+
if (nextHourInList !== void 0) {
|
|
331
|
+
return candidate.with({
|
|
332
|
+
hour: nextHourInList,
|
|
333
|
+
minute: byMinute ? byMinute[0] : 0,
|
|
334
|
+
second: bySecond ? bySecond[0] : 0
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
candidate = candidate.with({ hour: byHour[0], minute: byMinute ? byMinute[0] : 0, second: bySecond ? bySecond[0] : 0 }).add({ days: 1 });
|
|
322
338
|
}
|
|
323
339
|
}
|
|
324
|
-
return
|
|
340
|
+
return candidate;
|
|
325
341
|
}
|
|
326
342
|
if (byMinute && byMinute.length > 1) {
|
|
327
343
|
const idx = byMinute.indexOf(zdt.minute);
|
|
@@ -458,7 +474,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
458
474
|
}
|
|
459
475
|
}
|
|
460
476
|
} else {
|
|
461
|
-
let deltas
|
|
477
|
+
let deltas;
|
|
462
478
|
if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && this.opts.byDay.every((tok) => /^[A-Z]{2}$/.test(tok))) {
|
|
463
479
|
deltas = this.opts.byDay.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
|
|
464
480
|
} else {
|
|
@@ -578,7 +594,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
578
594
|
return bySecond.includes(zdt.second);
|
|
579
595
|
}
|
|
580
596
|
matchesAll(zdt) {
|
|
581
|
-
return this.
|
|
597
|
+
return this.matchesByMonth(zdt) && this.matchesByWeekNo(zdt) && this.matchesByYearDay(zdt) && this.matchesByMonthDay(zdt) && this.matchesByDay(zdt) && this.matchesByHour(zdt) && this.matchesByMinute(zdt) && this.matchesBySecond(zdt);
|
|
582
598
|
}
|
|
583
599
|
matchesByYearDay(zdt) {
|
|
584
600
|
const { byYearDay } = this.opts;
|
|
@@ -601,11 +617,8 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
601
617
|
if (!byWeekNo) return true;
|
|
602
618
|
const { week, year } = this.getIsoWeekInfo(zdt);
|
|
603
619
|
const jan1 = zdt.with({ year, month: 1, day: 1 });
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
607
|
-
lastWeek = 53;
|
|
608
|
-
}
|
|
620
|
+
const isLeapYear = jan1.inLeapYear;
|
|
621
|
+
const lastWeek = jan1.dayOfWeek === 4 || isLeapYear && jan1.dayOfWeek === 3 ? 53 : 52;
|
|
609
622
|
return byWeekNo.some((wn) => {
|
|
610
623
|
if (wn > 0) {
|
|
611
624
|
return week === wn;
|
|
@@ -657,326 +670,448 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
657
670
|
* @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
|
|
658
671
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
|
|
659
672
|
*/
|
|
660
|
-
|
|
673
|
+
_allMonthlyByDayOrMonthDay(iterator) {
|
|
674
|
+
const dates = [];
|
|
675
|
+
let iterationCount = 0;
|
|
676
|
+
const start = this.originalDtstart;
|
|
677
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
678
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
679
|
+
}
|
|
680
|
+
let monthCursor = start.with({ day: 1 });
|
|
681
|
+
while (true) {
|
|
682
|
+
if (++iterationCount > this.maxIterations) {
|
|
683
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
684
|
+
}
|
|
685
|
+
let occs = this.generateMonthlyOccurrences(monthCursor);
|
|
686
|
+
occs = this.applyBySetPos(occs);
|
|
687
|
+
if (monthCursor.month === start.month && occs.some((o) => import_polyfill.Temporal.ZonedDateTime.compare(o, start) < 0) && occs.some((o) => import_polyfill.Temporal.ZonedDateTime.compare(o, start) === 0)) {
|
|
688
|
+
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
|
|
692
|
+
if (shouldBreak) {
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
696
|
+
}
|
|
697
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
698
|
+
}
|
|
699
|
+
_allWeekly(iterator) {
|
|
661
700
|
var _a;
|
|
662
|
-
|
|
663
|
-
|
|
701
|
+
const dates = [];
|
|
702
|
+
let iterationCount = 0;
|
|
703
|
+
const start = this.originalDtstart;
|
|
704
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
705
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
664
706
|
}
|
|
707
|
+
const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
708
|
+
const tokens = this.opts.byDay ? [...this.opts.byDay] : this.opts.byMonthDay && this.opts.byMonthDay.length > 0 ? Object.keys(dayMap) : [Object.entries(dayMap).find(([, d]) => d === start.dayOfWeek)[0]];
|
|
709
|
+
const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
710
|
+
const firstWeekDates = dows.map((dw) => {
|
|
711
|
+
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
712
|
+
return start.add({ days: delta });
|
|
713
|
+
});
|
|
714
|
+
const firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
715
|
+
const wkstDay = (_a = dayMap[this.opts.wkst || "MO"]) != null ? _a : 1;
|
|
716
|
+
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
717
|
+
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
718
|
+
while (true) {
|
|
719
|
+
if (++iterationCount > this.maxIterations) {
|
|
720
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
721
|
+
}
|
|
722
|
+
let occs = dows.flatMap((dw) => {
|
|
723
|
+
const delta = (dw - wkstDay + 7) % 7;
|
|
724
|
+
const sameDate = weekCursor.add({ days: delta });
|
|
725
|
+
return this.expandByTime(sameDate);
|
|
726
|
+
}).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
727
|
+
occs = this.applyBySetPos(occs);
|
|
728
|
+
const { shouldBreak } = this.processOccurrences(
|
|
729
|
+
occs,
|
|
730
|
+
dates,
|
|
731
|
+
start,
|
|
732
|
+
iterator,
|
|
733
|
+
(occ) => this.matchesByMonth(occ) && this.matchesByMonthDay(occ)
|
|
734
|
+
);
|
|
735
|
+
if (shouldBreak) {
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
739
|
+
}
|
|
740
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
741
|
+
}
|
|
742
|
+
_allMonthlyByMonth(iterator) {
|
|
665
743
|
const dates = [];
|
|
666
744
|
let iterationCount = 0;
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
745
|
+
const start = this.originalDtstart;
|
|
746
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
747
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
748
|
+
}
|
|
749
|
+
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
750
|
+
let monthOffset = 0;
|
|
751
|
+
let startMonthIndex = months.findIndex((m) => m >= start.month);
|
|
752
|
+
if (startMonthIndex === -1) {
|
|
753
|
+
startMonthIndex = 0;
|
|
754
|
+
monthOffset = 1;
|
|
755
|
+
}
|
|
756
|
+
while (true) {
|
|
757
|
+
if (++iterationCount > this.maxIterations) {
|
|
758
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
671
759
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
760
|
+
const monthIndex = startMonthIndex + monthOffset;
|
|
761
|
+
const targetMonth = months[monthIndex % months.length];
|
|
762
|
+
const yearsToAdd = Math.floor(monthIndex / months.length);
|
|
763
|
+
const candidate = start.with({
|
|
764
|
+
year: start.year + yearsToAdd,
|
|
765
|
+
month: targetMonth
|
|
766
|
+
});
|
|
767
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.until) > 0) {
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, start) >= 0) {
|
|
771
|
+
if (iterator && !iterator(candidate, dates.length)) {
|
|
772
|
+
break;
|
|
682
773
|
}
|
|
683
|
-
|
|
684
|
-
if (
|
|
774
|
+
dates.push(candidate);
|
|
775
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
685
776
|
break;
|
|
686
777
|
}
|
|
687
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
688
778
|
}
|
|
779
|
+
monthOffset++;
|
|
780
|
+
}
|
|
781
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
782
|
+
}
|
|
783
|
+
_allYearlyByMonth(iterator) {
|
|
784
|
+
const dates = [];
|
|
785
|
+
let iterationCount = 0;
|
|
786
|
+
const start = this.originalDtstart;
|
|
787
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
689
788
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
690
789
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
790
|
+
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
791
|
+
let yearOffset = 0;
|
|
792
|
+
while (true) {
|
|
793
|
+
if (++iterationCount > this.maxIterations) {
|
|
794
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
695
795
|
}
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
});
|
|
703
|
-
let firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
704
|
-
const wkstDay = (_a = dayMap[this.opts.wkst || "MO"]) != null ? _a : 1;
|
|
705
|
-
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
706
|
-
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
707
|
-
while (true) {
|
|
708
|
-
if (++iterationCount > this.maxIterations) {
|
|
709
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
796
|
+
const year = start.year + yearOffset * this.opts.interval;
|
|
797
|
+
for (const month of months) {
|
|
798
|
+
let occ = start.with({ year, month });
|
|
799
|
+
occ = this.applyTimeOverride(occ);
|
|
800
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) {
|
|
801
|
+
continue;
|
|
710
802
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
dates,
|
|
720
|
-
start,
|
|
721
|
-
iterator,
|
|
722
|
-
(occ) => this.matchesByMonth(occ) && this.matchesByMonthDay(occ)
|
|
723
|
-
);
|
|
724
|
-
if (shouldBreak) {
|
|
725
|
-
break;
|
|
803
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
804
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
805
|
+
}
|
|
806
|
+
if (iterator && !iterator(occ, dates.length)) {
|
|
807
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
808
|
+
}
|
|
809
|
+
dates.push(occ);
|
|
810
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
811
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
726
812
|
}
|
|
727
|
-
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
728
813
|
}
|
|
814
|
+
yearOffset++;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
_allYearlyComplex(iterator) {
|
|
818
|
+
const dates = [];
|
|
819
|
+
let iterationCount = 0;
|
|
820
|
+
const start = this.originalDtstart;
|
|
821
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
729
822
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
730
823
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
if (
|
|
734
|
-
|
|
824
|
+
let yearCursor = start.with({ month: 1, day: 1 });
|
|
825
|
+
while (true) {
|
|
826
|
+
if (++iterationCount > this.maxIterations) {
|
|
827
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
735
828
|
}
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (++iterationCount > this.maxIterations) {
|
|
745
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
829
|
+
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
830
|
+
const uniqueOccs = [];
|
|
831
|
+
if (occs.length > 0) {
|
|
832
|
+
uniqueOccs.push(occs[0]);
|
|
833
|
+
for (let i = 1; i < occs.length; i++) {
|
|
834
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occs[i], occs[i - 1]) !== 0) {
|
|
835
|
+
uniqueOccs.push(occs[i]);
|
|
836
|
+
}
|
|
746
837
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
838
|
+
}
|
|
839
|
+
const { shouldBreak } = this.processOccurrences(uniqueOccs, dates, start, iterator);
|
|
840
|
+
if (shouldBreak) {
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
const interval = this.opts.freq === "WEEKLY" ? 1 : this.opts.interval;
|
|
844
|
+
yearCursor = yearCursor.add({ years: interval });
|
|
845
|
+
if (this.opts.freq === "WEEKLY" && this.opts.until && yearCursor.year > this.opts.until.year) {
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
850
|
+
}
|
|
851
|
+
_allMinutelySecondlyComplex(iterator) {
|
|
852
|
+
const dates = [];
|
|
853
|
+
let iterationCount = 0;
|
|
854
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
855
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
856
|
+
}
|
|
857
|
+
let current = this.computeFirst();
|
|
858
|
+
while (true) {
|
|
859
|
+
if (++iterationCount > this.maxIterations) {
|
|
860
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
861
|
+
}
|
|
862
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
if (this.matchesAll(current)) {
|
|
866
|
+
if (iterator && !iterator(current, dates.length)) {
|
|
755
867
|
break;
|
|
756
868
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
dates.push(candidate);
|
|
762
|
-
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
869
|
+
dates.push(current);
|
|
870
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
871
|
+
break;
|
|
765
872
|
}
|
|
766
|
-
|
|
873
|
+
current = this.nextCandidateSameDate(current);
|
|
874
|
+
} else {
|
|
875
|
+
current = this.findNextValidDate(current);
|
|
767
876
|
}
|
|
877
|
+
}
|
|
878
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
879
|
+
}
|
|
880
|
+
_allMonthlyByWeekNo(iterator) {
|
|
881
|
+
const dates = [];
|
|
882
|
+
let iterationCount = 0;
|
|
883
|
+
const start = this.originalDtstart;
|
|
884
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
768
885
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
769
886
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
887
|
+
let current = start;
|
|
888
|
+
const weekNos = [...this.opts.byWeekNo].sort((a, b) => a - b);
|
|
889
|
+
const interval = this.opts.interval;
|
|
890
|
+
let monthsAdvanced = 0;
|
|
891
|
+
let lastYearProcessed = -1;
|
|
892
|
+
outer_loop: while (true) {
|
|
893
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
894
|
+
break;
|
|
774
895
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
896
|
+
if (++iterationCount > this.maxIterations) {
|
|
897
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
898
|
+
}
|
|
899
|
+
const year = current.year;
|
|
900
|
+
if (year !== lastYearProcessed && current.month >= start.month) {
|
|
901
|
+
lastYearProcessed = year;
|
|
902
|
+
for (const weekNo of weekNos) {
|
|
903
|
+
const occs = this.generateOccurrencesForWeekInYear(year, weekNo);
|
|
904
|
+
for (const occ of occs) {
|
|
905
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) >= 0) {
|
|
906
|
+
if (iterator && !iterator(occ, dates.length)) {
|
|
907
|
+
break outer_loop;
|
|
908
|
+
}
|
|
909
|
+
dates.push(occ);
|
|
910
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
911
|
+
break outer_loop;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
780
915
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
916
|
+
}
|
|
917
|
+
monthsAdvanced += interval;
|
|
918
|
+
current = start.add({ months: monthsAdvanced });
|
|
919
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
924
|
+
}
|
|
925
|
+
_allMonthlyByYearDay(iterator) {
|
|
926
|
+
const dates = [];
|
|
927
|
+
let iterationCount = 0;
|
|
928
|
+
const start = this.originalDtstart;
|
|
929
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
930
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
931
|
+
}
|
|
932
|
+
let year = start.year;
|
|
933
|
+
const yearDays = [...this.opts.byYearDay].sort((a, b) => a - b);
|
|
934
|
+
const interval = this.opts.interval;
|
|
935
|
+
const startMonthAbs = start.year * 12 + start.month;
|
|
936
|
+
outer_loop: while (true) {
|
|
937
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
if (++iterationCount > this.maxIterations) {
|
|
941
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
942
|
+
}
|
|
943
|
+
const yearStart = start.with({ year, month: 1, day: 1 });
|
|
944
|
+
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
945
|
+
for (const yd of yearDays) {
|
|
946
|
+
const dayNum = yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
947
|
+
if (dayNum <= 0 || dayNum > lastDayOfYear) continue;
|
|
948
|
+
const baseOcc = yearStart.add({ days: dayNum - 1 });
|
|
949
|
+
for (const occ of this.expandByTime(baseOcc)) {
|
|
950
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
951
|
+
if (dates.some((d) => import_polyfill.Temporal.ZonedDateTime.compare(d, occ) === 0)) continue;
|
|
952
|
+
const occMonthAbs = occ.year * 12 + occ.month;
|
|
953
|
+
if ((occMonthAbs - startMonthAbs) % interval !== 0) {
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
if (!this.matchesByMonth(occ)) {
|
|
786
957
|
continue;
|
|
787
958
|
}
|
|
788
959
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
789
|
-
|
|
960
|
+
break outer_loop;
|
|
790
961
|
}
|
|
791
962
|
if (iterator && !iterator(occ, dates.length)) {
|
|
792
|
-
|
|
963
|
+
break outer_loop;
|
|
793
964
|
}
|
|
794
965
|
dates.push(occ);
|
|
795
966
|
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
796
|
-
|
|
967
|
+
break outer_loop;
|
|
797
968
|
}
|
|
798
969
|
}
|
|
799
|
-
yearOffset++;
|
|
800
970
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
const start = this.originalDtstart;
|
|
805
|
-
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
806
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
971
|
+
year++;
|
|
972
|
+
if (this.opts.until && year > this.opts.until.year + 2) {
|
|
973
|
+
break;
|
|
807
974
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
if (
|
|
811
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
812
|
-
}
|
|
813
|
-
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
814
|
-
const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
|
|
815
|
-
if (shouldBreak) {
|
|
816
|
-
break;
|
|
817
|
-
}
|
|
818
|
-
const interval = this.opts.freq === "WEEKLY" ? 1 : this.opts.interval;
|
|
819
|
-
yearCursor = yearCursor.add({ years: interval });
|
|
820
|
-
if (this.opts.freq === "WEEKLY" && this.opts.until && yearCursor.year > this.opts.until.year) {
|
|
975
|
+
if (!this.opts.until && this.opts.count) {
|
|
976
|
+
const yearsToScan = Math.ceil(this.opts.count / (this.opts.byYearDay.length || 1)) * interval + 5;
|
|
977
|
+
if (year > start.year + yearsToScan) {
|
|
821
978
|
break;
|
|
822
979
|
}
|
|
823
980
|
}
|
|
981
|
+
}
|
|
982
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
983
|
+
}
|
|
984
|
+
_allDailyMinutelyHourlyWithBySetPos(iterator) {
|
|
985
|
+
const dates = [];
|
|
986
|
+
let iterationCount = 0;
|
|
987
|
+
const start = this.originalDtstart;
|
|
988
|
+
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
824
989
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
825
990
|
}
|
|
826
|
-
|
|
827
|
-
|
|
991
|
+
let cursor;
|
|
992
|
+
let duration;
|
|
993
|
+
switch (this.opts.freq) {
|
|
994
|
+
case "MINUTELY":
|
|
995
|
+
cursor = start.with({ second: 0, microsecond: 0, nanosecond: 0 });
|
|
996
|
+
duration = { minutes: this.opts.interval };
|
|
997
|
+
break;
|
|
998
|
+
case "HOURLY":
|
|
999
|
+
cursor = start.with({ minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
1000
|
+
duration = { hours: this.opts.interval };
|
|
1001
|
+
break;
|
|
1002
|
+
case "DAILY":
|
|
1003
|
+
cursor = start.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
1004
|
+
duration = { days: this.opts.interval };
|
|
1005
|
+
break;
|
|
1006
|
+
default:
|
|
828
1007
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
1008
|
+
}
|
|
1009
|
+
while (true) {
|
|
1010
|
+
if (++iterationCount > this.maxIterations) {
|
|
1011
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
829
1012
|
}
|
|
830
|
-
let
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
break;
|
|
841
|
-
}
|
|
842
|
-
dates.push(current);
|
|
843
|
-
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
844
|
-
break;
|
|
845
|
-
}
|
|
846
|
-
current = this.nextCandidateSameDate(current);
|
|
847
|
-
} else {
|
|
848
|
-
current = this.findNextValidDate(current);
|
|
849
|
-
}
|
|
1013
|
+
let periodOccs = this.expandByTime(cursor);
|
|
1014
|
+
periodOccs = periodOccs.filter((occ) => this.matchesAll(occ));
|
|
1015
|
+
periodOccs = this.applyBySetPos(periodOccs);
|
|
1016
|
+
const { shouldBreak } = this.processOccurrences(periodOccs, dates, start, iterator);
|
|
1017
|
+
if (shouldBreak) {
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
cursor = cursor.add(duration);
|
|
1021
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(cursor, this.opts.until) > 0) {
|
|
1022
|
+
break;
|
|
850
1023
|
}
|
|
851
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
852
1024
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1025
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
1026
|
+
}
|
|
1027
|
+
_allFallback(iterator) {
|
|
1028
|
+
const dates = [];
|
|
1029
|
+
let iterationCount = 0;
|
|
1030
|
+
let current = this.computeFirst();
|
|
1031
|
+
if (this.includeDtstart && import_polyfill.Temporal.ZonedDateTime.compare(current, this.originalDtstart) > 0) {
|
|
1032
|
+
if (iterator && !iterator(this.originalDtstart, dates.length)) {
|
|
856
1033
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
857
1034
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const startMonthAbs = start.year * 12 + start.month;
|
|
862
|
-
outer_loop: while (true) {
|
|
863
|
-
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
if (++iterationCount > this.maxIterations) {
|
|
867
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
868
|
-
}
|
|
869
|
-
const yearStart = start.with({ year, month: 1, day: 1 });
|
|
870
|
-
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
871
|
-
for (const yd of yearDays) {
|
|
872
|
-
const dayNum = yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
873
|
-
if (dayNum <= 0 || dayNum > lastDayOfYear) continue;
|
|
874
|
-
const baseOcc = yearStart.add({ days: dayNum - 1 });
|
|
875
|
-
for (const occ of this.expandByTime(baseOcc)) {
|
|
876
|
-
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
877
|
-
if (dates.some((d) => import_polyfill.Temporal.ZonedDateTime.compare(d, occ) === 0)) continue;
|
|
878
|
-
const occMonthAbs = occ.year * 12 + occ.month;
|
|
879
|
-
if ((occMonthAbs - startMonthAbs) % interval !== 0) {
|
|
880
|
-
continue;
|
|
881
|
-
}
|
|
882
|
-
if (!this.matchesByMonth(occ)) {
|
|
883
|
-
continue;
|
|
884
|
-
}
|
|
885
|
-
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
886
|
-
break outer_loop;
|
|
887
|
-
}
|
|
888
|
-
if (iterator && !iterator(occ, dates.length)) {
|
|
889
|
-
break outer_loop;
|
|
890
|
-
}
|
|
891
|
-
dates.push(occ);
|
|
892
|
-
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
893
|
-
break outer_loop;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
year++;
|
|
898
|
-
if (this.opts.until && year > this.opts.until.year + 2) {
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
if (!this.opts.until && this.opts.count) {
|
|
902
|
-
const yearsToScan = Math.ceil(this.opts.count / (this.opts.byYearDay.length || 1)) * interval + 5;
|
|
903
|
-
if (year > start.year + yearsToScan) {
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
1035
|
+
dates.push(this.originalDtstart);
|
|
1036
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1037
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
907
1038
|
}
|
|
908
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
909
1039
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
1040
|
+
while (true) {
|
|
1041
|
+
if (++iterationCount > this.maxIterations) {
|
|
1042
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
914
1043
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
switch (this.opts.freq) {
|
|
918
|
-
case "MINUTELY":
|
|
919
|
-
cursor = start.with({ second: 0, microsecond: 0, nanosecond: 0 });
|
|
920
|
-
duration = { minutes: this.opts.interval };
|
|
921
|
-
break;
|
|
922
|
-
case "HOURLY":
|
|
923
|
-
cursor = start.with({ minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
924
|
-
duration = { hours: this.opts.interval };
|
|
925
|
-
break;
|
|
926
|
-
case "DAILY":
|
|
927
|
-
cursor = start.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
928
|
-
duration = { days: this.opts.interval };
|
|
929
|
-
break;
|
|
930
|
-
default:
|
|
931
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
1044
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
1045
|
+
break;
|
|
932
1046
|
}
|
|
933
|
-
|
|
934
|
-
if (
|
|
935
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
936
|
-
}
|
|
937
|
-
let periodOccs = this.expandByTime(cursor);
|
|
938
|
-
periodOccs = periodOccs.filter((occ) => this.matchesAll(occ));
|
|
939
|
-
periodOccs = this.applyBySetPos(periodOccs);
|
|
940
|
-
const { shouldBreak } = this.processOccurrences(periodOccs, dates, start, iterator);
|
|
941
|
-
if (shouldBreak) {
|
|
1047
|
+
if (this.matchesAll(current)) {
|
|
1048
|
+
if (iterator && !iterator(current, dates.length)) {
|
|
942
1049
|
break;
|
|
943
1050
|
}
|
|
944
|
-
|
|
945
|
-
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(cursor, this.opts.until) > 0) {
|
|
946
|
-
break;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
} else {
|
|
950
|
-
let current = this.computeFirst();
|
|
951
|
-
if (this.includeDtstart && import_polyfill.Temporal.ZonedDateTime.compare(current, this.originalDtstart) > 0) {
|
|
952
|
-
if (iterator && !iterator(this.originalDtstart, dates.length)) {
|
|
953
|
-
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
954
|
-
}
|
|
955
|
-
dates.push(this.originalDtstart);
|
|
1051
|
+
dates.push(current);
|
|
956
1052
|
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
957
|
-
|
|
1053
|
+
break;
|
|
958
1054
|
}
|
|
959
1055
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1056
|
+
current = this.nextCandidateSameDate(current);
|
|
1057
|
+
}
|
|
1058
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Returns all occurrences of the rule.
|
|
1062
|
+
* @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
|
|
1063
|
+
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
|
|
1064
|
+
*/
|
|
1065
|
+
all(iterator) {
|
|
1066
|
+
if (this.opts.byWeekNo && this.opts.byYearDay) {
|
|
1067
|
+
const yearStart = this.originalDtstart.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
1068
|
+
const yearDays = this.opts.byYearDay.map((yd) => {
|
|
1069
|
+
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
1070
|
+
return yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
1071
|
+
});
|
|
1072
|
+
let possibleDate = false;
|
|
1073
|
+
for (const yd of yearDays) {
|
|
1074
|
+
const date = yearStart.add({ days: yd - 1 });
|
|
1075
|
+
if (this.matchesByWeekNo(date)) {
|
|
1076
|
+
possibleDate = true;
|
|
965
1077
|
break;
|
|
966
1078
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
}
|
|
971
|
-
dates.push(current);
|
|
972
|
-
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
current = this.nextCandidateSameDate(current);
|
|
1079
|
+
}
|
|
1080
|
+
if (!possibleDate) {
|
|
1081
|
+
return [];
|
|
977
1082
|
}
|
|
978
1083
|
}
|
|
979
|
-
|
|
1084
|
+
if (!this.opts.count && !this.opts.until && !iterator) {
|
|
1085
|
+
throw new Error("all() requires iterator when no COUNT/UNTIL");
|
|
1086
|
+
}
|
|
1087
|
+
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay) && !this.opts.byWeekNo) {
|
|
1088
|
+
return this._allMonthlyByDayOrMonthDay(iterator);
|
|
1089
|
+
}
|
|
1090
|
+
if (this.opts.freq === "WEEKLY" && !(this.opts.byYearDay && this.opts.byYearDay.length > 0) && !(this.opts.byWeekNo && this.opts.byWeekNo.length > 0)) {
|
|
1091
|
+
return this._allWeekly(iterator);
|
|
1092
|
+
}
|
|
1093
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay) {
|
|
1094
|
+
return this._allMonthlyByMonth(iterator);
|
|
1095
|
+
}
|
|
1096
|
+
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
1097
|
+
return this._allYearlyByMonth(iterator);
|
|
1098
|
+
}
|
|
1099
|
+
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay || this.opts.byYearDay || this.opts.byWeekNo) || this.opts.freq === "WEEKLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 || this.opts.freq === "WEEKLY" && this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
|
|
1100
|
+
return this._allYearlyComplex(iterator);
|
|
1101
|
+
}
|
|
1102
|
+
if ((this.opts.freq === "MINUTELY" || this.opts.freq === "SECONDLY") && (this.opts.byMonth || this.opts.byWeekNo || this.opts.byYearDay || this.opts.byMonthDay || this.opts.byDay)) {
|
|
1103
|
+
return this._allMinutelySecondlyComplex(iterator);
|
|
1104
|
+
}
|
|
1105
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
|
|
1106
|
+
return this._allMonthlyByWeekNo(iterator);
|
|
1107
|
+
}
|
|
1108
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
1109
|
+
return this._allMonthlyByYearDay(iterator);
|
|
1110
|
+
}
|
|
1111
|
+
if ((this.opts.freq === "MINUTELY" || this.opts.freq === "HOURLY" || this.opts.freq === "DAILY") && this.opts.bySetPos) {
|
|
1112
|
+
return this._allDailyMinutelyHourlyWithBySetPos(iterator);
|
|
1113
|
+
}
|
|
1114
|
+
return this._allFallback(iterator);
|
|
980
1115
|
}
|
|
981
1116
|
/**
|
|
982
1117
|
* Converts rDate entries to ZonedDateTime and merges with existing dates.
|
|
@@ -984,8 +1119,9 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
984
1119
|
* @returns Merged and deduplicated array of dates
|
|
985
1120
|
*/
|
|
986
1121
|
mergeAndDeduplicateRDates(dates) {
|
|
987
|
-
if (
|
|
988
|
-
|
|
1122
|
+
if (this.opts.rDate) {
|
|
1123
|
+
dates.push(...this.opts.rDate);
|
|
1124
|
+
}
|
|
989
1125
|
dates.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
990
1126
|
const dedup = [];
|
|
991
1127
|
for (const d of dates) {
|
|
@@ -1223,8 +1359,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1223
1359
|
* if BYMONTH is not specified.
|
|
1224
1360
|
*/
|
|
1225
1361
|
generateYearlyOccurrences(sample) {
|
|
1226
|
-
|
|
1227
|
-
const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : this.opts.byMonthDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [this.originalDtstart.month];
|
|
1362
|
+
const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : this.opts.byMonthDay || this.opts.byDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [this.originalDtstart.month];
|
|
1228
1363
|
let occs = [];
|
|
1229
1364
|
const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
|
|
1230
1365
|
if (hasOrdinalByDay && !this.opts.byMonth) {
|
|
@@ -1256,6 +1391,7 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1256
1391
|
const last = sample.with({ month: 12, day: 31 }).dayOfYear;
|
|
1257
1392
|
for (const d of this.opts.byYearDay) {
|
|
1258
1393
|
const dayNum = d > 0 ? d : last + d + 1;
|
|
1394
|
+
if (dayNum <= 0 || dayNum > last) continue;
|
|
1259
1395
|
const dt = this.opts.freq === "MINUTELY" ? sample.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }).add({ days: dayNum - 1 }) : sample.with({ month: 1, day: 1 }).add({ days: dayNum - 1 });
|
|
1260
1396
|
if (!this.opts.byMonth || this.opts.byMonth.includes(dt.month)) {
|
|
1261
1397
|
occs.push(...this.expandByTime(dt));
|
|
@@ -1263,34 +1399,34 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1263
1399
|
}
|
|
1264
1400
|
}
|
|
1265
1401
|
if (this.opts.byWeekNo) {
|
|
1266
|
-
const
|
|
1267
|
-
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
1268
|
-
const jan1 = sample.with({ month: 1, day: 1 });
|
|
1269
|
-
const delta = (jan1.dayOfWeek - wkst + 7) % 7;
|
|
1270
|
-
const firstWeekStart = jan1.subtract({ days: delta });
|
|
1271
|
-
const isLeapYear = jan1.inLeapYear;
|
|
1272
|
-
const lastWeek = jan1.dayOfWeek === 4 || isLeapYear && jan1.dayOfWeek === 3 ? 53 : 52;
|
|
1273
|
-
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => {
|
|
1274
|
-
var _a2;
|
|
1275
|
-
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
1276
|
-
}) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
1402
|
+
const { lastWeek, firstWeekStart, tokens } = this.isoWeekByDay(sample);
|
|
1277
1403
|
for (const weekNo of this.opts.byWeekNo) {
|
|
1404
|
+
if (weekNo > 0 && weekNo > lastWeek || weekNo < 0 && -weekNo > lastWeek) {
|
|
1405
|
+
continue;
|
|
1406
|
+
}
|
|
1278
1407
|
const weekIndex = weekNo > 0 ? weekNo - 1 : lastWeek + weekNo;
|
|
1279
1408
|
const weekStart = firstWeekStart.add({ weeks: weekIndex });
|
|
1280
|
-
|
|
1281
|
-
if (!tok) continue;
|
|
1282
|
-
const targetDow = dayMap[tok];
|
|
1283
|
-
const inst = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
|
|
1284
|
-
if (!this.opts.byMonth || this.opts.byMonth.includes(inst.month)) {
|
|
1285
|
-
occs.push(...this.expandByTime(inst));
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1409
|
+
occs.push(...this.addByDay(tokens, weekStart));
|
|
1288
1410
|
}
|
|
1289
1411
|
}
|
|
1290
1412
|
occs = occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1291
1413
|
occs = this.applyBySetPos(occs);
|
|
1292
1414
|
return occs;
|
|
1293
1415
|
}
|
|
1416
|
+
addByDay(tokens, weekStart) {
|
|
1417
|
+
const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
1418
|
+
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
1419
|
+
const entries = [];
|
|
1420
|
+
for (const tok of tokens) {
|
|
1421
|
+
if (!tok) continue;
|
|
1422
|
+
const targetDow = dayMap[tok];
|
|
1423
|
+
const inst = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
|
|
1424
|
+
if (!this.opts.byMonth || this.opts.byMonth.includes(inst.month)) {
|
|
1425
|
+
entries.push(...this.expandByTime(inst));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
return entries;
|
|
1429
|
+
}
|
|
1294
1430
|
/**
|
|
1295
1431
|
* Helper to find the next valid value from a sorted array
|
|
1296
1432
|
*/
|
|
@@ -1302,6 +1438,19 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1302
1438
|
* large gaps when BYXXX constraints don't match.
|
|
1303
1439
|
*/
|
|
1304
1440
|
findNextValidDate(current) {
|
|
1441
|
+
if (this.opts.byWeekNo && this.opts.byYearDay) {
|
|
1442
|
+
const yearStart = current.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
1443
|
+
const yearDays = this.opts.byYearDay.map((yd) => {
|
|
1444
|
+
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
1445
|
+
return yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
1446
|
+
});
|
|
1447
|
+
for (const yd of yearDays) {
|
|
1448
|
+
const date = yearStart.add({ days: yd - 1 });
|
|
1449
|
+
if (this.matchesByWeekNo(date)) {
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1305
1454
|
if (this.opts.byMonth && !this.opts.byMonth.includes(current.month)) {
|
|
1306
1455
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
1307
1456
|
const nextMonth = this.findNextValidValue(current.month, months, (a, b) => a - b);
|
|
@@ -1313,6 +1462,11 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1313
1462
|
current = this.applyTimeOverride(current);
|
|
1314
1463
|
return current;
|
|
1315
1464
|
}
|
|
1465
|
+
if (this.opts.byWeekNo && !this.matchesByWeekNo(current)) {
|
|
1466
|
+
current = current.add({ weeks: 1 }).with({ hour: 0, minute: 0, second: 0 });
|
|
1467
|
+
current = this.applyTimeOverride(current);
|
|
1468
|
+
return current;
|
|
1469
|
+
}
|
|
1316
1470
|
if (this.opts.byYearDay && !this.matchesByYearDay(current)) {
|
|
1317
1471
|
const yearDays = [...this.opts.byYearDay].sort((a, b) => a - b);
|
|
1318
1472
|
const currentYearDay = current.dayOfYear;
|
|
@@ -1344,11 +1498,6 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1344
1498
|
current = this.applyTimeOverride(current);
|
|
1345
1499
|
return current;
|
|
1346
1500
|
}
|
|
1347
|
-
if (this.opts.byWeekNo && !this.matchesByWeekNo(current)) {
|
|
1348
|
-
current = current.add({ weeks: 1 }).with({ hour: 0, minute: 0, second: 0 });
|
|
1349
|
-
current = this.applyTimeOverride(current);
|
|
1350
|
-
return current;
|
|
1351
|
-
}
|
|
1352
1501
|
if (this.opts.byMonthDay && !this.matchesByMonthDay(current)) {
|
|
1353
1502
|
const monthDays = [...this.opts.byMonthDay].sort((a, b) => a - b);
|
|
1354
1503
|
const lastDayOfMonth = current.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
|
|
@@ -1369,6 +1518,8 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1369
1518
|
minute: 0,
|
|
1370
1519
|
second: 0
|
|
1371
1520
|
});
|
|
1521
|
+
} else {
|
|
1522
|
+
current = current.add({ months: 1 }).with({ day: 1, hour: 0, minute: 0, second: 0 });
|
|
1372
1523
|
}
|
|
1373
1524
|
}
|
|
1374
1525
|
current = this.applyTimeOverride(current);
|
|
@@ -1376,26 +1527,39 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1376
1527
|
}
|
|
1377
1528
|
if (this.opts.byDay && !this.matchesByDay(current)) {
|
|
1378
1529
|
const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
1379
|
-
const
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
if (nextDow <= 7) {
|
|
1391
|
-
current = current.add({ days: nextDow - currentDow }).with({ hour: 0, minute: 0, second: 0 });
|
|
1530
|
+
const targetDays = this.opts.byDay.map((tok) => {
|
|
1531
|
+
var _a;
|
|
1532
|
+
return (_a = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
|
|
1533
|
+
}).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
|
|
1534
|
+
const nextDayOfWeek = this.findNextValidValue(current.dayOfWeek, targetDays.sort(), (a, b) => a - b);
|
|
1535
|
+
if (nextDayOfWeek) {
|
|
1536
|
+
const delta = (nextDayOfWeek - current.dayOfWeek + 7) % 7;
|
|
1537
|
+
current = current.add({ days: delta }).with({ hour: 0, minute: 0, second: 0 });
|
|
1392
1538
|
} else {
|
|
1393
|
-
|
|
1539
|
+
const delta = (targetDays[0] - current.dayOfWeek + 7) % 7;
|
|
1540
|
+
current = current.add({ days: delta + 7 }).with({ hour: 0, minute: 0, second: 0 });
|
|
1394
1541
|
}
|
|
1395
1542
|
current = this.applyTimeOverride(current);
|
|
1396
1543
|
return current;
|
|
1397
1544
|
}
|
|
1398
|
-
|
|
1545
|
+
switch (this.opts.freq) {
|
|
1546
|
+
case "SECONDLY":
|
|
1547
|
+
case "MINUTELY":
|
|
1548
|
+
current = current.add({ days: 1 }).with({ hour: 0, minute: 0, second: 0 });
|
|
1549
|
+
break;
|
|
1550
|
+
case "HOURLY":
|
|
1551
|
+
current = current.add({ days: 1 }).with({ hour: 0, minute: 0, second: 0 });
|
|
1552
|
+
break;
|
|
1553
|
+
case "DAILY":
|
|
1554
|
+
case "WEEKLY":
|
|
1555
|
+
current = current.add({ months: 1 }).with({ day: 1, hour: 0, minute: 0, second: 0 });
|
|
1556
|
+
break;
|
|
1557
|
+
case "MONTHLY":
|
|
1558
|
+
case "YEARLY":
|
|
1559
|
+
current = current.add({ years: 1 }).with({ month: 1, day: 1, hour: 0, minute: 0, second: 0 });
|
|
1560
|
+
break;
|
|
1561
|
+
}
|
|
1562
|
+
return this.applyTimeOverride(current);
|
|
1399
1563
|
}
|
|
1400
1564
|
applyBySetPos(list) {
|
|
1401
1565
|
const { bySetPos } = this.opts;
|
|
@@ -1409,6 +1573,37 @@ var RRuleTemporal = class _RRuleTemporal {
|
|
|
1409
1573
|
}
|
|
1410
1574
|
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1411
1575
|
}
|
|
1576
|
+
isoWeekByDay(sample) {
|
|
1577
|
+
var _a;
|
|
1578
|
+
const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
1579
|
+
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
1580
|
+
const jan1 = sample.with({ month: 1, day: 1 });
|
|
1581
|
+
const jan4 = sample.with({ month: 1, day: 4 });
|
|
1582
|
+
const delta = (jan4.dayOfWeek - wkst + 7) % 7;
|
|
1583
|
+
const firstWeekStart = jan4.subtract({ days: delta });
|
|
1584
|
+
const isLeapYear = jan1.inLeapYear;
|
|
1585
|
+
const lastWeek = jan1.dayOfWeek === 4 || isLeapYear && jan1.dayOfWeek === 3 ? 53 : 52;
|
|
1586
|
+
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => {
|
|
1587
|
+
var _a2;
|
|
1588
|
+
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
1589
|
+
}) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
1590
|
+
return { lastWeek, firstWeekStart, tokens };
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Generate occurrences for a specific week number in a given year
|
|
1594
|
+
*/
|
|
1595
|
+
generateOccurrencesForWeekInYear(year, weekNo) {
|
|
1596
|
+
const occs = [];
|
|
1597
|
+
const sample = this.originalDtstart.with({ year, month: 1, day: 1 });
|
|
1598
|
+
const { lastWeek, firstWeekStart, tokens } = this.isoWeekByDay(sample);
|
|
1599
|
+
if (weekNo > 0 && weekNo > lastWeek || weekNo < 0 && -weekNo > lastWeek) {
|
|
1600
|
+
return occs;
|
|
1601
|
+
}
|
|
1602
|
+
const weekIndex = weekNo > 0 ? weekNo - 1 : lastWeek + weekNo;
|
|
1603
|
+
const weekStart = firstWeekStart.add({ weeks: weekIndex });
|
|
1604
|
+
occs.push(...this.addByDay(tokens, weekStart));
|
|
1605
|
+
return occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1606
|
+
}
|
|
1412
1607
|
};
|
|
1413
1608
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1414
1609
|
0 && (module.exports = {
|