rrule-temporal 1.4.6 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -49,10 +49,58 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
49
49
  // src/index.ts
50
50
  var index_exports = {};
51
51
  __export(index_exports, {
52
- RRuleTemporal: () => RRuleTemporal
52
+ RRuleTemporal: () => RRuleTemporal,
53
+ allowedFreq: () => allowedFreq,
54
+ allowedWeekdays: () => allowedWeekdays,
55
+ weekdayToIsoDay: () => weekdayToIsoDay
53
56
  });
54
57
  module.exports = __toCommonJS(index_exports);
55
58
  var import_polyfill = require("@js-temporal/polyfill");
59
+ var allowedFreq = ["YEARLY", "MONTHLY", "WEEKLY", "DAILY", "HOURLY", "MINUTELY", "SECONDLY"];
60
+ var allowedWeekdays = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
61
+ var weekdayToIsoDay = {
62
+ MO: 1,
63
+ TU: 2,
64
+ WE: 3,
65
+ TH: 4,
66
+ FR: 5,
67
+ SA: 6,
68
+ SU: 7
69
+ };
70
+ var allowedFreqSet = new Set(allowedFreq);
71
+ var allowedWeekdaysSet = new Set(allowedWeekdays);
72
+ var byDayTokenRegex = new RegExp(`^([+-]?\\d{1,2})?(${allowedWeekdays.join("|")})$`);
73
+ var byDayWeekdaySuffixRegex = new RegExp(`(${allowedWeekdays.join("|")})$`);
74
+ var MS_PER_SECOND = 1e3;
75
+ var MS_PER_MINUTE = 60 * MS_PER_SECOND;
76
+ var MS_PER_HOUR = 60 * MS_PER_MINUTE;
77
+ var MS_PER_DAY = 24 * MS_PER_HOUR;
78
+ var MS_PER_WEEK = 7 * MS_PER_DAY;
79
+ var GREGORIAN_MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
80
+ var GREGORIAN_WEEKDAY_OFFSETS = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
81
+ var NS_PER_MILLISECOND = BigInt(1e6);
82
+ var NS_PER_SECOND = BigInt(1e9);
83
+ var NS_PER_MINUTE = BigInt(60) * NS_PER_SECOND;
84
+ var NS_PER_HOUR = BigInt(60) * NS_PER_MINUTE;
85
+ var NS_PER_DAY = BigInt(24) * NS_PER_HOUR;
86
+ var NS_PER_WEEK = BigInt(7) * NS_PER_DAY;
87
+ function addIsoDays(dayOfWeek, deltaDays) {
88
+ return (dayOfWeek - 1 + deltaDays % 7 + 7) % 7 + 1;
89
+ }
90
+ function extractWeekdayToken(token) {
91
+ const m = token.toUpperCase().match(byDayWeekdaySuffixRegex);
92
+ const weekday = m == null ? void 0 : m[1];
93
+ if (!weekday || !allowedWeekdaysSet.has(weekday)) return null;
94
+ return weekday;
95
+ }
96
+ function parseByDayToken(token) {
97
+ const m = token.toUpperCase().match(byDayTokenRegex);
98
+ if (!m) return null;
99
+ const ord = m[1] ? parseInt(m[1], 10) : 0;
100
+ const weekday = m[2];
101
+ if (!weekday || !allowedWeekdaysSet.has(weekday)) return null;
102
+ return { ord, weekday };
103
+ }
56
104
  function isIcsOpts(opts) {
57
105
  return typeof opts.rruleString === "string";
58
106
  }
@@ -226,7 +274,7 @@ function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
226
274
  opts.bySecond = parseNumberArray(val, true);
227
275
  break;
228
276
  case "BYDAY":
229
- opts.byDay = val.split(",");
277
+ opts.byDay = val.split(",").map((token) => token.toUpperCase());
230
278
  break;
231
279
  case "BYMONTH":
232
280
  opts.byMonth = parseByMonthArray(val);
@@ -244,7 +292,7 @@ function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
244
292
  opts.bySetPos = parseNumberArray(val);
245
293
  break;
246
294
  case "WKST":
247
- opts.wkst = val;
295
+ opts.wkst = val == null ? void 0 : val.toUpperCase();
248
296
  break;
249
297
  }
250
298
  }
@@ -265,7 +313,7 @@ var _RRuleTemporal = class _RRuleTemporal {
265
313
  return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
266
314
  }
