rrule-temporal 1.1.0 → 1.1.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/README.md +2 -1
- package/dist/chunk-6A2XASAM.js +1335 -0
- package/dist/index.cjs +374 -291
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/totext.cjs +417 -358
- package/dist/totext.js +43 -67
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -41,52 +41,61 @@ var import_polyfill = require("@js-temporal/polyfill");
|
|
|
41
41
|
function unfoldLine(foldedLine) {
|
|
42
42
|
return foldedLine.replace(/\r?\n[ \t]/g, "");
|
|
43
43
|
}
|
|
44
|
-
function parseDateValues(dateValues, tzid) {
|
|
44
|
+
function parseDateValues(dateValues, tzid, valueType) {
|
|
45
45
|
const dates = [];
|
|
46
46
|
for (const dateValue of dateValues) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const isDate = valueType === "DATE" || !dateValue.includes("T");
|
|
48
|
+
if (isDate) {
|
|
49
|
+
const isoDate = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}`;
|
|
50
|
+
dates.push(import_polyfill.Temporal.PlainDate.from(isoDate).toZonedDateTime({ timeZone: tzid }));
|
|
50
51
|
} else {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
if (/Z$/.test(dateValue)) {
|
|
53
|
+
const iso = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9, 15)}Z`;
|
|
54
|
+
dates.push(import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC"));
|
|
55
|
+
} else {
|
|
56
|
+
const isoDate = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9)}`;
|
|
57
|
+
dates.push(import_polyfill.Temporal.PlainDateTime.from(isoDate).toZonedDateTime(tzid));
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
return dates;
|
|
56
62
|
}
|
|
57
63
|
function parseRRuleString(input, targetTimezone) {
|
|
58
|
-
var _a
|
|
64
|
+
var _a;
|
|
59
65
|
const unfoldedInput = unfoldLine(input).trim();
|
|
60
66
|
let dtstart;
|
|
61
67
|
let tzid = "UTC";
|
|
62
68
|
let rruleLine;
|
|
63
69
|
let exDate = [];
|
|
64
70
|
let rDate = [];
|
|
65
|
-
if (/^DTSTART/
|
|
71
|
+
if (/^DTSTART/im.test(unfoldedInput)) {
|
|
66
72
|
const lines = unfoldedInput.split(/\s+/);
|
|
67
|
-
const dtLine = lines
|
|
73
|
+
const dtLine = lines.find((line) => line.match(/^DTSTART/i));
|
|
68
74
|
const rrLine = lines.find((line) => line.match(/^RRULE:/i));
|
|
69
75
|
const exLines = lines.filter((line) => line.match(/^EXDATE/i));
|
|
70
76
|
const rLines = lines.filter((line) => line.match(/^RDATE/i));
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
const dtMatch = dtLine.match(/DTSTART(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
78
|
+
if (!dtMatch) throw new Error("Invalid DTSTART in ICS snippet");
|
|
79
|
+
const [, valueType, dtTzid, dtValue] = dtMatch;
|
|
80
|
+
tzid = (_a = dtTzid != null ? dtTzid : targetTimezone) != null ? _a : tzid;
|
|
81
|
+
dtstart = parseDateValues([dtValue], tzid, valueType)[0];
|
|
75
82
|
rruleLine = rrLine;
|
|
76
83
|
for (const exLine of exLines) {
|
|
77
|
-
const exMatch = exLine.match(/EXDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
84
|
+
const exMatch = exLine.match(/EXDATE(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
78
85
|
if (exMatch) {
|
|
79
|
-
const exTzid = exMatch
|
|
80
|
-
const
|
|
81
|
-
|
|
86
|
+
const [, valueType2, exTzid, dateValuesStr] = exMatch;
|
|
87
|
+
const exTimezone = exTzid || tzid;
|
|
88
|
+
const dateValues = dateValuesStr.split(",");
|
|
89
|
+
exDate.push(...parseDateValues(dateValues, exTimezone, valueType2));
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
for (const rLine of rLines) {
|
|
85
|
-
const rMatch = rLine.match(/RDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
93
|
+
const rMatch = rLine.match(/RDATE(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
86
94
|
if (rMatch) {
|
|
87
|
-
const rTzid = rMatch
|
|
88
|
-
const
|
|
89
|
-
|
|
95
|
+
const [, valueType2, rTzid, dateValuesStr] = rMatch;
|
|
96
|
+
const rTimezone = rTzid || tzid;
|
|
97
|
+
const dateValues = dateValuesStr.split(",");
|
|
98
|
+
rDate.push(...parseDateValues(dateValues, rTimezone, valueType2));
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
} else {
|
|
@@ -115,14 +124,13 @@ function parseRRuleString(input, targetTimezone) {
|
|
|
115
124
|
case "UNTIL": {
|
|
116
125
|
if (/Z$/.test(val)) {
|
|
117
126
|
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}Z`;
|
|
118
|
-
opts.until = import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(
|
|
119
|
-
tzid || "UTC"
|
|
120
|
-
);
|
|
127
|
+
opts.until = import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC");
|
|
121
128
|
} else {
|
|
122
129
|
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}`;
|
|
123
|
-
opts.until = import_polyfill.Temporal.PlainDateTime.from(iso).toZonedDateTime(
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
opts.until = import_polyfill.Temporal.PlainDateTime.from(iso).toZonedDateTime(tzid || "UTC");
|
|
131
|
+
if (tzid !== "UTC") {
|
|
132
|
+
throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
break;
|
|
128
136
|
}
|
|
@@ -160,7 +168,7 @@ function parseRRuleString(input, targetTimezone) {
|
|
|
160
168
|
}
|
|
161
169
|
return opts;
|
|
162
170
|
}
|
|
163
|
-
var RRuleTemporal = class {
|
|
171
|
+
var RRuleTemporal = class _RRuleTemporal {
|
|
164
172
|
constructor(params) {
|
|
165
173
|
var _a, _b, _c, _d, _e;
|
|
166
174
|
let manual;
|
|
@@ -225,6 +233,9 @@ var RRuleTemporal = class {
|
|
|
225
233
|
if (opts.bySecond.length === 0) delete opts.bySecond;
|
|
226
234
|
}
|
|
227
235
|
if (opts.bySetPos) {
|
|
236
|
+
if (opts.bySetPos.some((p) => p === 0)) {
|
|
237
|
+
throw new Error("bySetPos may not contain 0");
|
|
238
|
+
}
|
|
228
239
|
opts.bySetPos = opts.bySetPos.filter((n) => Number.isInteger(n) && n !== 0);
|
|
229
240
|
if (opts.bySetPos.length === 0) delete opts.bySetPos;
|
|
230
241
|
}
|
|
@@ -333,9 +344,73 @@ var RRuleTemporal = class {
|
|
|
333
344
|
return dt;
|
|
334
345
|
}
|
|
335
346
|
computeFirst() {
|
|
336
|
-
var _a;
|
|
347
|
+
var _a, _b, _c;
|
|
337
348
|
let zdt = this.originalDtstart;
|
|
338
|
-
if ((_a = this.opts.
|
|
349
|
+
if (((_a = this.opts.byWeekNo) == null ? void 0 : _a.length) && ["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq)) {
|
|
350
|
+
let targetWeek = this.opts.byWeekNo[0];
|
|
351
|
+
let targetYear = zdt.year;
|
|
352
|
+
while (targetYear <= zdt.year + 10) {
|
|
353
|
+
const jan1 = zdt.with({ year: targetYear, month: 1, day: 1 });
|
|
354
|
+
const dec31 = zdt.with({ year: targetYear, month: 12, day: 31 });
|
|
355
|
+
let hasTargetWeek = false;
|
|
356
|
+
if (targetWeek > 0) {
|
|
357
|
+
let maxWeek = 52;
|
|
358
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
359
|
+
maxWeek = 53;
|
|
360
|
+
}
|
|
361
|
+
hasTargetWeek = targetWeek <= maxWeek;
|
|
362
|
+
} else {
|
|
363
|
+
let maxWeek = 52;
|
|
364
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
365
|
+
maxWeek = 53;
|
|
366
|
+
}
|
|
367
|
+
hasTargetWeek = -targetWeek <= maxWeek;
|
|
368
|
+
}
|
|
369
|
+
if (hasTargetWeek) {
|
|
370
|
+
const firstThursday = jan1.add({ days: (4 - jan1.dayOfWeek + 7) % 7 });
|
|
371
|
+
let weekStart;
|
|
372
|
+
if (targetWeek > 0) {
|
|
373
|
+
weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: targetWeek - 1 });
|
|
374
|
+
} else {
|
|
375
|
+
const lastWeek = jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4 ? 53 : 52;
|
|
376
|
+
weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: lastWeek + targetWeek });
|
|
377
|
+
}
|
|
378
|
+
if ((_b = this.opts.byDay) == null ? void 0 : _b.length) {
|
|
379
|
+
const dayMap = {
|
|
380
|
+
MO: 1,
|
|
381
|
+
TU: 2,
|
|
382
|
+
WE: 3,
|
|
383
|
+
TH: 4,
|
|
384
|
+
FR: 5,
|
|
385
|
+
SA: 6,
|
|
386
|
+
SU: 7
|
|
387
|
+
};
|
|
388
|
+
const targetDays = this.opts.byDay.map((tok) => {
|
|
389
|
+
var _a2;
|
|
390
|
+
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
391
|
+
}).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
|
|
392
|
+
if (targetDays.length) {
|
|
393
|
+
const candidates = targetDays.map((dayOfWeek) => {
|
|
394
|
+
const delta = (dayOfWeek - weekStart.dayOfWeek + 7) % 7;
|
|
395
|
+
return weekStart.add({ days: delta });
|
|
396
|
+
});
|
|
397
|
+
const firstCandidate = candidates.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b))[0];
|
|
398
|
+
if (firstCandidate && import_polyfill.Temporal.ZonedDateTime.compare(firstCandidate, this.originalDtstart) >= 0) {
|
|
399
|
+
zdt = firstCandidate;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(weekStart, this.originalDtstart) >= 0) {
|
|
405
|
+
zdt = weekStart;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
targetYear++;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (((_c = this.opts.byDay) == null ? void 0 : _c.length) && !this.opts.byWeekNo) {
|
|
339
414
|
const dayMap = {
|
|
340
415
|
MO: 1,
|
|
341
416
|
TU: 2,
|
|
@@ -347,9 +422,7 @@ var RRuleTemporal = class {
|
|
|
347
422
|
};
|
|
348
423
|
let deltas = [];
|
|
349
424
|
if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && this.opts.byDay.every((tok) => /^[A-Z]{2}$/.test(tok))) {
|
|
350
|
-
deltas = this.opts.byDay.map(
|
|
351
|
-
(tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7
|
|
352
|
-
);
|
|
425
|
+
deltas = this.opts.byDay.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
|
|
353
426
|
} else {
|
|
354
427
|
deltas = this.opts.byDay.map((tok) => {
|
|
355
428
|
var _a2;
|
|
@@ -362,42 +435,27 @@ var RRuleTemporal = class {
|
|
|
362
435
|
}
|
|
363
436
|
}
|
|
364
437
|
const { byHour, byMinute, bySecond } = this.opts;
|
|
438
|
+
if (this.opts.freq === "HOURLY" && !byHour && import_polyfill.Temporal.ZonedDateTime.compare(
|
|
439
|
+
zdt.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 }),
|
|
440
|
+
this.originalDtstart
|
|
441
|
+
) > 0) {
|
|
442
|
+
zdt = zdt.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
443
|
+
}
|
|
365
444
|
if (byHour || byMinute || bySecond) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
zdt = this.applyTimeOverride(this.rawAdvance(this.originalDtstart));
|
|
445
|
+
const candidates = this.expandByTime(zdt);
|
|
446
|
+
for (const candidate of candidates) {
|
|
447
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.originalDtstart) >= 0) {
|
|
448
|
+
return candidate;
|
|
449
|
+
}
|
|
372
450
|
}
|
|
451
|
+
zdt = this.applyTimeOverride(this.rawAdvance(zdt));
|
|
373
452
|
}
|
|
374
453
|
return zdt;
|
|
375
454
|
}
|
|
376
|
-
// inside class RRuleTemporal:
|
|
377
|
-
generateWeeklyOccurrences(sample) {
|
|
378
|
-
var _a;
|
|
379
|
-
const dayMap = {
|
|
380
|
-
MO: 1,
|
|
381
|
-
TU: 2,
|
|
382
|
-
WE: 3,
|
|
383
|
-
TH: 4,
|
|
384
|
-
FR: 5,
|
|
385
|
-
SA: 6,
|
|
386
|
-
SU: 7
|
|
387
|
-
};
|
|
388
|
-
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? [...this.opts.byDay] : [Object.entries(dayMap).find(([, d]) => d === sample.dayOfWeek)[0]];
|
|
389
|
-
const occs = tokens.flatMap((tok) => {
|
|
390
|
-
const targetDow = dayMap[tok];
|
|
391
|
-
const delta = (targetDow - sample.dayOfWeek + 7) % 7;
|
|
392
|
-
const sameDate = sample.add({ days: delta });
|
|
393
|
-
return this.expandByTime(sameDate);
|
|
394
|
-
});
|
|
395
|
-
return occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
396
|
-
}
|
|
397
455
|
// --- NEW: constraint checks ---
|
|
398
456
|
// 2) Replace your matchesByDay with this:
|
|
399
457
|
matchesByDay(zdt) {
|
|
400
|
-
const { byDay } = this.opts;
|
|
458
|
+
const { byDay, freq } = this.opts;
|
|
401
459
|
if (!byDay) return true;
|
|
402
460
|
const dayMap = {
|
|
403
461
|
MO: 1,
|
|
@@ -415,6 +473,10 @@ var RRuleTemporal = class {
|
|
|
415
473
|
const weekday = m[2];
|
|
416
474
|
if (!weekday) continue;
|
|
417
475
|
const wd = dayMap[weekday];
|
|
476
|
+
if (freq === "DAILY") {
|
|
477
|
+
if (zdt.dayOfWeek === wd) return true;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
418
480
|
if (ord === 0) {
|
|
419
481
|
if (zdt.dayOfWeek === wd) return true;
|
|
420
482
|
continue;
|
|
@@ -440,9 +502,7 @@ var RRuleTemporal = class {
|
|
|
440
502
|
const { byMonthDay } = this.opts;
|
|
441
503
|
if (!byMonthDay) return true;
|
|
442
504
|
const lastDay = zdt.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
|
|
443
|
-
return byMonthDay.some(
|
|
444
|
-
(d) => d > 0 ? zdt.day === d : zdt.day === lastDay + d + 1
|
|
445
|
-
);
|
|
505
|
+
return byMonthDay.some((d) => d > 0 ? zdt.day === d : zdt.day === lastDay + d + 1);
|
|
446
506
|
}
|
|
447
507
|
matchesAll(zdt) {
|
|
448
508
|
return this.matchesByDay(zdt) && this.matchesByMonth(zdt) && this.matchesByMonthDay(zdt) && this.matchesByYearDay(zdt) && this.matchesByWeekNo(zdt);
|
|
@@ -454,19 +514,31 @@ var RRuleTemporal = class {
|
|
|
454
514
|
const last = zdt.with({ month: 12, day: 31 }).dayOfYear;
|
|
455
515
|
return byYearDay.some((d) => d > 0 ? dayOfYear === d : dayOfYear === last + d + 1);
|
|
456
516
|
}
|
|
517
|
+
getIsoWeekInfo(zdt) {
|
|
518
|
+
const thursday = zdt.add({ days: 4 - zdt.dayOfWeek });
|
|
519
|
+
const year = thursday.year;
|
|
520
|
+
const firstThursday = thursday.with({ month: 1, day: 1 }).add({ days: (4 - thursday.with({ month: 1, day: 1 }).dayOfWeek + 7) % 7 });
|
|
521
|
+
const diffDays = thursday.toPlainDate().since(firstThursday.toPlainDate()).days;
|
|
522
|
+
const week = Math.floor(diffDays / 7) + 1;
|
|
523
|
+
return { week, year };
|
|
524
|
+
}
|
|
457
525
|
matchesByWeekNo(zdt) {
|
|
458
|
-
const { byWeekNo
|
|
526
|
+
const { byWeekNo } = this.opts;
|
|
459
527
|
if (!byWeekNo) return true;
|
|
460
|
-
const
|
|
461
|
-
const
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
528
|
+
const { week, year } = this.getIsoWeekInfo(zdt);
|
|
529
|
+
const jan1 = zdt.with({ year, month: 1, day: 1 });
|
|
530
|
+
const dec31 = zdt.with({ year, month: 12, day: 31 });
|
|
531
|
+
let lastWeek = 52;
|
|
532
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
533
|
+
lastWeek = 53;
|
|
534
|
+
}
|
|
535
|
+
return byWeekNo.some((wn) => {
|
|
536
|
+
if (wn > 0) {
|
|
537
|
+
return week === wn;
|
|
538
|
+
} else {
|
|
539
|
+
return week === lastWeek + wn + 1;
|
|
540
|
+
}
|
|
541
|
+
});
|
|
470
542
|
}
|
|
471
543
|
options() {
|
|
472
544
|
return this.opts;
|
|
@@ -486,14 +558,14 @@ var RRuleTemporal = class {
|
|
|
486
558
|
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
487
559
|
const start = this.originalDtstart;
|
|
488
560
|
let monthCursor = start.with({ day: 1 });
|
|
489
|
-
let
|
|
561
|
+
let matchCount = 0;
|
|
490
562
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
491
|
-
if (iterator && !iterator(start,
|
|
563
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
492
564
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
493
565
|
}
|
|
494
566
|
dates.push(start);
|
|
495
|
-
|
|
496
|
-
if (this.shouldBreakForCountLimit(
|
|
567
|
+
matchCount++;
|
|
568
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
497
569
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
498
570
|
}
|
|
499
571
|
}
|
|
@@ -501,7 +573,8 @@ var RRuleTemporal = class {
|
|
|
501
573
|
if (++iterationCount > this.maxIterations) {
|
|
502
574
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
503
575
|
}
|
|
504
|
-
|
|
576
|
+
let occs = this.generateMonthlyOccurrences(monthCursor);
|
|
577
|
+
occs = this.applyBySetPos(occs);
|
|
505
578
|
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)) {
|
|
506
579
|
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
507
580
|
continue outer_month;
|
|
@@ -511,12 +584,12 @@ var RRuleTemporal = class {
|
|
|
511
584
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
512
585
|
break outer_month;
|
|
513
586
|
}
|
|
514
|
-
if (iterator && !iterator(occ,
|
|
587
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
515
588
|
break outer_month;
|
|
516
589
|
}
|
|
517
590
|
dates.push(occ);
|
|
518
|
-
|
|
519
|
-
if (this.shouldBreakForCountLimit(
|
|
591
|
+
matchCount++;
|
|
592
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
520
593
|
break outer_month;
|
|
521
594
|
}
|
|
522
595
|
}
|
|
@@ -525,6 +598,45 @@ var RRuleTemporal = class {
|
|
|
525
598
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
526
599
|
}
|
|
527
600
|
if (this.opts.freq === "WEEKLY") {
|
|
601
|
+
if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
|
|
602
|
+
const start2 = this.originalDtstart;
|
|
603
|
+
if (this.includeDtstart && !this.matchesAll(start2)) {
|
|
604
|
+
if (iterator && !iterator(start2, 0)) {
|
|
605
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
606
|
+
}
|
|
607
|
+
dates.push(start2);
|
|
608
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
609
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
let yearCursor = start2.with({ month: 1, day: 1 });
|
|
613
|
+
let matchCount2 = dates.length;
|
|
614
|
+
outer_year_for_weekly: while (true) {
|
|
615
|
+
if (++iterationCount > this.maxIterations) {
|
|
616
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
617
|
+
}
|
|
618
|
+
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
619
|
+
for (const occ of occs) {
|
|
620
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start2) < 0) continue;
|
|
621
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
622
|
+
break outer_year_for_weekly;
|
|
623
|
+
}
|
|
624
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
625
|
+
break outer_year_for_weekly;
|
|
626
|
+
}
|
|
627
|
+
dates.push(occ);
|
|
628
|
+
matchCount2++;
|
|
629
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
630
|
+
break outer_year_for_weekly;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (this.opts.until && yearCursor.year > this.opts.until.year) {
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
yearCursor = yearCursor.add({ years: 1 });
|
|
637
|
+
}
|
|
638
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
639
|
+
}
|
|
528
640
|
const start = this.originalDtstart;
|
|
529
641
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
530
642
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -544,39 +656,44 @@ var RRuleTemporal = class {
|
|
|
544
656
|
SA: 6,
|
|
545
657
|
SU: 7
|
|
546
658
|
};
|
|
547
|
-
const tokens = this.opts.byDay ? [...this.opts.byDay] : [Object.entries(dayMap).find(([, d]) => d === start.dayOfWeek)[0]];
|
|
548
|
-
const dows = tokens.map((tok) => dayMap[tok]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
659
|
+
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]];
|
|
660
|
+
const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
549
661
|
const firstWeekDates = dows.map((dw) => {
|
|
550
662
|
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
551
663
|
return start.add({ days: delta });
|
|
552
664
|
});
|
|
553
|
-
let firstOccurrence = firstWeekDates.reduce(
|
|
554
|
-
(a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b
|
|
555
|
-
);
|
|
665
|
+
let firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
556
666
|
const wkstDay = (_a = dayMap[this.opts.wkst || "MO"]) != null ? _a : 1;
|
|
557
667
|
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
558
668
|
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
559
|
-
let
|
|
669
|
+
let matchCount = 0;
|
|
560
670
|
outer_week: while (true) {
|
|
561
671
|
if (++iterationCount > this.maxIterations) {
|
|
562
672
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
563
673
|
}
|
|
564
|
-
|
|
674
|
+
let occs = dows.flatMap((dw) => {
|
|
565
675
|
const delta = (dw - wkstDay + 7) % 7;
|
|
566
676
|
const sameDate = weekCursor.add({ days: delta });
|
|
567
677
|
return this.expandByTime(sameDate);
|
|
568
678
|
}).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
679
|
+
occs = this.applyBySetPos(occs);
|
|
569
680
|
for (const occ of occs) {
|
|
570
681
|
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
571
682
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
572
683
|
break outer_week;
|
|
573
684
|
}
|
|
574
|
-
if (
|
|
685
|
+
if (!this.matchesByMonth(occ)) {
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
if (!this.matchesByMonthDay(occ)) {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
575
692
|
break outer_week;
|
|
576
693
|
}
|
|
577
694
|
dates.push(occ);
|
|
578
|
-
|
|
579
|
-
if (this.shouldBreakForCountLimit(
|
|
695
|
+
matchCount++;
|
|
696
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
580
697
|
break outer_week;
|
|
581
698
|
}
|
|
582
699
|
}
|
|
@@ -584,7 +701,7 @@ var RRuleTemporal = class {
|
|
|
584
701
|
}
|
|
585
702
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
586
703
|
}
|
|
587
|
-
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
704
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay) {
|
|
588
705
|
const start = this.originalDtstart;
|
|
589
706
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
590
707
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -597,7 +714,7 @@ var RRuleTemporal = class {
|
|
|
597
714
|
}
|
|
598
715
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
599
716
|
let monthOffset = 0;
|
|
600
|
-
let
|
|
717
|
+
let matchCount = dates.length;
|
|
601
718
|
let startMonthIndex = months.findIndex((m) => m >= start.month);
|
|
602
719
|
if (startMonthIndex === -1) {
|
|
603
720
|
startMonthIndex = 0;
|
|
@@ -618,12 +735,12 @@ var RRuleTemporal = class {
|
|
|
618
735
|
break;
|
|
619
736
|
}
|
|
620
737
|
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, start) >= 0) {
|
|
621
|
-
if (iterator && !iterator(candidate,
|
|
738
|
+
if (iterator && !iterator(candidate, matchCount)) {
|
|
622
739
|
break;
|
|
623
740
|
}
|
|
624
741
|
dates.push(candidate);
|
|
625
|
-
|
|
626
|
-
if (this.shouldBreakForCountLimit(
|
|
742
|
+
matchCount++;
|
|
743
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
627
744
|
break;
|
|
628
745
|
}
|
|
629
746
|
}
|
|
@@ -631,7 +748,7 @@ var RRuleTemporal = class {
|
|
|
631
748
|
}
|
|
632
749
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
633
750
|
}
|
|
634
|
-
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
751
|
+
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
635
752
|
const start = this.originalDtstart;
|
|
636
753
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
637
754
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -644,7 +761,7 @@ var RRuleTemporal = class {
|
|
|
644
761
|
}
|
|
645
762
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
646
763
|
let yearOffset = 0;
|
|
647
|
-
let
|
|
764
|
+
let matchCount = 0;
|
|
648
765
|
while (true) {
|
|
649
766
|
if (++iterationCount > this.maxIterations) {
|
|
650
767
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -659,12 +776,12 @@ var RRuleTemporal = class {
|
|
|
659
776
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
660
777
|
return dates;
|
|
661
778
|
}
|
|
662
|
-
if (iterator && !iterator(occ,
|
|
779
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
663
780
|
return dates;
|
|
664
781
|
}
|
|
665
782
|
dates.push(occ);
|
|
666
|
-
|
|
667
|
-
if (this.shouldBreakForCountLimit(
|
|
783
|
+
matchCount++;
|
|
784
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
668
785
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
669
786
|
}
|
|
670
787
|
}
|
|
@@ -684,7 +801,7 @@ var RRuleTemporal = class {
|
|
|
684
801
|
}
|
|
685
802
|
}
|
|
686
803
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
687
|
-
let
|
|
804
|
+
let matchCount = 0;
|
|
688
805
|
outer_year: while (true) {
|
|
689
806
|
if (++iterationCount > this.maxIterations) {
|
|
690
807
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -695,12 +812,12 @@ var RRuleTemporal = class {
|
|
|
695
812
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
696
813
|
break outer_year;
|
|
697
814
|
}
|
|
698
|
-
if (iterator && !iterator(occ,
|
|
815
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
699
816
|
break outer_year;
|
|
700
817
|
}
|
|
701
818
|
dates.push(occ);
|
|
702
|
-
|
|
703
|
-
if (this.shouldBreakForCountLimit(
|
|
819
|
+
matchCount++;
|
|
820
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
704
821
|
break outer_year;
|
|
705
822
|
}
|
|
706
823
|
}
|
|
@@ -720,7 +837,7 @@ var RRuleTemporal = class {
|
|
|
720
837
|
}
|
|
721
838
|
}
|
|
722
839
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
723
|
-
let
|
|
840
|
+
let matchCount = 0;
|
|
724
841
|
outer_year2: while (true) {
|
|
725
842
|
if (++iterationCount > this.maxIterations) {
|
|
726
843
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -731,12 +848,12 @@ var RRuleTemporal = class {
|
|
|
731
848
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
732
849
|
break outer_year2;
|
|
733
850
|
}
|
|
734
|
-
if (iterator && !iterator(occ,
|
|
851
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
735
852
|
break outer_year2;
|
|
736
853
|
}
|
|
737
854
|
dates.push(occ);
|
|
738
|
-
|
|
739
|
-
if (this.shouldBreakForCountLimit(
|
|
855
|
+
matchCount++;
|
|
856
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
740
857
|
break outer_year2;
|
|
741
858
|
}
|
|
742
859
|
}
|
|
@@ -744,36 +861,141 @@ var RRuleTemporal = class {
|
|
|
744
861
|
}
|
|
745
862
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
746
863
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
if (
|
|
751
|
-
|
|
864
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
865
|
+
const start = this.originalDtstart;
|
|
866
|
+
let matchCount = 0;
|
|
867
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
868
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
869
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
870
|
+
}
|
|
871
|
+
dates.push(start);
|
|
872
|
+
matchCount++;
|
|
873
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
874
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
875
|
+
}
|
|
752
876
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
877
|
+
let year = start.year;
|
|
878
|
+
const yearDays = [...this.opts.byYearDay].sort((a, b) => a - b);
|
|
879
|
+
const interval = this.opts.interval;
|
|
880
|
+
const startMonthAbs = start.year * 12 + start.month;
|
|
881
|
+
outer_loop: while (true) {
|
|
882
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
if (++iterationCount > this.maxIterations) {
|
|
886
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
887
|
+
}
|
|
888
|
+
const yearStart = start.with({ year, month: 1, day: 1 });
|
|
889
|
+
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
890
|
+
for (const yd of yearDays) {
|
|
891
|
+
const dayNum = yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
892
|
+
if (dayNum <= 0 || dayNum > lastDayOfYear) continue;
|
|
893
|
+
const baseOcc = yearStart.add({ days: dayNum - 1 });
|
|
894
|
+
for (const occ of this.expandByTime(baseOcc)) {
|
|
895
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
896
|
+
if (dates.some((d) => import_polyfill.Temporal.ZonedDateTime.compare(d, occ) === 0)) continue;
|
|
897
|
+
const occMonthAbs = occ.year * 12 + occ.month;
|
|
898
|
+
if ((occMonthAbs - startMonthAbs) % interval !== 0) {
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
if (!this.matchesByMonth(occ)) {
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
905
|
+
break outer_loop;
|
|
906
|
+
}
|
|
907
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
908
|
+
break outer_loop;
|
|
909
|
+
}
|
|
910
|
+
dates.push(occ);
|
|
911
|
+
matchCount++;
|
|
912
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
913
|
+
break outer_loop;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
year++;
|
|
918
|
+
if (this.opts.until && year > this.opts.until.year + 2) {
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
if (!this.opts.until && this.opts.count) {
|
|
922
|
+
const yearsToScan = Math.ceil(this.opts.count / (this.opts.byYearDay.length || 1)) * interval + 5;
|
|
923
|
+
if (year > start.year + yearsToScan) {
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
757
927
|
}
|
|
928
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
758
929
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
930
|
+
if (this.opts.freq === "DAILY" && this.opts.bySetPos) {
|
|
931
|
+
let start = this.originalDtstart;
|
|
932
|
+
let matchCount = 0;
|
|
933
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
934
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
935
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
936
|
+
}
|
|
937
|
+
dates.push(start);
|
|
938
|
+
matchCount++;
|
|
939
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
940
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
941
|
+
}
|
|
762
942
|
}
|
|
763
|
-
|
|
764
|
-
|
|
943
|
+
let dayCursor = start.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
944
|
+
outer_daily: while (true) {
|
|
945
|
+
if (++iterationCount > this.maxIterations) {
|
|
946
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
947
|
+
}
|
|
948
|
+
let dayOccs = this.expandByTime(dayCursor);
|
|
949
|
+
dayOccs = dayOccs.filter((occ) => this.matchesAll(occ));
|
|
950
|
+
dayOccs = this.applyBySetPos(dayOccs);
|
|
951
|
+
for (const occ of dayOccs) {
|
|
952
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
953
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
954
|
+
break outer_daily;
|
|
955
|
+
}
|
|
956
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
957
|
+
break outer_daily;
|
|
958
|
+
}
|
|
959
|
+
dates.push(occ);
|
|
960
|
+
matchCount++;
|
|
961
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
962
|
+
break outer_daily;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
dayCursor = dayCursor.add({ days: this.opts.interval });
|
|
765
966
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
967
|
+
} else {
|
|
968
|
+
let current = this.computeFirst();
|
|
969
|
+
let matchCount = 0;
|
|
970
|
+
if (this.includeDtstart && import_polyfill.Temporal.ZonedDateTime.compare(current, this.originalDtstart) > 0) {
|
|
971
|
+
if (iterator && !iterator(this.originalDtstart, matchCount)) {
|
|
972
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
769
973
|
}
|
|
770
|
-
dates.push(
|
|
974
|
+
dates.push(this.originalDtstart);
|
|
771
975
|
matchCount++;
|
|
772
976
|
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
977
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
while (true) {
|
|
981
|
+
if (++iterationCount > this.maxIterations) {
|
|
982
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
983
|
+
}
|
|
984
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
773
985
|
break;
|
|
774
986
|
}
|
|
987
|
+
if (this.matchesAll(current)) {
|
|
988
|
+
if (iterator && !iterator(current, matchCount)) {
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
dates.push(current);
|
|
992
|
+
matchCount++;
|
|
993
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
994
|
+
break;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
current = this.nextCandidateSameDate(current);
|
|
775
998
|
}
|
|
776
|
-
current = this.nextCandidateSameDate(current);
|
|
777
999
|
}
|
|
778
1000
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
779
1001
|
}
|
|
@@ -802,9 +1024,7 @@ var RRuleTemporal = class {
|
|
|
802
1024
|
excludeExDates(dates) {
|
|
803
1025
|
if (!this.opts.exDate || this.opts.exDate.length === 0) return dates;
|
|
804
1026
|
return dates.filter((date) => {
|
|
805
|
-
return !this.opts.exDate.some(
|
|
806
|
-
(exDate) => import_polyfill.Temporal.ZonedDateTime.compare(date, exDate) === 0
|
|
807
|
-
);
|
|
1027
|
+
return !this.opts.exDate.some((exDate) => import_polyfill.Temporal.ZonedDateTime.compare(date, exDate) === 0);
|
|
808
1028
|
});
|
|
809
1029
|
}
|
|
810
1030
|
/**
|
|
@@ -854,140 +1074,20 @@ var RRuleTemporal = class {
|
|
|
854
1074
|
between(after, before, inc = false) {
|
|
855
1075
|
const startInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
856
1076
|
const endInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
if (
|
|
860
|
-
|
|
861
|
-
outer: while (true) {
|
|
862
|
-
if (++iterationCount > this.maxIterations) {
|
|
863
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
864
|
-
}
|
|
865
|
-
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
866
|
-
for (const occ of occs) {
|
|
867
|
-
const inst = occ.toInstant();
|
|
868
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
869
|
-
break outer;
|
|
870
|
-
}
|
|
871
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
872
|
-
if (startOk) {
|
|
873
|
-
results.push(occ);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
877
|
-
}
|
|
878
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
879
|
-
}
|
|
880
|
-
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
881
|
-
const start = this.originalDtstart;
|
|
882
|
-
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
883
|
-
let yearOffset = 0;
|
|
884
|
-
outer: while (true) {
|
|
885
|
-
if (++iterationCount > this.maxIterations) {
|
|
886
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
887
|
-
}
|
|
888
|
-
const year = start.year + yearOffset * this.opts.interval;
|
|
889
|
-
for (const month of months) {
|
|
890
|
-
let occ = start.with({ year, month });
|
|
891
|
-
occ = this.applyTimeOverride(occ);
|
|
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;
|
|
895
|
-
}
|
|
896
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
897
|
-
if (startOk) {
|
|
898
|
-
results.push(occ);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
yearOffset++;
|
|
902
|
-
}
|
|
903
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
904
|
-
}
|
|
905
|
-
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
906
|
-
const start = this.originalDtstart;
|
|
907
|
-
let yearCursor = start.with({ month: 1, day: 1 });
|
|
908
|
-
outer_year: while (true) {
|
|
909
|
-
if (++iterationCount > this.maxIterations) {
|
|
910
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
911
|
-
}
|
|
912
|
-
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
913
|
-
for (const occ of occs) {
|
|
914
|
-
const inst = occ.toInstant();
|
|
915
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
916
|
-
break outer_year;
|
|
917
|
-
}
|
|
918
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
919
|
-
if (startOk) {
|
|
920
|
-
results.push(occ);
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
924
|
-
}
|
|
925
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
1077
|
+
const beforeZdt = import_polyfill.Temporal.Instant.from(endInst).toZonedDateTimeISO(this.tzid);
|
|
1078
|
+
const tempOpts = __spreadValues({}, this.opts);
|
|
1079
|
+
if (!tempOpts.until || import_polyfill.Temporal.ZonedDateTime.compare(beforeZdt, tempOpts.until) < 0) {
|
|
1080
|
+
tempOpts.until = beforeZdt;
|
|
926
1081
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
const inst = occ.toInstant();
|
|
937
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
938
|
-
break outer_year2;
|
|
939
|
-
}
|
|
940
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
941
|
-
if (startOk) {
|
|
942
|
-
results.push(occ);
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
946
|
-
}
|
|
947
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
948
|
-
}
|
|
949
|
-
if (this.opts.freq === "WEEKLY") {
|
|
950
|
-
const startInst2 = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
951
|
-
const endInst2 = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
952
|
-
let weekCursor = this.computeFirst();
|
|
953
|
-
const results2 = [];
|
|
954
|
-
outer: while (true) {
|
|
955
|
-
if (++iterationCount > this.maxIterations) {
|
|
956
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
957
|
-
}
|
|
958
|
-
const occs = this.generateWeeklyOccurrences(weekCursor);
|
|
959
|
-
for (const occ of occs) {
|
|
960
|
-
const inst = occ.toInstant();
|
|
961
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst2) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst2) >= 0) {
|
|
962
|
-
break outer;
|
|
963
|
-
}
|
|
964
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst2) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst2) > 0;
|
|
965
|
-
if (startOk) {
|
|
966
|
-
results2.push(occ);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
970
|
-
}
|
|
971
|
-
return this.mergeRDates(results2, startInst2, endInst2, inc);
|
|
972
|
-
}
|
|
973
|
-
let current = this.computeFirst();
|
|
974
|
-
while (true) {
|
|
975
|
-
if (++iterationCount > this.maxIterations) {
|
|
976
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
977
|
-
}
|
|
978
|
-
const inst = current.toInstant();
|
|
979
|
-
if (inc) {
|
|
980
|
-
if (import_polyfill.Temporal.Instant.compare(inst, endInst) > 0) break;
|
|
981
|
-
} else {
|
|
982
|
-
if (import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) break;
|
|
983
|
-
}
|
|
984
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
985
|
-
if (startOk && this.matchesAll(current)) {
|
|
986
|
-
results.push(current);
|
|
987
|
-
}
|
|
988
|
-
current = this.nextCandidateSameDate(current);
|
|
989
|
-
}
|
|
990
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
1082
|
+
delete tempOpts.count;
|
|
1083
|
+
const tempRule = new _RRuleTemporal(tempOpts);
|
|
1084
|
+
const allDates = tempRule.all();
|
|
1085
|
+
return allDates.filter((date) => {
|
|
1086
|
+
const inst = date.toInstant();
|
|
1087
|
+
const afterStart = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1088
|
+
const beforeEnd = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1089
|
+
return afterStart && beforeEnd;
|
|
1090
|
+
});
|
|
991
1091
|
}
|
|
992
1092
|
/**
|
|
993
1093
|
* Returns the next occurrence of the rule after a specified date.
|
|
@@ -1096,10 +1196,12 @@ var RRuleTemporal = class {
|
|
|
1096
1196
|
return [];
|
|
1097
1197
|
}
|
|
1098
1198
|
const dates = byMonthDayHits.map((d) => sample.with({ day: d }));
|
|
1099
|
-
|
|
1199
|
+
let expanded2 = dates.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1200
|
+
return expanded2;
|
|
1100
1201
|
}
|
|
1101
1202
|
if (!byDay) {
|
|
1102
|
-
|
|
1203
|
+
const expanded2 = this.expandByTime(sample);
|
|
1204
|
+
return expanded2;
|
|
1103
1205
|
}
|
|
1104
1206
|
const dayMap = {
|
|
1105
1207
|
MO: 1,
|
|
@@ -1143,7 +1245,6 @@ var RRuleTemporal = class {
|
|
|
1143
1245
|
}
|
|
1144
1246
|
const hits = finalDays.map((d) => sample.with({ day: d }));
|
|
1145
1247
|
let expanded = hits.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1146
|
-
expanded = this.applyBySetPos(expanded);
|
|
1147
1248
|
return expanded;
|
|
1148
1249
|
}
|
|
1149
1250
|
/**
|
|
@@ -1153,9 +1254,10 @@ var RRuleTemporal = class {
|
|
|
1153
1254
|
*/
|
|
1154
1255
|
generateYearlyOccurrences(sample) {
|
|
1155
1256
|
var _a;
|
|
1156
|
-
const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : [this.originalDtstart.month];
|
|
1257
|
+
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];
|
|
1157
1258
|
let occs = [];
|
|
1158
|
-
|
|
1259
|
+
const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
|
|
1260
|
+
if (hasOrdinalByDay && !this.opts.byMonth) {
|
|
1159
1261
|
const dayMap = {
|
|
1160
1262
|
MO: 1,
|
|
1161
1263
|
TU: 2,
|
|
@@ -1180,9 +1282,7 @@ var RRuleTemporal = class {
|
|
|
1180
1282
|
const delta = (dec31.dayOfWeek - wd + 7) % 7;
|
|
1181
1283
|
dt = dec31.subtract({ days: delta + 7 * (-ord - 1) });
|
|
1182
1284
|
}
|
|
1183
|
-
|
|
1184
|
-
occs.push(...this.expandByTime(dt));
|
|
1185
|
-
}
|
|
1285
|
+
occs.push(...this.expandByTime(dt));
|
|
1186
1286
|
}
|
|
1187
1287
|
} else if (!this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
1188
1288
|
occs = months.flatMap((m) => {
|
|
@@ -1249,23 +1349,6 @@ var RRuleTemporal = class {
|
|
|
1249
1349
|
}
|
|
1250
1350
|
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1251
1351
|
}
|
|
1252
|
-
mergeRDates(list, startInst, endInst, inc) {
|
|
1253
|
-
if (!this.opts.rDate) return this.excludeExDates(list);
|
|
1254
|
-
for (const z of this.opts.rDate) {
|
|
1255
|
-
const inst = z.toInstant();
|
|
1256
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1257
|
-
const endOk = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1258
|
-
if (startOk && endOk) list.push(z);
|
|
1259
|
-
}
|
|
1260
|
-
list.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1261
|
-
const dedup = [];
|
|
1262
|
-
for (const d of list) {
|
|
1263
|
-
if (dedup.length === 0 || import_polyfill.Temporal.ZonedDateTime.compare(d, dedup[dedup.length - 1]) !== 0) {
|
|
1264
|
-
dedup.push(d);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
return this.excludeExDates(dedup);
|
|
1268
|
-
}
|
|
1269
1352
|
};
|
|
1270
1353
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1271
1354
|
0 && (module.exports = {
|