rrule-temporal 1.4.7 → 1.5.1
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 +24 -0
- package/dist/{chunk-Y57KCW63.js → chunk-S4JPXM4U.js} +569 -81
- package/dist/index.cjs +569 -81
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +1 -1
- package/dist/totext.cjs +569 -81
- package/dist/totext.js +1 -1
- package/package.json +1 -1
|
@@ -47,6 +47,22 @@ var allowedFreqSet = new Set(allowedFreq);
|
|
|
47
47
|
var allowedWeekdaysSet = new Set(allowedWeekdays);
|
|
48
48
|
var byDayTokenRegex = new RegExp(`^([+-]?\\d{1,2})?(${allowedWeekdays.join("|")})$`);
|
|
49
49
|
var byDayWeekdaySuffixRegex = new RegExp(`(${allowedWeekdays.join("|")})$`);
|
|
50
|
+
var MS_PER_SECOND = 1e3;
|
|
51
|
+
var MS_PER_MINUTE = 60 * MS_PER_SECOND;
|
|
52
|
+
var MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
53
|
+
var MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
54
|
+
var MS_PER_WEEK = 7 * MS_PER_DAY;
|
|
55
|
+
var GREGORIAN_MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
56
|
+
var GREGORIAN_WEEKDAY_OFFSETS = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
|
|
57
|
+
var NS_PER_MILLISECOND = BigInt(1e6);
|
|
58
|
+
var NS_PER_SECOND = BigInt(1e9);
|
|
59
|
+
var NS_PER_MINUTE = BigInt(60) * NS_PER_SECOND;
|
|
60
|
+
var NS_PER_HOUR = BigInt(60) * NS_PER_MINUTE;
|
|
61
|
+
var NS_PER_DAY = BigInt(24) * NS_PER_HOUR;
|
|
62
|
+
var NS_PER_WEEK = BigInt(7) * NS_PER_DAY;
|
|
63
|
+
function addIsoDays(dayOfWeek, deltaDays) {
|
|
64
|
+
return (dayOfWeek - 1 + deltaDays % 7 + 7) % 7 + 1;
|
|
65
|
+
}
|
|
50
66
|
function extractWeekdayToken(token) {
|
|
51
67
|
const m = token.toUpperCase().match(byDayWeekdaySuffixRegex);
|
|
52
68
|
const weekday = m == null ? void 0 : m[1];
|
|
@@ -273,7 +289,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
273
289
|
return Temporal.ZonedDateTime.from(zdt.toString());
|
|
274
290
|
}
|
|
275
291
|
constructor(params) {
|
|
276
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
292
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
277
293
|
let manual;
|
|
278
294
|
if (isIcsOpts(params)) {
|
|
279
295
|
const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
|
|
@@ -314,6 +330,32 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
314
330
|
this.opts = this.sanitizeOpts(manual);
|
|
315
331
|
this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
|
|
316
332
|
this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
|
|
333
|
+
this.parsedByDayTokens = this.buildParsedByDayTokens(this.opts.byDay);
|
|
334
|
+
this.simpleByDayIsoDays = this.buildByDayIsoDays(this.parsedByDayTokens, false);
|
|
335
|
+
this.allByDayIsoDays = this.buildByDayIsoDays(this.parsedByDayTokens, true);
|
|
336
|
+
this.hasOrdinalByDay = (_j = (_i = this.parsedByDayTokens) == null ? void 0 : _i.some((token) => token.ord !== 0)) != null ? _j : false;
|
|
337
|
+
this.canUseEpochMillisecondsPrecisionFlag = this.originalDtstart.microsecond === 0 && this.originalDtstart.nanosecond === 0 && (!this.opts.until || this.opts.until.microsecond === 0 && this.opts.until.nanosecond === 0);
|
|
338
|
+
this.timeSlotOffsetsMs = this.buildTimeSlotOffsetsMs();
|
|
339
|
+
this.numericByMonths = (_k = this.opts.byMonth) == null ? void 0 : _k.filter((value) => typeof value === "number");
|
|
340
|
+
}
|
|
341
|
+
buildParsedByDayTokens(byDay) {
|
|
342
|
+
if (!(byDay == null ? void 0 : byDay.length)) return void 0;
|
|
343
|
+
const tokens = byDay.map((tok) => {
|
|
344
|
+
const parsed = parseByDayToken(tok);
|
|
345
|
+
if (!parsed) return null;
|
|
346
|
+
return {
|
|
347
|
+
ord: parsed.ord,
|
|
348
|
+
weekday: parsed.weekday,
|
|
349
|
+
isoDay: weekdayToIsoDay[parsed.weekday]
|
|
350
|
+
};
|
|
351
|
+
}).filter((token) => token !== null);
|
|
352
|
+
return tokens.length > 0 ? tokens : void 0;
|
|
353
|
+
}
|
|
354
|
+
buildByDayIsoDays(tokens, includeOrdinals) {
|
|
355
|
+
if (!(tokens == null ? void 0 : tokens.length)) return void 0;
|
|
356
|
+
const isoDays = tokens.filter((token) => includeOrdinals || token.ord === 0).map((token) => token.isoDay);
|
|
357
|
+
if (!isoDays.length) return void 0;
|
|
358
|
+
return [...new Set(isoDays)].sort((a, b) => a - b);
|
|
317
359
|
}
|
|
318
360
|
sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
|
|
319
361
|
if (!arr) return void 0;
|
|
@@ -435,9 +477,21 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
435
477
|
*/
|
|
436
478
|
expandByTime(base) {
|
|
437
479
|
var _a, _b, _c;
|
|
480
|
+
if (!this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond) {
|
|
481
|
+
return [base];
|
|
482
|
+
}
|
|
438
483
|
const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
|
|
439
484
|
const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
|
|
440
485
|
const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
|
|
486
|
+
if (hours.length === 1 && minutes.length === 1 && seconds.length === 1) {
|
|
487
|
+
const hour = hours[0];
|
|
488
|
+
const minute = minutes[0];
|
|
489
|
+
const second = seconds[0];
|
|
490
|
+
if (hour === base.hour && minute === base.minute && second === base.second) {
|
|
491
|
+
return [base];
|
|
492
|
+
}
|
|
493
|
+
return [base.with({ hour, minute, second })];
|
|
494
|
+
}
|
|
441
495
|
const out = [];
|
|
442
496
|
for (const h of hours) {
|
|
443
497
|
for (const m of minutes) {
|
|
@@ -685,30 +739,26 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
685
739
|
// --- NEW: constraint checks ---
|
|
686
740
|
// 2) Replace your matchesByDay with this:
|
|
687
741
|
matchesByDay(zdt) {
|
|
742
|
+
var _a, _b, _c;
|
|
688
743
|
const { byDay, freq } = this.opts;
|
|
689
744
|
if (!byDay) return true;
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (zdt.dayOfWeek === wd) return true;
|
|
698
|
-
continue;
|
|
699
|
-
}
|
|
700
|
-
if (ord === 0) {
|
|
701
|
-
if (zdt.dayOfWeek === wd) return true;
|
|
745
|
+
if (!this.hasOrdinalByDay) {
|
|
746
|
+
return (_b = (_a = this.simpleByDayIsoDays) == null ? void 0 : _a.includes(zdt.dayOfWeek)) != null ? _b : false;
|
|
747
|
+
}
|
|
748
|
+
for (const token of (_c = this.parsedByDayTokens) != null ? _c : []) {
|
|
749
|
+
if (freq === "DAILY" && zdt.dayOfWeek === token.isoDay) return true;
|
|
750
|
+
if (token.ord === 0) {
|
|
751
|
+
if (zdt.dayOfWeek === token.isoDay) return true;
|
|
702
752
|
continue;
|
|
703
753
|
}
|
|
704
754
|
const month = zdt.month;
|
|
705
755
|
let dt = zdt.with({ day: 1 });
|
|
706
756
|
const candidates = [];
|
|
707
757
|
while (dt.month === month) {
|
|
708
|
-
if (dt.dayOfWeek ===
|
|
758
|
+
if (dt.dayOfWeek === token.isoDay) candidates.push(dt.day);
|
|
709
759
|
dt = dt.add({ days: 1 });
|
|
710
760
|
}
|
|
711
|
-
const idx = ord > 0 ? ord - 1 : candidates.length + ord;
|
|
761
|
+
const idx = token.ord > 0 ? token.ord - 1 : candidates.length + token.ord;
|
|
712
762
|
if (candidates[idx] === zdt.day) return true;
|
|
713
763
|
}
|
|
714
764
|
return false;
|
|
@@ -901,6 +951,485 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
901
951
|
}
|
|
902
952
|
return true;
|
|
903
953
|
}
|
|
954
|
+
canUseUtcLinearFastPath(iterator) {
|
|
955
|
+
if (iterator || this.tzid !== "UTC" || this.opts.rscale || this.opts.rDate || this.opts.exDate) {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
if (this.opts.byMonth || this.opts.byMonthDay || this.opts.byYearDay || this.opts.byWeekNo || this.opts.bySetPos) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
switch (this.opts.freq) {
|
|
962
|
+
case "DAILY":
|
|
963
|
+
return !this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond && !this.hasOrdinalByDay;
|
|
964
|
+
case "HOURLY":
|
|
965
|
+
case "MINUTELY":
|
|
966
|
+
return !this.opts.byDay && !this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond;
|
|
967
|
+
default:
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
canUseUtcWeeklyFastPath(iterator) {
|
|
972
|
+
return !iterator && this.tzid === "UTC" && this.opts.freq === "WEEKLY" && !this.opts.rscale && !this.opts.rDate && !this.opts.exDate && !this.opts.byMonth && !this.opts.byMonthDay && !this.opts.byYearDay && !this.opts.byWeekNo && !this.opts.bySetPos && !this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond && !this.hasOrdinalByDay;
|
|
973
|
+
}
|
|
974
|
+
canUseUtcMonthlyFastPath(iterator) {
|
|
975
|
+
return !iterator && this.tzid === "UTC" && this.opts.freq === "MONTHLY" && !this.opts.rscale && !this.opts.rDate && !this.opts.exDate && !this.opts.byYearDay && !this.opts.byWeekNo && this.canUseEpochMillisecondsPrecisionFlag && !!(this.opts.byDay || this.opts.byMonthDay);
|
|
976
|
+
}
|
|
977
|
+
utcZdtFromEpochNanoseconds(epochNanoseconds) {
|
|
978
|
+
return Temporal.Instant.fromEpochNanoseconds(epochNanoseconds).toZonedDateTimeISO("UTC");
|
|
979
|
+
}
|
|
980
|
+
utcZdtFromEpochMilliseconds(epochMilliseconds) {
|
|
981
|
+
return Temporal.Instant.fromEpochMilliseconds(epochMilliseconds).toZonedDateTimeISO("UTC");
|
|
982
|
+
}
|
|
983
|
+
canUseUtcEpochMillisecondsPrecision() {
|
|
984
|
+
return this.canUseEpochMillisecondsPrecisionFlag;
|
|
985
|
+
}
|
|
986
|
+
buildTimeSlotOffsetsMs() {
|
|
987
|
+
var _a, _b, _c;
|
|
988
|
+
if (!this.canUseEpochMillisecondsPrecisionFlag) return void 0;
|
|
989
|
+
const hours = (_a = this.opts.byHour) != null ? _a : [this.originalDtstart.hour];
|
|
990
|
+
const minutes = (_b = this.opts.byMinute) != null ? _b : [this.originalDtstart.minute];
|
|
991
|
+
const seconds = (_c = this.opts.bySecond) != null ? _c : [this.originalDtstart.second];
|
|
992
|
+
const baseMilliseconds = this.originalDtstart.millisecond;
|
|
993
|
+
const offsets = [];
|
|
994
|
+
for (const hour of hours) {
|
|
995
|
+
for (const minute of minutes) {
|
|
996
|
+
for (const second of seconds) {
|
|
997
|
+
offsets.push(((hour * 60 + minute) * 60 + second) * MS_PER_SECOND + baseMilliseconds);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return offsets;
|
|
1002
|
+
}
|
|
1003
|
+
findFirstMatchingDailyStep(startDayOfWeek, stepDays, allowedDays) {
|
|
1004
|
+
let dayOfWeek = startDayOfWeek;
|
|
1005
|
+
for (let steps = 0; steps < 7; steps++) {
|
|
1006
|
+
if (allowedDays.includes(dayOfWeek)) {
|
|
1007
|
+
return steps;
|
|
1008
|
+
}
|
|
1009
|
+
dayOfWeek = addIsoDays(dayOfWeek, stepDays);
|
|
1010
|
+
}
|
|
1011
|
+
return null;
|
|
1012
|
+
}
|
|
1013
|
+
allUtcFastPath(iterator) {
|
|
1014
|
+
if (this.canUseUtcLinearFastPath(iterator)) {
|
|
1015
|
+
switch (this.opts.freq) {
|
|
1016
|
+
case "DAILY":
|
|
1017
|
+
return this._allUtcDailySimple();
|
|
1018
|
+
case "HOURLY":
|
|
1019
|
+
return this._allUtcFixedStepSimple(NS_PER_HOUR * BigInt(this.opts.interval));
|
|
1020
|
+
case "MINUTELY":
|
|
1021
|
+
return this._allUtcFixedStepSimple(NS_PER_MINUTE * BigInt(this.opts.interval));
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (this.canUseUtcMonthlyFastPath(iterator)) {
|
|
1025
|
+
return this._allUtcMonthlyByDayOrMonthDay();
|
|
1026
|
+
}
|
|
1027
|
+
if (this.canUseUtcWeeklyFastPath(iterator)) {
|
|
1028
|
+
return this._allUtcWeeklySimple();
|
|
1029
|
+
}
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
_allUtcFixedStepSimple(stepNanoseconds) {
|
|
1033
|
+
var _a, _b;
|
|
1034
|
+
const dates = [];
|
|
1035
|
+
if (!this.addDtstartIfNeeded(dates)) {
|
|
1036
|
+
return dates;
|
|
1037
|
+
}
|
|
1038
|
+
let iterationCount = 0;
|
|
1039
|
+
if (this.canUseUtcEpochMillisecondsPrecision()) {
|
|
1040
|
+
let currentMilliseconds = this.originalDtstart.epochMilliseconds;
|
|
1041
|
+
const stepMilliseconds = Number(stepNanoseconds / NS_PER_MILLISECOND);
|
|
1042
|
+
const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
|
|
1043
|
+
while (true) {
|
|
1044
|
+
if (++iterationCount > this.maxIterations) {
|
|
1045
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1046
|
+
}
|
|
1047
|
+
if (untilMilliseconds !== void 0 && currentMilliseconds > untilMilliseconds) {
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
dates.push(this.utcZdtFromEpochMilliseconds(currentMilliseconds));
|
|
1051
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
currentMilliseconds += stepMilliseconds;
|
|
1055
|
+
}
|
|
1056
|
+
return dates;
|
|
1057
|
+
}
|
|
1058
|
+
let currentNanoseconds = this.originalDtstart.epochNanoseconds;
|
|
1059
|
+
const untilNanoseconds = (_b = this.opts.until) == null ? void 0 : _b.epochNanoseconds;
|
|
1060
|
+
while (true) {
|
|
1061
|
+
if (++iterationCount > this.maxIterations) {
|
|
1062
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1063
|
+
}
|
|
1064
|
+
if (untilNanoseconds !== void 0 && currentNanoseconds > untilNanoseconds) {
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
dates.push(this.utcZdtFromEpochNanoseconds(currentNanoseconds));
|
|
1068
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
currentNanoseconds += stepNanoseconds;
|
|
1072
|
+
}
|
|
1073
|
+
return dates;
|
|
1074
|
+
}
|
|
1075
|
+
_allUtcDailySimple() {
|
|
1076
|
+
var _a, _b;
|
|
1077
|
+
const dates = [];
|
|
1078
|
+
if (!this.addDtstartIfNeeded(dates)) {
|
|
1079
|
+
return dates;
|
|
1080
|
+
}
|
|
1081
|
+
const stepDays = this.opts.interval;
|
|
1082
|
+
const allowedDays = this.simpleByDayIsoDays;
|
|
1083
|
+
let iterationCount = 0;
|
|
1084
|
+
if (this.canUseUtcEpochMillisecondsPrecision()) {
|
|
1085
|
+
const stepMilliseconds = stepDays * MS_PER_DAY;
|
|
1086
|
+
const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
|
|
1087
|
+
let currentMilliseconds = this.originalDtstart.epochMilliseconds;
|
|
1088
|
+
let currentDayOfWeek2 = this.originalDtstart.dayOfWeek;
|
|
1089
|
+
if (allowedDays == null ? void 0 : allowedDays.length) {
|
|
1090
|
+
const firstMatchingStep = this.findFirstMatchingDailyStep(currentDayOfWeek2, stepDays, allowedDays);
|
|
1091
|
+
if (firstMatchingStep === null) {
|
|
1092
|
+
return dates;
|
|
1093
|
+
}
|
|
1094
|
+
currentMilliseconds += firstMatchingStep * stepMilliseconds;
|
|
1095
|
+
currentDayOfWeek2 = addIsoDays(currentDayOfWeek2, firstMatchingStep * stepDays);
|
|
1096
|
+
}
|
|
1097
|
+
while (true) {
|
|
1098
|
+
if (++iterationCount > this.maxIterations) {
|
|
1099
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1100
|
+
}
|
|
1101
|
+
if (untilMilliseconds !== void 0 && currentMilliseconds > untilMilliseconds) {
|
|
1102
|
+
break;
|
|
1103
|
+
}
|
|
1104
|
+
if (!allowedDays || allowedDays.includes(currentDayOfWeek2)) {
|
|
1105
|
+
dates.push(this.utcZdtFromEpochMilliseconds(currentMilliseconds));
|
|
1106
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1107
|
+
break;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
currentMilliseconds += stepMilliseconds;
|
|
1111
|
+
currentDayOfWeek2 = addIsoDays(currentDayOfWeek2, stepDays);
|
|
1112
|
+
}
|
|
1113
|
+
return dates;
|
|
1114
|
+
}
|
|
1115
|
+
const stepNanoseconds = BigInt(stepDays) * NS_PER_DAY;
|
|
1116
|
+
const untilNanoseconds = (_b = this.opts.until) == null ? void 0 : _b.epochNanoseconds;
|
|
1117
|
+
let currentNanoseconds = this.originalDtstart.epochNanoseconds;
|
|
1118
|
+
let currentDayOfWeek = this.originalDtstart.dayOfWeek;
|
|
1119
|
+
if (allowedDays == null ? void 0 : allowedDays.length) {
|
|
1120
|
+
const firstMatchingStep = this.findFirstMatchingDailyStep(currentDayOfWeek, stepDays, allowedDays);
|
|
1121
|
+
if (firstMatchingStep === null) {
|
|
1122
|
+
return dates;
|
|
1123
|
+
}
|
|
1124
|
+
currentNanoseconds += BigInt(firstMatchingStep) * stepNanoseconds;
|
|
1125
|
+
currentDayOfWeek = addIsoDays(currentDayOfWeek, firstMatchingStep * stepDays);
|
|
1126
|
+
}
|
|
1127
|
+
while (true) {
|
|
1128
|
+
if (++iterationCount > this.maxIterations) {
|
|
1129
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1130
|
+
}
|
|
1131
|
+
if (untilNanoseconds !== void 0 && currentNanoseconds > untilNanoseconds) {
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
if (!allowedDays || allowedDays.includes(currentDayOfWeek)) {
|
|
1135
|
+
dates.push(this.utcZdtFromEpochNanoseconds(currentNanoseconds));
|
|
1136
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
currentNanoseconds += stepNanoseconds;
|
|
1141
|
+
currentDayOfWeek = addIsoDays(currentDayOfWeek, stepDays);
|
|
1142
|
+
}
|
|
1143
|
+
return dates;
|
|
1144
|
+
}
|
|
1145
|
+
_allUtcWeeklySimple() {
|
|
1146
|
+
var _a, _b, _c, _d, _e;
|
|
1147
|
+
const dates = [];
|
|
1148
|
+
if (!this.addDtstartIfNeeded(dates)) {
|
|
1149
|
+
return dates;
|
|
1150
|
+
}
|
|
1151
|
+
const start = this.originalDtstart;
|
|
1152
|
+
const wkstToken = (_a = extractWeekdayToken(this.opts.wkst || "MO")) != null ? _a : "MO";
|
|
1153
|
+
const wkstDay = (_b = weekdayToIsoDay[wkstToken]) != null ? _b : 1;
|
|
1154
|
+
const targetDays = this.opts.byDay ? [...(_c = this.allByDayIsoDays) != null ? _c : []] : [start.dayOfWeek];
|
|
1155
|
+
const dayOffsets = targetDays.map((day) => (day - wkstDay + 7) % 7).sort((a, b) => a - b);
|
|
1156
|
+
const weekStartOffset = (start.dayOfWeek - wkstDay + 7) % 7;
|
|
1157
|
+
let iterationCount = 0;
|
|
1158
|
+
if (this.canUseUtcEpochMillisecondsPrecision()) {
|
|
1159
|
+
const startMilliseconds = start.epochMilliseconds;
|
|
1160
|
+
const untilMilliseconds = (_d = this.opts.until) == null ? void 0 : _d.epochMilliseconds;
|
|
1161
|
+
const weekStepMilliseconds = this.opts.interval * MS_PER_WEEK;
|
|
1162
|
+
let weekStartMilliseconds = startMilliseconds - weekStartOffset * MS_PER_DAY;
|
|
1163
|
+
while (true) {
|
|
1164
|
+
if (++iterationCount > this.maxIterations) {
|
|
1165
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1166
|
+
}
|
|
1167
|
+
for (const dayOffset of dayOffsets) {
|
|
1168
|
+
const occurrenceMilliseconds = weekStartMilliseconds + dayOffset * MS_PER_DAY;
|
|
1169
|
+
if (occurrenceMilliseconds < startMilliseconds) {
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
if (untilMilliseconds !== void 0 && occurrenceMilliseconds > untilMilliseconds) {
|
|
1173
|
+
return dates;
|
|
1174
|
+
}
|
|
1175
|
+
dates.push(this.utcZdtFromEpochMilliseconds(occurrenceMilliseconds));
|
|
1176
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1177
|
+
return dates;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
weekStartMilliseconds += weekStepMilliseconds;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
const startNanoseconds = start.epochNanoseconds;
|
|
1184
|
+
const untilNanoseconds = (_e = this.opts.until) == null ? void 0 : _e.epochNanoseconds;
|
|
1185
|
+
const weekStepNanoseconds = BigInt(this.opts.interval) * NS_PER_WEEK;
|
|
1186
|
+
let weekStartNanoseconds = startNanoseconds - BigInt(weekStartOffset) * NS_PER_DAY;
|
|
1187
|
+
while (true) {
|
|
1188
|
+
if (++iterationCount > this.maxIterations) {
|
|
1189
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1190
|
+
}
|
|
1191
|
+
for (const dayOffset of dayOffsets) {
|
|
1192
|
+
const occurrenceNanoseconds = weekStartNanoseconds + BigInt(dayOffset) * NS_PER_DAY;
|
|
1193
|
+
if (occurrenceNanoseconds < startNanoseconds) {
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
if (untilNanoseconds !== void 0 && occurrenceNanoseconds > untilNanoseconds) {
|
|
1197
|
+
return dates;
|
|
1198
|
+
}
|
|
1199
|
+
dates.push(this.utcZdtFromEpochNanoseconds(occurrenceNanoseconds));
|
|
1200
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1201
|
+
return dates;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
weekStartNanoseconds += weekStepNanoseconds;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
hasSingleExpandedTimeSlot() {
|
|
1208
|
+
var _a, _b, _c;
|
|
1209
|
+
if (this.timeSlotOffsetsMs) {
|
|
1210
|
+
return this.timeSlotOffsetsMs.length === 1;
|
|
1211
|
+
}
|
|
1212
|
+
const hours = (_a = this.opts.byHour) != null ? _a : [this.originalDtstart.hour];
|
|
1213
|
+
const minutes = (_b = this.opts.byMinute) != null ? _b : [this.originalDtstart.minute];
|
|
1214
|
+
const seconds = (_c = this.opts.bySecond) != null ? _c : [this.originalDtstart.second];
|
|
1215
|
+
return hours.length === 1 && minutes.length === 1 && seconds.length === 1;
|
|
1216
|
+
}
|
|
1217
|
+
buildMonthlyOccurrenceOnDay(monthStart, day) {
|
|
1218
|
+
const base = monthStart.day === day ? monthStart : monthStart.with({ day });
|
|
1219
|
+
return this.applyTimeOverride(base);
|
|
1220
|
+
}
|
|
1221
|
+
applyBySetPosToSortedList(list) {
|
|
1222
|
+
const { bySetPos } = this.opts;
|
|
1223
|
+
if (!bySetPos || !bySetPos.length || list.length === 0) return list;
|
|
1224
|
+
const out = [];
|
|
1225
|
+
const len = list.length;
|
|
1226
|
+
for (const pos of bySetPos) {
|
|
1227
|
+
const idx = pos > 0 ? pos - 1 : len + pos;
|
|
1228
|
+
if (idx >= 0 && idx < len) out.push(list[idx]);
|
|
1229
|
+
}
|
|
1230
|
+
return out;
|
|
1231
|
+
}
|
|
1232
|
+
generateMonthlyOccurrenceDays(sample) {
|
|
1233
|
+
const { byDay, byMonth, byMonthDay } = this.opts;
|
|
1234
|
+
const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
|
|
1235
|
+
if (byMonth && !byMonth.includes(sample.month)) return [];
|
|
1236
|
+
const lastDay = monthStart.add({ months: 1 }).subtract({ days: 1 }).day;
|
|
1237
|
+
let byMonthDayHits = [];
|
|
1238
|
+
if (byMonthDay && byMonthDay.length > 0) {
|
|
1239
|
+
byMonthDayHits = byMonthDay.map((d) => d > 0 ? d : lastDay + d + 1).filter((d) => d >= 1 && d <= lastDay);
|
|
1240
|
+
byMonthDayHits = [...new Set(byMonthDayHits)].sort((a, b) => a - b);
|
|
1241
|
+
}
|
|
1242
|
+
if (!byDay && byMonthDay && byMonthDay.length > 0) {
|
|
1243
|
+
return byMonthDayHits;
|
|
1244
|
+
}
|
|
1245
|
+
if (!byDay) {
|
|
1246
|
+
return [sample.day];
|
|
1247
|
+
}
|
|
1248
|
+
const tokens = this.parsedByDayTokens;
|
|
1249
|
+
if (!(tokens == null ? void 0 : tokens.length)) return [];
|
|
1250
|
+
const firstDayOfWeek = monthStart.dayOfWeek;
|
|
1251
|
+
const lastDayOfWeek = (firstDayOfWeek - 1 + lastDay - 1) % 7 + 1;
|
|
1252
|
+
const byDayHits = /* @__PURE__ */ new Set();
|
|
1253
|
+
for (const { ord, isoDay } of tokens) {
|
|
1254
|
+
if (ord === 0) {
|
|
1255
|
+
let day = 1 + (isoDay - firstDayOfWeek + 7) % 7;
|
|
1256
|
+
while (day <= lastDay) {
|
|
1257
|
+
byDayHits.add(day);
|
|
1258
|
+
day += 7;
|
|
1259
|
+
}
|
|
1260
|
+
} else {
|
|
1261
|
+
let day;
|
|
1262
|
+
if (ord > 0) {
|
|
1263
|
+
day = 1 + (isoDay - firstDayOfWeek + 7) % 7 + 7 * (ord - 1);
|
|
1264
|
+
} else {
|
|
1265
|
+
const lastMatch = lastDay - (lastDayOfWeek - isoDay + 7) % 7;
|
|
1266
|
+
day = lastMatch + 7 * (ord + 1);
|
|
1267
|
+
}
|
|
1268
|
+
if (day >= 1 && day <= lastDay) {
|
|
1269
|
+
byDayHits.add(day);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
let finalDays = [...byDayHits].sort((a, b) => a - b);
|
|
1274
|
+
if (byMonthDay && byMonthDay.length > 0) {
|
|
1275
|
+
if (byMonthDayHits.length === 0) {
|
|
1276
|
+
return [];
|
|
1277
|
+
}
|
|
1278
|
+
const byMonthDayHitSet = new Set(byMonthDayHits);
|
|
1279
|
+
finalDays = finalDays.filter((d) => byMonthDayHitSet.has(d));
|
|
1280
|
+
}
|
|
1281
|
+
return finalDays;
|
|
1282
|
+
}
|
|
1283
|
+
generateMonthlyOccurrencesOptimizedBySetPos(sample) {
|
|
1284
|
+
if (!this.opts.bySetPos || !this.hasSingleExpandedTimeSlot()) {
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
|
|
1288
|
+
const days = this.generateMonthlyOccurrenceDays(monthStart);
|
|
1289
|
+
if (days.length === 0) {
|
|
1290
|
+
return [];
|
|
1291
|
+
}
|
|
1292
|
+
const selectedDays = this.applyBySetPosToSortedList(days);
|
|
1293
|
+
if (selectedDays.length === 0) {
|
|
1294
|
+
return [];
|
|
1295
|
+
}
|
|
1296
|
+
return selectedDays.sort((a, b) => a - b).map((day) => this.buildMonthlyOccurrenceOnDay(monthStart, day));
|
|
1297
|
+
}
|
|
1298
|
+
isGregorianLeapYear(year) {
|
|
1299
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
1300
|
+
}
|
|
1301
|
+
daysInGregorianMonth(year, month) {
|
|
1302
|
+
if (month === 2 && this.isGregorianLeapYear(year)) {
|
|
1303
|
+
return 29;
|
|
1304
|
+
}
|
|
1305
|
+
return GREGORIAN_MONTH_LENGTHS[month - 1];
|
|
1306
|
+
}
|
|
1307
|
+
gregorianIsoDayOfWeek(year, month, day) {
|
|
1308
|
+
let adjustedYear = year;
|
|
1309
|
+
if (month < 3) adjustedYear -= 1;
|
|
1310
|
+
const sundayZero = (adjustedYear + Math.floor(adjustedYear / 4) - Math.floor(adjustedYear / 100) + Math.floor(adjustedYear / 400) + GREGORIAN_WEEKDAY_OFFSETS[month - 1] + day) % 7;
|
|
1311
|
+
return sundayZero === 0 ? 7 : sundayZero;
|
|
1312
|
+
}
|
|
1313
|
+
monthIndexToYearMonth(monthIndex) {
|
|
1314
|
+
const year = Math.floor(monthIndex / 12);
|
|
1315
|
+
return {
|
|
1316
|
+
year,
|
|
1317
|
+
month: monthIndex - year * 12 + 1
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
generateMonthlyOccurrenceDaysUtc(year, month) {
|
|
1321
|
+
if (this.numericByMonths && this.numericByMonths.length > 0 && !this.numericByMonths.includes(month)) {
|
|
1322
|
+
return [];
|
|
1323
|
+
}
|
|
1324
|
+
const byMonthDay = this.opts.byMonthDay;
|
|
1325
|
+
const byDay = this.opts.byDay;
|
|
1326
|
+
const lastDay = this.daysInGregorianMonth(year, month);
|
|
1327
|
+
let byMonthDayHits = [];
|
|
1328
|
+
if (byMonthDay && byMonthDay.length > 0) {
|
|
1329
|
+
byMonthDayHits = byMonthDay.map((day) => day > 0 ? day : lastDay + day + 1).filter((day) => day >= 1 && day <= lastDay);
|
|
1330
|
+
byMonthDayHits = [...new Set(byMonthDayHits)].sort((a, b) => a - b);
|
|
1331
|
+
}
|
|
1332
|
+
if (!byDay && byMonthDay && byMonthDay.length > 0) {
|
|
1333
|
+
return byMonthDayHits;
|
|
1334
|
+
}
|
|
1335
|
+
if (!byDay) {
|
|
1336
|
+
const day = this.originalDtstart.day;
|
|
1337
|
+
return day >= 1 && day <= lastDay ? [day] : [];
|
|
1338
|
+
}
|
|
1339
|
+
const tokens = this.parsedByDayTokens;
|
|
1340
|
+
if (!(tokens == null ? void 0 : tokens.length)) return [];
|
|
1341
|
+
const firstDayOfWeek = this.gregorianIsoDayOfWeek(year, month, 1);
|
|
1342
|
+
const lastDayOfWeek = addIsoDays(firstDayOfWeek, lastDay - 1);
|
|
1343
|
+
const byDayHits = /* @__PURE__ */ new Set();
|
|
1344
|
+
for (const { ord, isoDay } of tokens) {
|
|
1345
|
+
if (ord === 0) {
|
|
1346
|
+
let day = 1 + (isoDay - firstDayOfWeek + 7) % 7;
|
|
1347
|
+
while (day <= lastDay) {
|
|
1348
|
+
byDayHits.add(day);
|
|
1349
|
+
day += 7;
|
|
1350
|
+
}
|
|
1351
|
+
} else {
|
|
1352
|
+
let day;
|
|
1353
|
+
if (ord > 0) {
|
|
1354
|
+
day = 1 + (isoDay - firstDayOfWeek + 7) % 7 + 7 * (ord - 1);
|
|
1355
|
+
} else {
|
|
1356
|
+
const lastMatch = lastDay - (lastDayOfWeek - isoDay + 7) % 7;
|
|
1357
|
+
day = lastMatch + 7 * (ord + 1);
|
|
1358
|
+
}
|
|
1359
|
+
if (day >= 1 && day <= lastDay) {
|
|
1360
|
+
byDayHits.add(day);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
let finalDays = [...byDayHits].sort((a, b) => a - b);
|
|
1365
|
+
if (byMonthDay && byMonthDay.length > 0) {
|
|
1366
|
+
if (byMonthDayHits.length === 0) return [];
|
|
1367
|
+
const byMonthDayHitSet = new Set(byMonthDayHits);
|
|
1368
|
+
finalDays = finalDays.filter((day) => byMonthDayHitSet.has(day));
|
|
1369
|
+
}
|
|
1370
|
+
return finalDays;
|
|
1371
|
+
}
|
|
1372
|
+
generateMonthlyOccurrenceEpochsUtc(year, month) {
|
|
1373
|
+
var _a;
|
|
1374
|
+
const days = this.generateMonthlyOccurrenceDaysUtc(year, month);
|
|
1375
|
+
if (days.length === 0) return [];
|
|
1376
|
+
const monthStartMs = Date.UTC(year, month - 1, 1, 0, 0, 0, 0);
|
|
1377
|
+
const timeSlotOffsets = (_a = this.timeSlotOffsetsMs) != null ? _a : [0];
|
|
1378
|
+
if (this.opts.bySetPos && this.opts.bySetPos.length > 0) {
|
|
1379
|
+
if (timeSlotOffsets.length === 1) {
|
|
1380
|
+
const selectedDays = this.applyBySetPosToSortedList(days).sort((a, b) => a - b);
|
|
1381
|
+
const offset = timeSlotOffsets[0];
|
|
1382
|
+
return selectedDays.map((day) => monthStartMs + (day - 1) * MS_PER_DAY + offset);
|
|
1383
|
+
}
|
|
1384
|
+
const timestamps2 = [];
|
|
1385
|
+
for (const day of days) {
|
|
1386
|
+
const dayBase = monthStartMs + (day - 1) * MS_PER_DAY;
|
|
1387
|
+
for (const offset of timeSlotOffsets) {
|
|
1388
|
+
timestamps2.push(dayBase + offset);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
return this.applyBySetPosToSortedList(timestamps2).sort((a, b) => a - b);
|
|
1392
|
+
}
|
|
1393
|
+
const timestamps = [];
|
|
1394
|
+
for (const day of days) {
|
|
1395
|
+
const dayBase = monthStartMs + (day - 1) * MS_PER_DAY;
|
|
1396
|
+
for (const offset of timeSlotOffsets) {
|
|
1397
|
+
timestamps.push(dayBase + offset);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
return timestamps;
|
|
1401
|
+
}
|
|
1402
|
+
_allUtcMonthlyByDayOrMonthDay() {
|
|
1403
|
+
var _a;
|
|
1404
|
+
const dates = [];
|
|
1405
|
+
const startMilliseconds = this.originalDtstart.epochMilliseconds;
|
|
1406
|
+
const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
|
|
1407
|
+
let iterationCount = 0;
|
|
1408
|
+
if (!this.addDtstartIfNeeded(dates)) {
|
|
1409
|
+
return dates;
|
|
1410
|
+
}
|
|
1411
|
+
let monthIndex = this.originalDtstart.year * 12 + (this.originalDtstart.month - 1);
|
|
1412
|
+
while (true) {
|
|
1413
|
+
if (++iterationCount > this.maxIterations) {
|
|
1414
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
1415
|
+
}
|
|
1416
|
+
const { year, month } = this.monthIndexToYearMonth(monthIndex);
|
|
1417
|
+
const occurrenceEpochs = this.generateMonthlyOccurrenceEpochsUtc(year, month);
|
|
1418
|
+
for (const epochMilliseconds of occurrenceEpochs) {
|
|
1419
|
+
if (epochMilliseconds < startMilliseconds) {
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
if (untilMilliseconds !== void 0 && epochMilliseconds > untilMilliseconds) {
|
|
1423
|
+
return dates;
|
|
1424
|
+
}
|
|
1425
|
+
dates.push(this.utcZdtFromEpochMilliseconds(epochMilliseconds));
|
|
1426
|
+
if (this.shouldBreakForCountLimit(dates.length)) {
|
|
1427
|
+
return dates;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
monthIndex += this.opts.interval;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
904
1433
|
processOccurrences(occs, dates, start, iterator, extraFilters) {
|
|
905
1434
|
let shouldBreak = false;
|
|
906
1435
|
for (const occ of occs) {
|
|
@@ -944,8 +1473,11 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
944
1473
|
if (++iterationCount > this.maxIterations) {
|
|
945
1474
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
946
1475
|
}
|
|
947
|
-
let occs = this.
|
|
948
|
-
|
|
1476
|
+
let occs = this.generateMonthlyOccurrencesOptimizedBySetPos(monthCursor);
|
|
1477
|
+
if (!occs) {
|
|
1478
|
+
occs = this.generateMonthlyOccurrences(monthCursor);
|
|
1479
|
+
occs = this.applyBySetPos(occs);
|
|
1480
|
+
}
|
|
949
1481
|
const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
|
|
950
1482
|
if (shouldBreak) {
|
|
951
1483
|
break;
|
|
@@ -955,7 +1487,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
955
1487
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
956
1488
|
}
|
|
957
1489
|
_allWeekly(iterator) {
|
|
958
|
-
var _a, _b;
|
|
1490
|
+
var _a, _b, _c;
|
|
959
1491
|
const dates = [];
|
|
960
1492
|
let iterationCount = 0;
|
|
961
1493
|
const start = this.originalDtstart;
|
|
@@ -963,15 +1495,14 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
963
1495
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
964
1496
|
}
|
|
965
1497
|
const dayMap = weekdayToIsoDay;
|
|
966
|
-
const
|
|
967
|
-
const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
1498
|
+
const dows = this.opts.byDay ? [...(_a = this.allByDayIsoDays) != null ? _a : []] : this.opts.byMonthDay && this.opts.byMonthDay.length > 0 ? [...Object.values(dayMap)] : [start.dayOfWeek];
|
|
968
1499
|
const firstWeekDates = dows.map((dw) => {
|
|
969
1500
|
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
970
1501
|
return start.add({ days: delta });
|
|
971
1502
|
});
|
|
972
1503
|
const firstOccurrence = firstWeekDates.reduce((a, b) => Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
973
|
-
const wkstToken = (
|
|
974
|
-
const wkstDay = (
|
|
1504
|
+
const wkstToken = (_b = extractWeekdayToken(this.opts.wkst || "MO")) != null ? _b : "MO";
|
|
1505
|
+
const wkstDay = (_c = dayMap[wkstToken]) != null ? _c : 1;
|
|
975
1506
|
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
976
1507
|
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
977
1508
|
while (true) {
|
|
@@ -1370,6 +1901,10 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1370
1901
|
if (!this.opts.count && !this.opts.until && !iterator) {
|
|
1371
1902
|
throw new Error("all() requires iterator when no COUNT/UNTIL");
|
|
1372
1903
|
}
|
|
1904
|
+
const utcFastPathDates = this.allUtcFastPath(iterator);
|
|
1905
|
+
if (utcFastPathDates) {
|
|
1906
|
+
return utcFastPathDates;
|
|
1907
|
+
}
|
|
1373
1908
|
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay) && !this.opts.byWeekNo) {
|
|
1374
1909
|
return this._allMonthlyByDayOrMonthDay(iterator);
|
|
1375
1910
|
}
|
|
@@ -1773,58 +2308,14 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1773
2308
|
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
1774
2309
|
*/
|
|
1775
2310
|
generateMonthlyOccurrences(sample) {
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
if (byMonth && !byMonth.includes(sample.month)) return [];
|
|
1779
|
-
const lastDay = sample.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
|
|
1780
|
-
let byMonthDayHits = [];
|
|
1781
|
-
if (byMonthDay && byMonthDay.length > 0) {
|
|
1782
|
-
byMonthDayHits = byMonthDay.map((d) => d > 0 ? d : lastDay + d + 1).filter((d) => d >= 1 && d <= lastDay);
|
|
1783
|
-
}
|
|
1784
|
-
if (!byDay && byMonthDay && byMonthDay.length > 0) {
|
|
1785
|
-
if (byMonthDayHits.length === 0) {
|
|
1786
|
-
return [];
|
|
1787
|
-
}
|
|
1788
|
-
const dates = byMonthDayHits.map((d) => sample.with({ day: d }));
|
|
1789
|
-
return dates.flatMap((z) => this.expandByTime(z)).sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
1790
|
-
}
|
|
1791
|
-
if (!byDay) {
|
|
2311
|
+
const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
|
|
2312
|
+
if (!this.opts.byDay && !this.opts.byMonthDay) {
|
|
1792
2313
|
return this.expandByTime(sample);
|
|
1793
2314
|
}
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
return { ord: parsed.ord, wd: dayMap[parsed.weekday] };
|
|
1799
|
-
}).filter((x) => x !== null);
|
|
1800
|
-
const buckets = {};
|
|
1801
|
-
let cursor = sample.with({ day: 1 });
|
|
1802
|
-
while (cursor.month === sample.month) {
|
|
1803
|
-
const dow = cursor.dayOfWeek;
|
|
1804
|
-
(buckets[dow] || (buckets[dow] = [])).push(cursor.day);
|
|
1805
|
-
cursor = cursor.add({ days: 1 });
|
|
1806
|
-
}
|
|
1807
|
-
const byDayHits = [];
|
|
1808
|
-
for (const { ord, wd } of tokens) {
|
|
1809
|
-
const list = (_a = buckets[wd]) != null ? _a : [];
|
|
1810
|
-
if (!list.length) continue;
|
|
1811
|
-
if (ord === 0) {
|
|
1812
|
-
for (const d of list) byDayHits.push(d);
|
|
1813
|
-
} else {
|
|
1814
|
-
const idx = ord > 0 ? ord - 1 : list.length + ord;
|
|
1815
|
-
const dayN = list[idx];
|
|
1816
|
-
if (dayN) byDayHits.push(dayN);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
let finalDays = byDayHits;
|
|
1820
|
-
if (byMonthDay && byMonthDay.length > 0) {
|
|
1821
|
-
if (byMonthDayHits.length === 0) {
|
|
1822
|
-
return [];
|
|
1823
|
-
}
|
|
1824
|
-
finalDays = finalDays.filter((d) => byMonthDayHits.includes(d));
|
|
1825
|
-
}
|
|
1826
|
-
const hits = finalDays.map((d) => sample.with({ day: d }));
|
|
1827
|
-
return hits.flatMap((z) => this.expandByTime(z)).sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
2315
|
+
const finalDays = this.generateMonthlyOccurrenceDays(monthStart);
|
|
2316
|
+
if (finalDays.length === 0) return [];
|
|
2317
|
+
const hits = finalDays.map((d) => monthStart.with({ day: d }));
|
|
2318
|
+
return hits.flatMap((z) => this.expandByTime(z));
|
|
1828
2319
|
}
|
|
1829
2320
|
/**
|
|
1830
2321
|
* Given any date in a year, return all ZonedDateTimes in that year matching
|
|
@@ -2020,9 +2511,11 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2020
2511
|
return current;
|
|
2021
2512
|
}
|
|
2022
2513
|
if (this.opts.byDay && !this.matchesByDay(current)) {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2514
|
+
const targetDays = this.allByDayIsoDays;
|
|
2515
|
+
if (!(targetDays == null ? void 0 : targetDays.length)) {
|
|
2516
|
+
return this.applyTimeOverride(current.add({ days: 1 }).with({ hour: 0, minute: 0, second: 0 }));
|
|
2517
|
+
}
|
|
2518
|
+
const nextDayOfWeek = this.findNextValidValue(current.dayOfWeek, targetDays, (a, b) => a - b);
|
|
2026
2519
|
if (nextDayOfWeek) {
|
|
2027
2520
|
const delta = (nextDayOfWeek - current.dayOfWeek + 7) % 7;
|
|
2028
2521
|
current = current.add({ days: delta }).with({ hour: 0, minute: 0, second: 0 });
|
|
@@ -2056,12 +2549,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2056
2549
|
const { bySetPos } = this.opts;
|
|
2057
2550
|
if (!bySetPos || !bySetPos.length) return list;
|
|
2058
2551
|
const sorted = [...list].sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
2059
|
-
const out =
|
|
2060
|
-
const len = sorted.length;
|
|
2061
|
-
for (const pos of bySetPos) {
|
|
2062
|
-
const idx = pos > 0 ? pos - 1 : len + pos;
|
|
2063
|
-
if (idx >= 0 && idx < len) out.push(sorted[idx]);
|
|
2064
|
-
}
|
|
2552
|
+
const out = this.applyBySetPosToSortedList(sorted);
|
|
2065
2553
|
return out.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
|
|
2066
2554
|
}
|
|
2067
2555
|
isoWeekByDay(sample) {
|