267
315
  constructor(params) {
268
- var _a, _b, _c, _d, _e, _f, _g, _h;
316
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
269
317
  let manual;
270
318
  if (isIcsOpts(params)) {
271
319
  const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
@@ -306,6 +354,32 @@ var _RRuleTemporal = class _RRuleTemporal {
306
354
  this.opts = this.sanitizeOpts(manual);
307
355
  this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
308
356
  this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
357
+ this.parsedByDayTokens = this.buildParsedByDayTokens(this.opts.byDay);
358
+ this.simpleByDayIsoDays = this.buildByDayIsoDays(this.parsedByDayTokens, false);
359
+ this.allByDayIsoDays = this.buildByDayIsoDays(this.parsedByDayTokens, true);
360
+ this.hasOrdinalByDay = (_j = (_i = this.parsedByDayTokens) == null ? void 0 : _i.some((token) => token.ord !== 0)) != null ? _j : false;
361
+ this.canUseEpochMillisecondsPrecisionFlag = this.originalDtstart.microsecond === 0 && this.originalDtstart.nanosecond === 0 && (!this.opts.until || this.opts.until.microsecond === 0 && this.opts.until.nanosecond === 0);
362
+ this.timeSlotOffsetsMs = this.buildTimeSlotOffsetsMs();
363
+ this.numericByMonths = (_k = this.opts.byMonth) == null ? void 0 : _k.filter((value) => typeof value === "number");
364
+ }
365
+ buildParsedByDayTokens(byDay) {
366
+ if (!(byDay == null ? void 0 : byDay.length)) return void 0;
367
+ const tokens = byDay.map((tok) => {
368
+ const parsed = parseByDayToken(tok);
369
+ if (!parsed) return null;
370
+ return {
371
+ ord: parsed.ord,
372
+ weekday: parsed.weekday,
373
+ isoDay: weekdayToIsoDay[parsed.weekday]
374
+ };
375
+ }).filter((token) => token !== null);
376
+ return tokens.length > 0 ? tokens : void 0;
377
+ }
378
+ buildByDayIsoDays(tokens, includeOrdinals) {
379
+ if (!(tokens == null ? void 0 : tokens.length)) return void 0;
380
+ const isoDays = tokens.filter((token) => includeOrdinals || token.ord === 0).map((token) => token.isoDay);
381
+ if (!isoDays.length) return void 0;
382
+ return [...new Set(isoDays)].sort((a, b) => a - b);
309
383
  }
310
384
  sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
311
385
  if (!arr) return void 0;
@@ -314,22 +388,20 @@ var _RRuleTemporal = class _RRuleTemporal {
314
388
  return sort ? sanitized.sort((a, b) => a - b) : sanitized;
315
389
  }
316
390
  sanitizeByDay(byDay) {
317
- const validDay = /^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/;
318
- const days = (byDay != null ? byDay : []).filter((day) => day && typeof day === "string");
391
+ const days = (byDay != null ? byDay : []).filter((day) => Boolean(day) && typeof day === "string");
392
+ const normalized = [];
319
393
  for (const day of days) {
320
- const match = day.match(validDay);
321
- if (!match) {
394
+ const token = day.toUpperCase();
395
+ const parsed = parseByDayToken(token);
396
+ if (!parsed) {
322
397
  throw new Error(`Invalid BYDAY value: ${day}`);
323
398
  }
324
- const ord = match[1];
325
- if (ord) {
326
- const ordInt = parseInt(ord, 10);
327
- if (ordInt === 0) {
328
- throw new Error(`Invalid BYDAY value: ${day}`);
329
- }
399
+ if (parsed.ord === 0 && /^[+-]?\d/.test(token)) {
400
+ throw new Error(`Invalid BYDAY value: ${day}`);
330
401
  }
402
+ normalized.push(token);
331
403
  }
332
- return days.length > 0 ? days : void 0;
404
+ return normalized.length > 0 ? normalized : void 0;
333
405
  }
334
406
  enforceStrictRfc(opts) {
335
407
  var _a;
@@ -360,7 +432,17 @@ var _RRuleTemporal = class _RRuleTemporal {
360
432
  }
361
433
  sanitizeOpts(opts) {
362
434
  var _a;
435
+ if (!allowedFreqSet.has(opts.freq)) {
436
+ throw new Error(`Invalid FREQ value: ${opts.freq}`);
437
+ }
363
438
  opts.byDay = this.sanitizeByDay(opts.byDay);
439
+ if (opts.wkst) {
440
+ const wkst = opts.wkst.toUpperCase();
441
+ if (!allowedWeekdaysSet.has(wkst)) {
442
+ throw new Error(`Invalid WKST value: ${opts.wkst}`);
443
+ }
444
+ opts.wkst = wkst;
445
+ }
364
446
  if (opts.byMonth) {
365
447
  const numeric = opts.byMonth.filter((v) => typeof v === "number");
366
448
  const stringy = opts.byMonth.filter((v) => typeof v === "string");
@@ -419,9 +501,21 @@ var _RRuleTemporal = class _RRuleTemporal {
419
501
  */
420
502
  expandByTime(base) {
421
503
  var _a, _b, _c;
504
+ if (!this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond) {
505
+ return [base];
506
+ }
422
507
  const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
423
508
  const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
424
509
  const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
510
+ if (hours.length === 1 && minutes.length === 1 && seconds.length === 1) {
511
+ const hour = hours[0];
512
+ const minute = minutes[0];
513
+ const second = seconds[0];
514
+ if (hour === base.hour && minute === base.minute && second === base.second) {
515
+ return [base];
516
+ }
517
+ return [base.with({ hour, minute, second })];
518
+ }
425
519
  const out = [];
426
520
  for (const h of hours) {
427
521
  for (const m of minutes) {
@@ -575,11 +669,8 @@ var _RRuleTemporal = class _RRuleTemporal {
575
669
  weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: lastWeek + targetWeek });
576
670
  }
577
671
  if ((_b = this.opts.byDay) == null ? void 0 : _b.length) {
578
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
579
- const targetDays = this.opts.byDay.map((tok) => {
580
- var _a2;
581
- return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
582
- }).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
672
+ const dayMap = weekdayToIsoDay;
673
+ const targetDays = this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null).map((day) => dayMap[day]).filter(Boolean);
583
674
  if (targetDays.length) {
584
675
  const candidates = targetDays.map((dayOfWeek) => {
585
676
  const delta = (dayOfWeek - weekStart.dayOfWeek + 7) % 7;
@@ -602,7 +693,7 @@ var _RRuleTemporal = class _RRuleTemporal {
602
693
  }
603
694
  }
604
695
  if (((_c = this.opts.byDay) == null ? void 0 : _c.length) && !this.opts.byWeekNo) {
605
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
696
+ const dayMap = weekdayToIsoDay;
606
697
  const hasOrdinalTokens = this.opts.byDay.some((tok) => /^[+-]?\d/.test(tok));
607
698
  if (hasOrdinalTokens && this.opts.byMonth && (this.opts.freq === "MINUTELY" || this.opts.freq === "SECONDLY")) {
608
699
  const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
@@ -628,14 +719,11 @@ var _RRuleTemporal = class _RRuleTemporal {
628
719
  }
629
720
  } else {
630
721
  let deltas;
631
- if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && this.opts.byDay.every((tok) => /^[A-Z]{2}$/.test(tok))) {
632
- deltas = this.opts.byDay.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
722
+ const weekdayTokens = this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((tok) => tok !== null);
723
+ if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && weekdayTokens.length === this.opts.byDay.length) {
724
+ deltas = weekdayTokens.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
633
725
  } else {
634
- deltas = this.opts.byDay.map((tok) => {
635
- var _a2;
636
- const wdTok = (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
637
- return wdTok ? (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7 : null;
638
- }).filter((d) => d !== null);
726
+ deltas = weekdayTokens.map((wdTok) => (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7);
639
727
  }
640
728
  if (deltas.length) {
641
729
  zdt = zdt.add({ days: Math.min(...deltas) });
@@ -675,32 +763,26 @@ var _RRuleTemporal = class _RRuleTemporal {
675
763
  // --- NEW: constraint checks ---
676
764
  // 2) Replace your matchesByDay with this:
677
765
  matchesByDay(zdt) {
766
+ var _a, _b, _c;
678
767
  const { byDay, freq } = this.opts;
679
768
  if (!byDay) return true;
680
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
681
- for (const token of byDay) {
682
- const m = token.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
683
- if (!m) continue;
684
- const ord = m[1] ? parseInt(m[1], 10) : 0;
685
- const weekday = m[2];
686
- if (!weekday) continue;
687
- const wd = dayMap[weekday];
688
- if (freq === "DAILY") {
689
- if (zdt.dayOfWeek === wd) return true;
690
- continue;
691
- }
692
- if (ord === 0) {
693
- if (zdt.dayOfWeek === wd) return true;
769
+ if (!this.hasOrdinalByDay) {
770
+ return (_b = (_a = this.simpleByDayIsoDays) == null ? void 0 : _a.includes(zdt.dayOfWeek)) != null ? _b : false;
771
+ }
772
+ for (const token of (_c = this.parsedByDayTokens) != null ? _c : []) {
773
+ if (freq === "DAILY" && zdt.dayOfWeek === token.isoDay) return true;
774
+ if (token.ord === 0) {
775
+ if (zdt.dayOfWeek === token.isoDay) return true;
694
776
  continue;
695
777
  }
696
778
  const month = zdt.month;
697
779
  let dt = zdt.with({ day: 1 });
698
780
  const candidates = [];
699
781
  while (dt.month === month) {
700
- if (dt.dayOfWeek === wd) candidates.push(dt.day);
782
+ if (dt.dayOfWeek === token.isoDay) candidates.push(dt.day);
701
783
  dt = dt.add({ days: 1 });
702
784
  }
703
- const idx = ord > 0 ? ord - 1 : candidates.length + ord;
785
+ const idx = token.ord > 0 ? token.ord - 1 : candidates.length + token.ord;
704
786
  if (candidates[idx] === zdt.day) return true;
705
787
  }
706
788
  return false;
@@ -893,6 +975,485 @@ var _RRuleTemporal = class _RRuleTemporal {
893
975
  }
894
976
  return true;
895
977
  }
978
+ canUseUtcLinearFastPath(iterator) {
979
+ if (iterator || this.tzid !== "UTC" || this.opts.rscale || this.opts.rDate || this.opts.exDate) {
980
+ return false;
981
+ }
982
+ if (this.opts.byMonth || this.opts.byMonthDay || this.opts.byYearDay || this.opts.byWeekNo || this.opts.bySetPos) {
983
+ return false;
984
+ }
985
+ switch (this.opts.freq) {
986
+ case "DAILY":
987
+ return !this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond && !this.hasOrdinalByDay;
988
+ case "HOURLY":
989
+ case "MINUTELY":
990
+ return !this.opts.byDay && !this.opts.byHour && !this.opts.byMinute && !this.opts.bySecond;
991
+ default:
992
+ return false;
993
+ }
994
+ }
995
+ canUseUtcWeeklyFastPath(iterator) {
996
+ 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;
997
+ }
998
+ canUseUtcMonthlyFastPath(iterator) {
999
+ 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);
1000
+ }
1001
+ utcZdtFromEpochNanoseconds(epochNanoseconds) {
1002
+ return import_polyfill.Temporal.Instant.fromEpochNanoseconds(epochNanoseconds).toZonedDateTimeISO("UTC");
1003
+ }
1004
+ utcZdtFromEpochMilliseconds(epochMilliseconds) {
1005
+ return import_polyfill.Temporal.Instant.fromEpochMilliseconds(epochMilliseconds).toZonedDateTimeISO("UTC");
1006
+ }
1007
+ canUseUtcEpochMillisecondsPrecision() {
1008
+ return this.canUseEpochMillisecondsPrecisionFlag;
1009
+ }
1010
+ buildTimeSlotOffsetsMs() {
1011
+ var _a, _b, _c;
1012
+ if (!this.canUseEpochMillisecondsPrecisionFlag) return void 0;
1013
+ const hours = (_a = this.opts.byHour) != null ? _a : [this.originalDtstart.hour];
1014
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [this.originalDtstart.minute];
1015
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [this.originalDtstart.second];
1016
+ const baseMilliseconds = this.originalDtstart.millisecond;
1017
+ const offsets = [];
1018
+ for (const hour of hours) {
1019
+ for (const minute of minutes) {
1020
+ for (const second of seconds) {
1021
+ offsets.push(((hour * 60 + minute) * 60 + second) * MS_PER_SECOND + baseMilliseconds);
1022
+ }
1023
+ }
1024
+ }
1025
+ return offsets;
1026
+ }
1027
+ findFirstMatchingDailyStep(startDayOfWeek, stepDays, allowedDays) {
1028
+ let dayOfWeek = startDayOfWeek;
1029
+ for (let steps = 0; steps < 7; steps++) {
1030
+ if (allowedDays.includes(dayOfWeek)) {
1031
+ return steps;
1032
+ }
1033
+ dayOfWeek = addIsoDays(dayOfWeek, stepDays);
1034
+ }
1035
+ return null;
1036
+ }
1037
+ allUtcFastPath(iterator) {
1038
+ if (this.canUseUtcLinearFastPath(iterator)) {
1039
+ switch (this.opts.freq) {
1040
+ case "DAILY":
1041
+ return this._allUtcDailySimple();
1042
+ case "HOURLY":
1043
+ return this._allUtcFixedStepSimple(NS_PER_HOUR * BigInt(this.opts.interval));
1044
+ case "MINUTELY":
1045
+ return this._allUtcFixedStepSimple(NS_PER_MINUTE * BigInt(this.opts.interval));
1046
+ }
1047
+ }
1048
+ if (this.canUseUtcMonthlyFastPath(iterator)) {
1049
+ return this._allUtcMonthlyByDayOrMonthDay();
1050
+ }
1051
+ if (this.canUseUtcWeeklyFastPath(iterator)) {
1052
+ return this._allUtcWeeklySimple();
1053
+ }
1054
+ return null;
1055
+ }
1056
+ _allUtcFixedStepSimple(stepNanoseconds) {
1057
+ var _a, _b;
1058
+ const dates = [];
1059
+ if (!this.addDtstartIfNeeded(dates)) {
1060
+ return dates;
1061
+ }
1062
+ let iterationCount = 0;
1063
+ if (this.canUseUtcEpochMillisecondsPrecision()) {
1064
+ let currentMilliseconds = this.originalDtstart.epochMilliseconds;
1065
+ const stepMilliseconds = Number(stepNanoseconds / NS_PER_MILLISECOND);
1066
+ const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
1067
+ while (true) {
1068
+ if (++iterationCount > this.maxIterations) {
1069
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1070
+ }
1071
+ if (untilMilliseconds !== void 0 && currentMilliseconds > untilMilliseconds) {
1072
+ break;
1073
+ }
1074
+ dates.push(this.utcZdtFromEpochMilliseconds(currentMilliseconds));
1075
+ if (this.shouldBreakForCountLimit(dates.length)) {
1076
+ break;
1077
+ }
1078
+ currentMilliseconds += stepMilliseconds;
1079
+ }
1080
+ return dates;
1081
+ }
1082
+ let currentNanoseconds = this.originalDtstart.epochNanoseconds;
1083
+ const untilNanoseconds = (_b = this.opts.until) == null ? void 0 : _b.epochNanoseconds;
1084
+ while (true) {
1085
+ if (++iterationCount > this.maxIterations) {
1086
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1087
+ }
1088
+ if (untilNanoseconds !== void 0 && currentNanoseconds > untilNanoseconds) {
1089
+ break;
1090
+ }
1091
+ dates.push(this.utcZdtFromEpochNanoseconds(currentNanoseconds));
1092
+ if (this.shouldBreakForCountLimit(dates.length)) {
1093
+ break;
1094
+ }
1095
+ currentNanoseconds += stepNanoseconds;
1096
+ }
1097
+ return dates;
1098
+ }
1099
+ _allUtcDailySimple() {
1100
+ var _a, _b;
1101
+ const dates = [];
1102
+ if (!this.addDtstartIfNeeded(dates)) {
1103
+ return dates;
1104
+ }
1105
+ const stepDays = this.opts.interval;
1106
+ const allowedDays = this.simpleByDayIsoDays;
1107
+ let iterationCount = 0;
1108
+ if (this.canUseUtcEpochMillisecondsPrecision()) {
1109
+ const stepMilliseconds = stepDays * MS_PER_DAY;
1110
+ const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
1111
+ let currentMilliseconds = this.originalDtstart.epochMilliseconds;
1112
+ let currentDayOfWeek2 = this.originalDtstart.dayOfWeek;
1113
+ if (allowedDays == null ? void 0 : allowedDays.length) {
1114
+ const firstMatchingStep = this.findFirstMatchingDailyStep(currentDayOfWeek2, stepDays, allowedDays);
1115
+ if (firstMatchingStep === null) {
1116
+ return dates;
1117
+ }
1118
+ currentMilliseconds += firstMatchingStep * stepMilliseconds;
1119
+ currentDayOfWeek2 = addIsoDays(currentDayOfWeek2, firstMatchingStep * stepDays);
1120
+ }
1121
+ while (true) {
1122
+ if (++iterationCount > this.maxIterations) {
1123
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1124
+ }
1125
+ if (untilMilliseconds !== void 0 && currentMilliseconds > untilMilliseconds) {
1126
+ break;
1127
+ }
1128
+ if (!allowedDays || allowedDays.includes(currentDayOfWeek2)) {
1129
+ dates.push(this.utcZdtFromEpochMilliseconds(currentMilliseconds));
1130
+ if (this.shouldBreakForCountLimit(dates.length)) {
1131
+ break;
1132
+ }
1133
+ }
1134
+ currentMilliseconds += stepMilliseconds;
1135
+ currentDayOfWeek2 = addIsoDays(currentDayOfWeek2, stepDays);
1136
+ }
1137
+ return dates;
1138
+ }
1139
+ const stepNanoseconds = BigInt(stepDays) * NS_PER_DAY;
1140
+ const untilNanoseconds = (_b = this.opts.until) == null ? void 0 : _b.epochNanoseconds;
1141
+ let currentNanoseconds = this.originalDtstart.epochNanoseconds;
1142
+ let currentDayOfWeek = this.originalDtstart.dayOfWeek;
1143
+ if (allowedDays == null ? void 0 : allowedDays.length) {
1144
+ const firstMatchingStep = this.findFirstMatchingDailyStep(currentDayOfWeek, stepDays, allowedDays);
1145
+ if (firstMatchingStep === null) {
1146
+ return dates;
1147
+ }
1148
+ currentNanoseconds += BigInt(firstMatchingStep) * stepNanoseconds;
1149
+ currentDayOfWeek = addIsoDays(currentDayOfWeek, firstMatchingStep * stepDays);
1150
+ }
1151
+ while (true) {
1152
+ if (++iterationCount > this.maxIterations) {
1153
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1154
+ }
1155
+ if (untilNanoseconds !== void 0 && currentNanoseconds > untilNanoseconds) {
1156
+ break;
1157
+ }
1158
+ if (!allowedDays || allowedDays.includes(currentDayOfWeek)) {
1159
+ dates.push(this.utcZdtFromEpochNanoseconds(currentNanoseconds));
1160
+ if (this.shouldBreakForCountLimit(dates.length)) {
1161
+ break;
1162
+ }
1163
+ }
1164
+ currentNanoseconds += stepNanoseconds;
1165
+ currentDayOfWeek = addIsoDays(currentDayOfWeek, stepDays);
1166
+ }
1167
+ return dates;
1168
+ }
1169
+ _allUtcWeeklySimple() {
1170
+ var _a, _b, _c, _d, _e;
1171
+ const dates = [];
1172
+ if (!this.addDtstartIfNeeded(dates)) {
1173
+ return dates;
1174
+ }
1175
+ const start = this.originalDtstart;
1176
+ const wkstToken = (_a = extractWeekdayToken(this.opts.wkst || "MO")) != null ? _a : "MO";
1177
+ const wkstDay = (_b = weekdayToIsoDay[wkstToken]) != null ? _b : 1;
1178
+ const targetDays = this.opts.byDay ? [...(_c = this.allByDayIsoDays) != null ? _c : []] : [start.dayOfWeek];
1179
+ const dayOffsets = targetDays.map((day) => (day - wkstDay + 7) % 7).sort((a, b) => a - b);
1180
+ const weekStartOffset = (start.dayOfWeek - wkstDay + 7) % 7;
1181
+ let iterationCount = 0;
1182
+ if (this.canUseUtcEpochMillisecondsPrecision()) {
1183
+ const startMilliseconds = start.epochMilliseconds;
1184
+ const untilMilliseconds = (_d = this.opts.until) == null ? void 0 : _d.epochMilliseconds;
1185
+ const weekStepMilliseconds = this.opts.interval * MS_PER_WEEK;
1186
+ let weekStartMilliseconds = startMilliseconds - weekStartOffset * MS_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 occurrenceMilliseconds = weekStartMilliseconds + dayOffset * MS_PER_DAY;
1193
+ if (occurrenceMilliseconds < startMilliseconds) {
1194
+ continue;
1195
+ }
1196
+ if (untilMilliseconds !== void 0 && occurrenceMilliseconds > untilMilliseconds) {
1197
+ return dates;
1198
+ }
1199
+ dates.push(this.utcZdtFromEpochMilliseconds(occurrenceMilliseconds));
1200
+ if (this.shouldBreakForCountLimit(dates.length)) {
1201
+ return dates;
1202
+ }
1203
+ }
1204
+ weekStartMilliseconds += weekStepMilliseconds;
1205
+ }
1206
+ }
1207
+ const startNanoseconds = start.epochNanoseconds;
1208
+ const untilNanoseconds = (_e = this.opts.until) == null ? void 0 : _e.epochNanoseconds;
1209
+ const weekStepNanoseconds = BigInt(this.opts.interval) * NS_PER_WEEK;
1210
+ let weekStartNanoseconds = startNanoseconds - BigInt(weekStartOffset) * NS_PER_DAY;
1211
+ while (true) {
1212
+ if (++iterationCount > this.maxIterations) {
1213
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1214
+ }
1215
+ for (const dayOffset of dayOffsets) {
1216
+ const occurrenceNanoseconds = weekStartNanoseconds + BigInt(dayOffset) * NS_PER_DAY;
1217
+ if (occurrenceNanoseconds < startNanoseconds) {
1218
+ continue;
1219
+ }
1220
+ if (untilNanoseconds !== void 0 && occurrenceNanoseconds > untilNanoseconds) {
1221
+ return dates;
1222
+ }
1223
+ dates.push(this.utcZdtFromEpochNanoseconds(occurrenceNanoseconds));
1224
+ if (this.shouldBreakForCountLimit(dates.length)) {
1225
+ return dates;
1226
+ }
1227
+ }
1228
+ weekStartNanoseconds += weekStepNanoseconds;
1229
+ }
1230
+ }
1231
+ hasSingleExpandedTimeSlot() {
1232
+ var _a, _b, _c;
1233
+ if (this.timeSlotOffsetsMs) {
1234
+ return this.timeSlotOffsetsMs.length === 1;
1235
+ }
1236
+ const hours = (_a = this.opts.byHour) != null ? _a : [this.originalDtstart.hour];
1237
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [this.originalDtstart.minute];
1238
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [this.originalDtstart.second];
1239
+ return hours.length === 1 && minutes.length === 1 && seconds.length === 1;
1240
+ }
1241
+ buildMonthlyOccurrenceOnDay(monthStart, day) {
1242
+ const base = monthStart.day === day ? monthStart : monthStart.with({ day });
1243
+ return this.applyTimeOverride(base);
1244
+ }
1245
+ applyBySetPosToSortedList(list) {
1246
+ const { bySetPos } = this.opts;
1247
+ if (!bySetPos || !bySetPos.length || list.length === 0) return list;
1248
+ const out = [];
1249
+ const len = list.length;
1250
+ for (const pos of bySetPos) {
1251
+ const idx = pos > 0 ? pos - 1 : len + pos;
1252
+ if (idx >= 0 && idx < len) out.push(list[idx]);
1253
+ }
1254
+ return out;
1255
+ }
1256
+ generateMonthlyOccurrenceDays(sample) {
1257
+ const { byDay, byMonth, byMonthDay } = this.opts;
1258
+ const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
1259
+ if (byMonth && !byMonth.includes(sample.month)) return [];
1260
+ const lastDay = monthStart.add({ months: 1 }).subtract({ days: 1 }).day;
1261
+ let byMonthDayHits = [];
1262
+ if (byMonthDay && byMonthDay.length > 0) {
1263
+ byMonthDayHits = byMonthDay.map((d) => d > 0 ? d : lastDay + d + 1).filter((d) => d >= 1 && d <= lastDay);
1264
+ byMonthDayHits = [...new Set(byMonthDayHits)].sort((a, b) => a - b);
1265
+ }
1266
+ if (!byDay && byMonthDay && byMonthDay.length > 0) {
1267
+ return byMonthDayHits;
1268
+ }
1269
+ if (!byDay) {
1270
+ return [sample.day];
1271
+ }
1272
+ const tokens = this.parsedByDayTokens;
1273
+ if (!(tokens == null ? void 0 : tokens.length)) return [];
1274
+ const firstDayOfWeek = monthStart.dayOfWeek;
1275
+ const lastDayOfWeek = (firstDayOfWeek - 1 + lastDay - 1) % 7 + 1;
1276
+ const byDayHits = /* @__PURE__ */ new Set();
1277
+ for (const { ord, isoDay } of tokens) {
1278
+ if (ord === 0) {
1279
+ let day = 1 + (isoDay - firstDayOfWeek + 7) % 7;
1280
+ while (day <= lastDay) {
1281
+ byDayHits.add(day);
1282
+ day += 7;
1283
+ }
1284
+ } else {
1285
+ let day;
1286
+ if (ord > 0) {
1287
+ day = 1 + (isoDay - firstDayOfWeek + 7) % 7 + 7 * (ord - 1);
1288
+ } else {
1289
+ const lastMatch = lastDay - (lastDayOfWeek - isoDay + 7) % 7;
1290
+ day = lastMatch + 7 * (ord + 1);
1291
+ }
1292
+ if (day >= 1 && day <= lastDay) {
1293
+ byDayHits.add(day);
1294
+ }
1295
+ }
1296
+ }
1297
+ let finalDays = [...byDayHits].sort((a, b) => a - b);
1298
+ if (byMonthDay && byMonthDay.length > 0) {
1299
+ if (byMonthDayHits.length === 0) {
1300
+ return [];
1301
+ }
1302
+ const byMonthDayHitSet = new Set(byMonthDayHits);
1303
+ finalDays = finalDays.filter((d) => byMonthDayHitSet.has(d));
1304
+ }
1305
+ return finalDays;
1306
+ }
1307
+ generateMonthlyOccurrencesOptimizedBySetPos(sample) {
1308
+ if (!this.opts.bySetPos || !this.hasSingleExpandedTimeSlot()) {
1309
+ return null;
1310
+ }
1311
+ const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
1312
+ const days = this.generateMonthlyOccurrenceDays(monthStart);
1313
+ if (days.length === 0) {
1314
+ return [];
1315
+ }
1316
+ const selectedDays = this.applyBySetPosToSortedList(days);
1317
+ if (selectedDays.length === 0) {
1318
+ return [];
1319
+ }
1320
+ return selectedDays.sort((a, b) => a - b).map((day) => this.buildMonthlyOccurrenceOnDay(monthStart, day));
1321
+ }
1322
+ isGregorianLeapYear(year) {
1323
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
1324
+ }
1325
+ daysInGregorianMonth(year, month) {
1326
+ if (month === 2 && this.isGregorianLeapYear(year)) {
1327
+ return 29;
1328
+ }
1329
+ return GREGORIAN_MONTH_LENGTHS[month - 1];
1330
+ }
1331
+ gregorianIsoDayOfWeek(year, month, day) {
1332
+ let adjustedYear = year;
1333
+ if (month < 3) adjustedYear -= 1;
1334
+ const sundayZero = (adjustedYear + Math.floor(adjustedYear / 4) - Math.floor(adjustedYear / 100) + Math.floor(adjustedYear / 400) + GREGORIAN_WEEKDAY_OFFSETS[month - 1] + day) % 7;
1335
+ return sundayZero === 0 ? 7 : sundayZero;
1336
+ }
1337
+ monthIndexToYearMonth(monthIndex) {
1338
+ const year = Math.floor(monthIndex / 12);
1339
+ return {
1340
+ year,
1341
+ month: monthIndex - year * 12 + 1
1342
+ };
1343
+ }
1344
+ generateMonthlyOccurrenceDaysUtc(year, month) {
1345
+ if (this.numericByMonths && this.numericByMonths.length > 0 && !this.numericByMonths.includes(month)) {
1346
+ return [];
1347
+ }
1348
+ const byMonthDay = this.opts.byMonthDay;
1349
+ const byDay = this.opts.byDay;
1350
+ const lastDay = this.daysInGregorianMonth(year, month);
1351
+ let byMonthDayHits = [];
1352
+ if (byMonthDay && byMonthDay.length > 0) {
1353
+ byMonthDayHits = byMonthDay.map((day) => day > 0 ? day : lastDay + day + 1).filter((day) => day >= 1 && day <= lastDay);
1354
+ byMonthDayHits = [...new Set(byMonthDayHits)].sort((a, b) => a - b);
1355
+ }
1356
+ if (!byDay && byMonthDay && byMonthDay.length > 0) {
1357
+ return byMonthDayHits;
1358
+ }
1359
+ if (!byDay) {
1360
+ const day = this.originalDtstart.day;
1361
+ return day >= 1 && day <= lastDay ? [day] : [];
1362
+ }
1363
+ const tokens = this.parsedByDayTokens;
1364
+ if (!(tokens == null ? void 0 : tokens.length)) return [];
1365
+ const firstDayOfWeek = this.gregorianIsoDayOfWeek(year, month, 1);
1366
+ const lastDayOfWeek = addIsoDays(firstDayOfWeek, lastDay - 1);
1367
+ const byDayHits = /* @__PURE__ */ new Set();
1368
+ for (const { ord, isoDay } of tokens) {
1369
+ if (ord === 0) {
1370
+ let day = 1 + (isoDay - firstDayOfWeek + 7) % 7;
1371
+ while (day <= lastDay) {
1372
+ byDayHits.add(day);
1373
+ day += 7;
1374
+ }
1375
+ } else {
1376
+ let day;
1377
+ if (ord > 0) {
1378
+ day = 1 + (isoDay - firstDayOfWeek + 7) % 7 + 7 * (ord - 1);
1379
+ } else {
1380
+ const lastMatch = lastDay - (lastDayOfWeek - isoDay + 7) % 7;
1381
+ day = lastMatch + 7 * (ord + 1);
1382
+ }
1383
+ if (day >= 1 && day <= lastDay) {
1384
+ byDayHits.add(day);
1385
+ }
1386
+ }
1387
+ }
1388
+ let finalDays = [...byDayHits].sort((a, b) => a - b);
1389
+ if (byMonthDay && byMonthDay.length > 0) {
1390
+ if (byMonthDayHits.length === 0) return [];
1391
+ const byMonthDayHitSet = new Set(byMonthDayHits);
1392
+ finalDays = finalDays.filter((day) => byMonthDayHitSet.has(day));
1393
+ }
1394
+ return finalDays;
1395
+ }
1396
+ generateMonthlyOccurrenceEpochsUtc(year, month) {
1397
+ var _a;
1398
+ const days = this.generateMonthlyOccurrenceDaysUtc(year, month);
1399
+ if (days.length === 0) return [];
1400
+ const monthStartMs = Date.UTC(year, month - 1, 1, 0, 0, 0, 0);
1401
+ const timeSlotOffsets = (_a = this.timeSlotOffsetsMs) != null ? _a : [0];
1402
+ if (this.opts.bySetPos && this.opts.bySetPos.length > 0) {
1403
+ if (timeSlotOffsets.length === 1) {
1404
+ const selectedDays = this.applyBySetPosToSortedList(days).sort((a, b) => a - b);
1405
+ const offset = timeSlotOffsets[0];
1406
+ return selectedDays.map((day) => monthStartMs + (day - 1) * MS_PER_DAY + offset);
1407
+ }
1408
+ const timestamps2 = [];
1409
+ for (const day of days) {
1410
+ const dayBase = monthStartMs + (day - 1) * MS_PER_DAY;
1411
+ for (const offset of timeSlotOffsets) {
1412
+ timestamps2.push(dayBase + offset);
1413
+ }
1414
+ }
1415
+ return this.applyBySetPosToSortedList(timestamps2).sort((a, b) => a - b);
1416
+ }
1417
+ const timestamps = [];
1418
+ for (const day of days) {
1419
+ const dayBase = monthStartMs + (day - 1) * MS_PER_DAY;
1420
+ for (const offset of timeSlotOffsets) {
1421
+ timestamps.push(dayBase + offset);
1422
+ }
1423
+ }
1424
+ return timestamps;
1425
+ }
1426
+ _allUtcMonthlyByDayOrMonthDay() {
1427
+ var _a;
1428
+ const dates = [];
1429
+ const startMilliseconds = this.originalDtstart.epochMilliseconds;
1430
+ const untilMilliseconds = (_a = this.opts.until) == null ? void 0 : _a.epochMilliseconds;
1431
+ let iterationCount = 0;
1432
+ if (!this.addDtstartIfNeeded(dates)) {
1433
+ return dates;
1434
+ }
1435
+ let monthIndex = this.originalDtstart.year * 12 + (this.originalDtstart.month - 1);
1436
+ while (true) {
1437
+ if (++iterationCount > this.maxIterations) {
1438
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1439
+ }
1440
+ const { year, month } = this.monthIndexToYearMonth(monthIndex);
1441
+ const occurrenceEpochs = this.generateMonthlyOccurrenceEpochsUtc(year, month);
1442
+ for (const epochMilliseconds of occurrenceEpochs) {
1443
+ if (epochMilliseconds < startMilliseconds) {
1444
+ continue;
1445
+ }
1446
+ if (untilMilliseconds !== void 0 && epochMilliseconds > untilMilliseconds) {
1447
+ return dates;
1448
+ }
1449
+ dates.push(this.utcZdtFromEpochMilliseconds(epochMilliseconds));
1450
+ if (this.shouldBreakForCountLimit(dates.length)) {
1451
+ return dates;
1452
+ }
1453
+ }
1454
+ monthIndex += this.opts.interval;
1455
+ }
1456
+ }
896
1457
  processOccurrences(occs, dates, start, iterator, extraFilters) {
897
1458
  let shouldBreak = false;
898
1459
  for (const occ of occs) {
@@ -936,11 +1497,10 @@ var _RRuleTemporal = class _RRuleTemporal {
936
1497
  if (++iterationCount > this.maxIterations) {
937
1498
  throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
938
1499
  }
939
- let occs = this.generateMonthlyOccurrences(monthCursor);
940
- occs = this.applyBySetPos(occs);
941
- 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)) {
942
- monthCursor = monthCursor.add({ months: this.opts.interval });
943
- continue;
1500
+ let occs = this.generateMonthlyOccurrencesOptimizedBySetPos(monthCursor);
1501
+ if (!occs) {
1502
+ occs = this.generateMonthlyOccurrences(monthCursor);
1503
+ occs = this.applyBySetPos(occs);
944
1504
  }
945
1505
  const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
946
1506
  if (shouldBreak) {
@@ -951,22 +1511,22 @@ var _RRuleTemporal = class _RRuleTemporal {
951
1511
  return this.applyCountLimitAndMergeRDates(dates, iterator);
952
1512
  }
953
1513
  _allWeekly(iterator) {
954
- var _a;
1514
+ var _a, _b, _c;
955
1515
  const dates = [];
956
1516
  let iterationCount = 0;
957
1517
  const start = this.originalDtstart;
958
1518
  if (!this.addDtstartIfNeeded(dates, iterator)) {
959
1519
  return this.applyCountLimitAndMergeRDates(dates, iterator);
960
1520
  }
961
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
962
- 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]];
963
- const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
1521
+ const dayMap = weekdayToIsoDay;
1522
+ const dows = this.opts.byDay ? [...(_a = this.allByDayIsoDays) != null ? _a : []] : this.opts.byMonthDay && this.opts.byMonthDay.length > 0 ? [...Object.values(dayMap)] : [start.dayOfWeek];
964
1523
  const firstWeekDates = dows.map((dw) => {
965
1524
  const delta = (dw - start.dayOfWeek + 7) % 7;
966
1525
  return start.add({ days: delta });
967
1526
  });
968
1527
  const firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
969
- const wkstDay = (_a = dayMap[this.opts.wkst || "MO"]) != null ? _a : 1;
1528
+ const wkstToken = (_b = extractWeekdayToken(this.opts.wkst || "MO")) != null ? _b : "MO";
1529
+ const wkstDay = (_c = dayMap[wkstToken]) != null ? _c : 1;
970
1530
  const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
971
1531
  let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
972
1532
  while (true) {
@@ -1365,6 +1925,10 @@ var _RRuleTemporal = class _RRuleTemporal {
1365
1925
  if (!this.opts.count && !this.opts.until && !iterator) {
1366
1926
  throw new Error("all() requires iterator when no COUNT/UNTIL");
1367
1927
  }
1928
+ const utcFastPathDates = this.allUtcFastPath(iterator);
1929
+ if (utcFastPathDates) {
1930
+ return utcFastPathDates;
1931
+ }
1368
1932
  if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay) && !this.opts.byWeekNo) {
1369
1933
  return this._allMonthlyByDayOrMonthDay(iterator);
1370
1934
  }
@@ -1768,58 +2332,14 @@ var _RRuleTemporal = class _RRuleTemporal {
1768
2332
  * matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
1769
2333
  */
1770
2334
  generateMonthlyOccurrences(sample) {
1771
- var _a;
1772
- const { byDay, byMonth, byMonthDay } = this.opts;
1773
- if (byMonth && !byMonth.includes(sample.month)) return [];
1774
- const lastDay = sample.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
1775
- let byMonthDayHits = [];
1776
- if (byMonthDay && byMonthDay.length > 0) {
1777
- byMonthDayHits = byMonthDay.map((d) => d > 0 ? d : lastDay + d + 1).filter((d) => d >= 1 && d <= lastDay);
1778
- }
1779
- if (!byDay && byMonthDay && byMonthDay.length > 0) {
1780
- if (byMonthDayHits.length === 0) {
1781
- return [];
1782
- }
1783
- const dates = byMonthDayHits.map((d) => sample.with({ day: d }));
1784
- return dates.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
1785
- }
1786
- if (!byDay) {
2335
+ const monthStart = sample.day === 1 ? sample : sample.with({ day: 1 });
2336
+ if (!this.opts.byDay && !this.opts.byMonthDay) {
1787
2337
  return this.expandByTime(sample);
1788
2338
  }
1789
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1790
- const tokens = byDay.map((tok) => {
1791
- const m = tok.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
1792
- if (!m) return null;
1793
- return { ord: m[1] ? parseInt(m[1], 10) : 0, wd: dayMap[m[2]] };
1794
- }).filter((x) => x !== null);
1795
- const buckets = {};
1796
- let cursor = sample.with({ day: 1 });
1797
- while (cursor.month === sample.month) {
1798
- const dow = cursor.dayOfWeek;
1799
- (buckets[dow] || (buckets[dow] = [])).push(cursor.day);
1800
- cursor = cursor.add({ days: 1 });
1801
- }
1802
- const byDayHits = [];
1803
- for (const { ord, wd } of tokens) {
1804
- const list = (_a = buckets[wd]) != null ? _a : [];
1805
- if (!list.length) continue;
1806
- if (ord === 0) {
1807
- for (const d of list) byDayHits.push(d);
1808
- } else {
1809
- const idx = ord > 0 ? ord - 1 : list.length + ord;
1810
- const dayN = list[idx];
1811
- if (dayN) byDayHits.push(dayN);
1812
- }
1813
- }
1814
- let finalDays = byDayHits;
1815
- if (byMonthDay && byMonthDay.length > 0) {
1816
- if (byMonthDayHits.length === 0) {
1817
- return [];
1818
- }
1819
- finalDays = finalDays.filter((d) => byMonthDayHits.includes(d));
1820
- }
1821
- const hits = finalDays.map((d) => sample.with({ day: d }));
1822
- return hits.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2339
+ const finalDays = this.generateMonthlyOccurrenceDays(monthStart);
2340
+ if (finalDays.length === 0) return [];
2341
+ const hits = finalDays.map((d) => monthStart.with({ day: d }));
2342
+ return hits.flatMap((z) => this.expandByTime(z));
1823
2343
  }
1824
2344
  /**
1825
2345
  * Given any date in a year, return all ZonedDateTimes in that year matching
@@ -1831,12 +2351,12 @@ var _RRuleTemporal = class _RRuleTemporal {
1831
2351
  let occs = [];
1832
2352
  const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
1833
2353
  if (hasOrdinalByDay && !this.opts.byMonth) {
1834
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2354
+ const dayMap = weekdayToIsoDay;
1835
2355
  for (const tok of this.opts.byDay) {
1836
- const m = tok.match(/^([+-]?\d{1,2})(MO|TU|WE|TH|FR|SA|SU)$/);
1837
- if (!m) continue;
1838
- const ord = parseInt(m[1], 10);
1839
- const wd = dayMap[m[2]];
2356
+ const parsed = parseByDayToken(tok);
2357
+ if (!parsed || parsed.ord === 0) continue;
2358
+ const ord = parsed.ord;
2359
+ const wd = dayMap[parsed.weekday];
1840
2360
  let dt;
1841
2361
  if (ord > 0) {
1842
2362
  const jan1 = sample.with({ month: 1, day: 1 });
@@ -1900,7 +2420,7 @@ var _RRuleTemporal = class _RRuleTemporal {
1900
2420
  return occs;
1901
2421
  }
1902
2422
  addByDay(tokens, weekStart) {
1903
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2423
+ const dayMap = weekdayToIsoDay;
1904
2424
  const wkst = dayMap[this.opts.wkst || "MO"];
1905
2425
  const entries = [];
1906
2426
  for (const tok of tokens) {
@@ -2015,12 +2535,11 @@ var _RRuleTemporal = class _RRuleTemporal {
2015
2535
  return current;
2016
2536
  }
2017
2537
  if (this.opts.byDay && !this.matchesByDay(current)) {
2018
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2019
- const targetDays = this.opts.byDay.map((tok) => {
2020
- var _a;
2021
- return (_a = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
2022
- }).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
2023
- const nextDayOfWeek = this.findNextValidValue(current.dayOfWeek, targetDays.sort(), (a, b) => a - b);
2538
+ const targetDays = this.allByDayIsoDays;
2539
+ if (!(targetDays == null ? void 0 : targetDays.length)) {
2540
+ return this.applyTimeOverride(current.add({ days: 1 }).with({ hour: 0, minute: 0, second: 0 }));
2541
+ }
2542
+ const nextDayOfWeek = this.findNextValidValue(current.dayOfWeek, targetDays, (a, b) => a - b);
2024
2543
  if (nextDayOfWeek) {
2025
2544
  const delta = (nextDayOfWeek - current.dayOfWeek + 7) % 7;
2026
2545
  current = current.add({ days: delta }).with({ hour: 0, minute: 0, second: 0 });
@@ -2054,17 +2573,12 @@ var _RRuleTemporal = class _RRuleTemporal {
2054
2573
  const { bySetPos } = this.opts;
2055
2574
  if (!bySetPos || !bySetPos.length) return list;
2056
2575
  const sorted = [...list].sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2057
- const out = [];
2058
- const len = sorted.length;
2059
- for (const pos of bySetPos) {
2060
- const idx = pos > 0 ? pos - 1 : len + pos;
2061
- if (idx >= 0 && idx < len) out.push(sorted[idx]);
2062
- }
2576
+ const out = this.applyBySetPosToSortedList(sorted);
2063
2577
  return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2064
2578
  }
2065
2579
  isoWeekByDay(sample) {
2066
2580
  var _a;
2067
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2581
+ const dayMap = weekdayToIsoDay;
2068
2582
  const wkst = dayMap[this.opts.wkst || "MO"];
2069
2583
  const jan1 = sample.with({ month: 1, day: 1 });
2070
2584
  const jan4 = sample.with({ month: 1, day: 4 });
@@ -2072,10 +2586,7 @@ var _RRuleTemporal = class _RRuleTemporal {
2072
2586
  const firstWeekStart = jan4.subtract({ days: delta });
2073
2587
  const isLeapYear = jan1.inLeapYear;
2074
2588
  const lastWeek = jan1.dayOfWeek === 4 || isLeapYear && jan1.dayOfWeek === 3 ? 53 : 52;
2075
- const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => {
2076
- var _a2;
2077
- return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2078
- }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2589
+ const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2079
2590
  return { lastWeek, firstWeekStart, tokens };
2080
2591
  }
2081
2592
  /**
@@ -2193,7 +2704,7 @@ var _RRuleTemporal = class _RRuleTemporal {
2193
2704
  rscaleMatchesByWeekNo(calId, pd) {
2194
2705
  const list = this.opts.byWeekNo;
2195
2706
  if (!list || list.length === 0) return true;
2196
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2707
+ const dayMap = weekdayToIsoDay;
2197
2708
  const wkst = dayMap[this.opts.wkst || "MO"];
2198
2709
  const weekStart = pd.subtract({ days: (pd.dayOfWeek - wkst + 7) % 7 });
2199
2710
  const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
@@ -2218,11 +2729,8 @@ var _RRuleTemporal = class _RRuleTemporal {
2218
2729
  rscaleMatchesByDayBasic(pd) {
2219
2730
  const byDay = this.opts.byDay;
2220
2731
  if (!byDay || byDay.length === 0) return true;
2221
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2222
- const tokens = byDay.map((tok) => {
2223
- var _a;
2224
- return (_a = tok.match(/^(?:[+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
2225
- }).filter((x) => !!x);
2732
+ const dayMap = weekdayToIsoDay;
2733
+ const tokens = byDay.map((tok) => extractWeekdayToken(tok)).filter((x) => x !== null);
2226
2734
  if (tokens.length === 0) return true;
2227
2735
  return tokens.some((wd) => dayMap[wd] === pd.dayOfWeek);
2228
2736
  }
@@ -2267,7 +2775,7 @@ var _RRuleTemporal = class _RRuleTemporal {
2267
2775
  }
2268
2776
  }
2269
2777
  if (byDay && byDay.length > 0) {
2270
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2778
+ const dayMap = weekdayToIsoDay;
2271
2779
  const buckets = {};
2272
2780
  let cur = monthStart;
2273
2781
  while (cur.month === monthStart.month && cur.year === monthStart.year) {
@@ -2276,10 +2784,10 @@ var _RRuleTemporal = class _RRuleTemporal {
2276
2784
  cur = cur.add({ days: 1 });
2277
2785
  }
2278
2786
  for (const tok of byDay) {
2279
- const m = tok.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
2280
- if (!m) continue;
2281
- const ord = m[1] ? parseInt(m[1], 10) : 0;
2282
- const wd = dayMap[m[2]];
2787
+ const parsed = parseByDayToken(tok);
2788
+ if (!parsed) continue;
2789
+ const ord = parsed.ord;
2790
+ const wd = dayMap[parsed.weekday];
2283
2791
  const list = buckets[wd] || [];
2284
2792
  if (list.length === 0) continue;
2285
2793
  if (ord === 0) {
@@ -2316,15 +2824,12 @@ var _RRuleTemporal = class _RRuleTemporal {
2316
2824
  let occs = [];
2317
2825
  const monthsTokens = this.opts.byMonth;
2318
2826
  const months = this.monthsOfYear(calId, tgtYear);
2319
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2827
+ const dayMap = weekdayToIsoDay;
2320
2828
  const wkst = dayMap[this.opts.wkst || "MO"];
2321
2829
  if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
2322
2830
  const firstStart = this.rscaleFirstWeekStart(calId, tgtYear, wkst);
2323
2831
  const lastWeek = this.rscaleLastWeekCount(calId, tgtYear, wkst);
2324
- const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) => {
2325
- var _a2;
2326
- return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2327
- }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2832
+ const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2328
2833
  for (const wn of this.opts.byWeekNo) {
2329
2834
  let idx = wn > 0 ? wn - 1 : lastWeek + wn;
2330
2835
  if (idx < 0 || idx >= lastWeek) continue;
@@ -2393,12 +2898,9 @@ var _RRuleTemporal = class _RRuleTemporal {
2393
2898
  return this.applyCountLimitAndMergeRDates(dates, iterator);
2394
2899
  }
2395
2900
  if (this.opts.freq === "WEEKLY") {
2396
- const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2901
+ const dayMap = weekdayToIsoDay;
2397
2902
  const wkst = dayMap[this.opts.wkst || "MO"];
2398
- const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) => {
2399
- var _a2;
2400
- return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2401
- }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2903
+ const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2402
2904
  let weekStart = seed.toPlainDate().subtract({ days: (seed.dayOfWeek - wkst + 7) % 7 });
2403
2905
  while (true) {
2404
2906
  if (++iterationCount > this.maxIterations) {
@@ -2530,5 +3032,8 @@ _RRuleTemporal.rscaleCalendarSupport = {};
2530
3032
  var RRuleTemporal = _RRuleTemporal;
2531
3033
  // Annotate the CommonJS export names for ESM import in node:
2532
3034
  0 && (module.exports = {
2533
- RRuleTemporal
3035
+ RRuleTemporal,
3036
+ allowedFreq,
3037
+ allowedWeekdays,
3038
+ weekdayToIsoDay
2534
3039
  });