rrule-temporal 1.1.14 → 1.2.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
@@ -79,6 +79,14 @@ function parseNumberArray(val, sort = false) {
79
79
  }
80
80
  return arr;
81
81
  }
82
+ function parseByMonthArray(val) {
83
+ return val.split(",").map((tok) => {
84
+ const t = tok.trim();
85
+ if (/^\d+L$/i.test(t)) return t.toUpperCase();
86
+ const n = parseInt(t, 10);
87
+ return Number.isFinite(n) ? n : t;
88
+ });
89
+ }
82
90
  function parseRRuleString(input, targetTimezone) {
83
91
  var _a;
84
92
  const unfoldedInput = unfoldLine(input).trim();
@@ -111,10 +119,32 @@ function parseRRuleString(input, targetTimezone) {
111
119
  exDate: exDate.length > 0 ? exDate : void 0,
112
120
  rDate: rDate.length > 0 ? rDate : void 0
113
121
  };
122
+ let pendingSkip;
114
123
  for (const part of parts) {
115
124
  const [key, val] = part.split("=");
116
125
  if (!key) continue;
117
126
  switch (key.toUpperCase()) {
127
+ case "RSCALE":
128
+ if (val) {
129
+ opts.rscale = val.toUpperCase();
130
+ if (pendingSkip && !opts.skip) {
131
+ opts.skip = pendingSkip;
132
+ pendingSkip = void 0;
133
+ }
134
+ }
135
+ break;
136
+ case "SKIP": {
137
+ const v = (val || "").toUpperCase();
138
+ if (!["OMIT", "BACKWARD", "FORWARD"].includes(v)) {
139
+ throw new Error(`Invalid SKIP value: ${val}`);
140
+ }
141
+ if (opts.rscale) {
142
+ opts.skip = v;
143
+ } else {
144
+ pendingSkip = v;
145
+ }
146
+ break;
147
+ }
118
148
  case "FREQ":
119
149
  opts.freq = val.toUpperCase();
120
150
  break;
@@ -144,7 +174,7 @@ function parseRRuleString(input, targetTimezone) {
144
174
  opts.byDay = val.split(",");
145
175
  break;
146
176
  case "BYMONTH":
147
- opts.byMonth = parseNumberArray(val);
177
+ opts.byMonth = parseByMonthArray(val);
148
178
  break;
149
179
  case "BYMONTHDAY":
150
180
  opts.byMonthDay = parseNumberArray(val);
@@ -163,6 +193,12 @@ function parseRRuleString(input, targetTimezone) {
163
193
  break;
164
194
  }
165
195
  }
196
+ if (pendingSkip && !opts.rscale) {
197
+ throw new Error("SKIP MUST NOT be present unless RSCALE is present");
198
+ }
199
+ if (pendingSkip && opts.rscale && !opts.skip) {
200
+ opts.skip = pendingSkip;
201
+ }
166
202
  return opts;
167
203
  }
168
204
  var RRuleTemporal = class _RRuleTemporal {
@@ -224,8 +260,18 @@ var RRuleTemporal = class _RRuleTemporal {
224
260
  return days.length > 0 ? days : void 0;
225
261
  }
226
262
  sanitizeOpts(opts) {
263
+ var _a;
227
264
  opts.byDay = this.sanitizeByDay(opts.byDay);
228
- opts.byMonth = this.sanitizeNumericArray(opts.byMonth, 1, 12, false, false);
265
+ if (opts.byMonth) {
266
+ const numeric = opts.byMonth.filter((v) => typeof v === "number");
267
+ const stringy = opts.byMonth.filter((v) => typeof v === "string");
268
+ const sanitizedNum = (_a = this.sanitizeNumericArray(numeric, 1, 12, false, false)) != null ? _a : [];
269
+ const merged = [...sanitizedNum, ...stringy];
270
+ opts.byMonth = merged.length > 0 ? merged : void 0;
271
+ }
272
+ if (opts.rscale && !opts.skip) {
273
+ opts.skip = "OMIT";
274
+ }
229
275
  opts.byMonthDay = this.sanitizeNumericArray(opts.byMonthDay, -31, 31, false, false);
230
276
  opts.byYearDay = this.sanitizeNumericArray(opts.byYearDay, -366, 366, false, false);
231
277
  opts.byWeekNo = this.sanitizeNumericArray(opts.byWeekNo, -53, 53, false, false);
@@ -459,7 +505,7 @@ var RRuleTemporal = class _RRuleTemporal {
459
505
  const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
460
506
  const hasOrdinalTokens = this.opts.byDay.some((tok) => /^[+-]?\d/.test(tok));
461
507
  if (hasOrdinalTokens && this.opts.byMonth && (this.opts.freq === "MINUTELY" || this.opts.freq === "SECONDLY")) {
462
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
508
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
463
509
  let foundFirst = false;
464
510
  for (let year = zdt.year; year <= zdt.year + 10 && !foundFirst; year++) {
465
511
  for (const month of months) {
@@ -562,7 +608,9 @@ var RRuleTemporal = class _RRuleTemporal {
562
608
  matchesByMonth(zdt) {
563
609
  const { byMonth } = this.opts;
564
610
  if (!byMonth) return true;
565
- return byMonth.includes(zdt.month);
611
+ const nums = byMonth.filter((v) => typeof v === "number");
612
+ if (nums.length === 0) return true;
613
+ return nums.includes(zdt.month);
566
614
  }
567
615
  matchesNumericConstraint(value, constraints, maxPositiveValue) {
568
616
  return constraints.some((c) => {
@@ -759,7 +807,7 @@ var RRuleTemporal = class _RRuleTemporal {
759
807
  if (!this.addDtstartIfNeeded(dates, iterator)) {
760
808
  return this.applyCountLimitAndMergeRDates(dates, iterator);
761
809
  }
762
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
810
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
763
811
  let monthOffset = 0;
764
812
  let startMonthIndex = months.findIndex((m) => m >= start.month);
765
813
  if (startMonthIndex === -1) {
@@ -803,7 +851,7 @@ var RRuleTemporal = class _RRuleTemporal {
803
851
  if (!this.addDtstartIfNeeded(dates, iterator)) {
804
852
  return this.applyCountLimitAndMergeRDates(dates, iterator);
805
853
  }
806
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
854
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
807
855
  let yearOffset = 0;
808
856
  while (true) {
809
857
  if (++iterationCount > this.maxIterations) {
@@ -1098,6 +1146,11 @@ var RRuleTemporal = class _RRuleTemporal {
1098
1146
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
1099
1147
  */
1100
1148
  all(iterator) {
1149
+ if (this.opts.rscale && ["CHINESE", "HEBREW", "INDIAN"].includes(this.opts.rscale)) {
1150
+ if (["YEARLY", "MONTHLY", "WEEKLY"].includes(this.opts.freq) || !!this.opts.byYearDay || !!this.opts.byWeekNo || this.opts.byMonthDay && this.opts.byMonthDay.length > 0) {
1151
+ return this._allRscaleNonGregorian(iterator);
1152
+ }
1153
+ }
1101
1154
  if (this.opts.byWeekNo && this.opts.byYearDay) {
1102
1155
  const yearStart = this.originalDtstart.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 });
1103
1156
  const yearDays = this.opts.byYearDay.map((yd) => {
@@ -1143,11 +1196,68 @@ var RRuleTemporal = class _RRuleTemporal {
1143
1196
  if (this.opts.freq === "MONTHLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 && !this.opts.byDay && !this.opts.byMonthDay) {
1144
1197
  return this._allMonthlyByYearDay(iterator);
1145
1198
  }
1199
+ if (this.opts.rscale && this.opts.freq === "MONTHLY" && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byWeekNo && !this.opts.byYearDay) {
1200
+ return this._allMonthlyRscaleSimple(iterator);
1201
+ }
1146
1202
  if ((this.opts.freq === "MINUTELY" || this.opts.freq === "HOURLY" || this.opts.freq === "DAILY") && this.opts.bySetPos) {
1147
1203
  return this._allDailyMinutelyHourlyWithBySetPos(iterator);
1148
1204
  }
1149
1205
  return this._allFallback(iterator);
1150
1206
  }
1207
+ /**
1208
+ * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
1209
+ * Handles month-to-month stepping from DTSTART's year/month aiming for DTSTART's day-of-month.
1210
+ * Applies SKIP=OMIT (skip invalid months), BACKWARD (clamp to last day), FORWARD (first day of next month).
1211
+ */
1212
+ _allMonthlyRscaleSimple(iterator) {
1213
+ var _a;
1214
+ const dates = [];
1215
+ let iterationCount = 0;
1216
+ const start = this.originalDtstart;
1217
+ const interval = (_a = this.opts.interval) != null ? _a : 1;
1218
+ const targetDom = start.day;
1219
+ if (!this.addDtstartIfNeeded(dates, iterator)) {
1220
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
1221
+ }
1222
+ let cursor = start.with({ day: 1 });
1223
+ while (true) {
1224
+ if (++iterationCount > this.maxIterations) {
1225
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1226
+ }
1227
+ const lastDay = cursor.add({ months: 1 }).subtract({ days: 1 }).day;
1228
+ let occ = null;
1229
+ if (targetDom <= lastDay) {
1230
+ occ = cursor.with({ day: targetDom });
1231
+ } else {
1232
+ const skip = this.opts.skip || "OMIT";
1233
+ if (skip === "BACKWARD") {
1234
+ occ = cursor.with({ day: lastDay });
1235
+ } else if (skip === "FORWARD") {
1236
+ occ = cursor.add({ months: 1 }).with({ day: 1 });
1237
+ } else {
1238
+ occ = null;
1239
+ }
1240
+ }
1241
+ if (occ) {
1242
+ occ = occ.with({ hour: start.hour, minute: start.minute, second: start.second });
1243
+ if (!(iterator && this.isExcluded(occ))) {
1244
+ if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) >= 0) {
1245
+ if (!iterator || iterator(occ, dates.length)) {
1246
+ dates.push(occ);
1247
+ if (this.shouldBreakForCountLimit(dates.length)) break;
1248
+ } else {
1249
+ break;
1250
+ }
1251
+ }
1252
+ }
1253
+ }
1254
+ cursor = cursor.add({ months: interval });
1255
+ if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(cursor, this.opts.until) > 0) {
1256
+ break;
1257
+ }
1258
+ }
1259
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
1260
+ }
1151
1261
  /**
1152
1262
  * Converts rDate entries to ZonedDateTime and merges with existing dates.
1153
1263
  * @param dates - Array of dates to merge with
@@ -1368,6 +1478,8 @@ var RRuleTemporal = class _RRuleTemporal {
1368
1478
  rDate,
1369
1479
  exDate
1370
1480
  } = this.opts;
1481
+ if (this.opts.rscale) rule.push(`RSCALE=${this.opts.rscale}`);
1482
+ if (this.opts.rscale && this.opts.skip) rule.push(`SKIP=${this.opts.skip}`);
1371
1483
  rule.push(`FREQ=${freq}`);
1372
1484
  if (interval !== 1) rule.push(`INTERVAL=${interval}`);
1373
1485
  if (count !== void 0) rule.push(`COUNT=${count}`);
@@ -1463,7 +1575,7 @@ var RRuleTemporal = class _RRuleTemporal {
1463
1575
  * if BYMONTH is not specified.
1464
1576
  */
1465
1577
  generateYearlyOccurrences(sample) {
1466
- const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : this.opts.byMonthDay || this.opts.byDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [this.originalDtstart.month];
1578
+ const months = this.opts.byMonth ? this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b) : this.opts.byMonthDay || this.opts.byDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [this.originalDtstart.month];
1467
1579
  let occs = [];
1468
1580
  const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
1469
1581
  if (hasOrdinalByDay && !this.opts.byMonth) {
@@ -1486,10 +1598,28 @@ var RRuleTemporal = class _RRuleTemporal {
1486
1598
  occs.push(...this.expandByTime(dt));
1487
1599
  }
1488
1600
  } else if (!this.opts.byYearDay && !this.opts.byWeekNo) {
1489
- occs = months.flatMap((m) => {
1601
+ occs = [];
1602
+ for (const m of months) {
1490
1603
  const monthSample = sample.with({ month: m, day: 1 });
1491
- return this.generateMonthlyOccurrences(monthSample);
1492
- });
1604
+ const monthOccs = this.generateMonthlyOccurrences(monthSample);
1605
+ if (monthOccs.length === 0 && this.opts.rscale && this.opts.byMonthDay && this.opts.byMonthDay.length > 0) {
1606
+ const lastDay = monthSample.add({ months: 1 }).subtract({ days: 1 }).day;
1607
+ const target = this.opts.byMonthDay[0];
1608
+ const absTarget = target > 0 ? target : lastDay + target + 1;
1609
+ if (absTarget > lastDay || absTarget <= 0) {
1610
+ const skip = this.opts.skip || "OMIT";
1611
+ if (skip === "BACKWARD") {
1612
+ occs.push(...this.expandByTime(monthSample.with({ day: lastDay })));
1613
+ } else if (skip === "FORWARD") {
1614
+ const nextMonth = monthSample.add({ months: 1 }).with({ day: 1 });
1615
+ occs.push(...this.expandByTime(nextMonth));
1616
+ } else {
1617
+ }
1618
+ }
1619
+ } else {
1620
+ occs.push(...monthOccs);
1621
+ }
1622
+ }
1493
1623
  }
1494
1624
  if (this.opts.byYearDay) {
1495
1625
  const last = sample.with({ month: 12, day: 31 }).dayOfYear;
@@ -1555,16 +1685,19 @@ var RRuleTemporal = class _RRuleTemporal {
1555
1685
  }
1556
1686
  }
1557
1687
  }
1558
- if (this.opts.byMonth && !this.opts.byMonth.includes(current.month)) {
1559
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
1560
- const nextMonth = this.findNextValidValue(current.month, months, (a, b) => a - b);
1561
- if (nextMonth) {
1562
- current = current.with({ month: nextMonth, day: 1, hour: 0, minute: 0, second: 0 });
1563
- } else {
1564
- current = current.add({ years: 1 }).with({ month: months[0], day: 1, hour: 0, minute: 0, second: 0 });
1688
+ if (this.opts.byMonth) {
1689
+ const numericMonths = this.opts.byMonth.filter((v) => typeof v === "number");
1690
+ if (numericMonths.length && !numericMonths.includes(current.month)) {
1691
+ const months = [...numericMonths].sort((a, b) => a - b);
1692
+ const nextMonth = this.findNextValidValue(current.month, months, (a, b) => a - b);
1693
+ if (nextMonth) {
1694
+ current = current.with({ month: nextMonth, day: 1, hour: 0, minute: 0, second: 0 });
1695
+ } else {
1696
+ current = current.add({ years: 1 }).with({ month: months[0], day: 1, hour: 0, minute: 0, second: 0 });
1697
+ }
1698
+ current = this.applyTimeOverride(current);
1699
+ return current;
1565
1700
  }
1566
- current = this.applyTimeOverride(current);
1567
- return current;
1568
1701
  }
1569
1702
  if (this.opts.byWeekNo && !this.matchesByWeekNo(current)) {
1570
1703
  current = current.add({ weeks: 1 }).with({ hour: 0, minute: 0, second: 0 });
@@ -1708,6 +1841,416 @@ var RRuleTemporal = class _RRuleTemporal {
1708
1841
  occs.push(...this.addByDay(tokens, weekStart));
1709
1842
  return occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
1710
1843
  }
1844
+ // ===== RSCALE (non-Gregorian) support: Chinese and Hebrew =====
1845
+ getRscaleCalendarId() {
1846
+ var _a;
1847
+ const map = {
1848
+ GREGORIAN: "gregory",
1849
+ CHINESE: "chinese",
1850
+ HEBREW: "hebrew",
1851
+ INDIAN: "indian"
1852
+ };
1853
+ const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
1854
+ return map[r] || null;
1855
+ }
1856
+ pad2(n) {
1857
+ return String(n).padStart(2, "0");
1858
+ }
1859
+ monthMatchesToken(monthCode, token) {
1860
+ if (typeof token === "number") {
1861
+ return monthCode === `M${this.pad2(token)}`;
1862
+ }
1863
+ if (/^\d+L$/i.test(token)) {
1864
+ const n = parseInt(token, 10);
1865
+ return monthCode === `M${this.pad2(n)}L`;
1866
+ }
1867
+ return false;
1868
+ }
1869
+ monthsOfYear(calId, year) {
1870
+ const out = [];
1871
+ for (let m = 1; m <= 20; m++) {
1872
+ try {
1873
+ const d = import_polyfill.Temporal.PlainDate.from({ calendar: calId, year, month: m, day: 1 });
1874
+ out.push(d);
1875
+ } catch (e) {
1876
+ break;
1877
+ }
1878
+ }
1879
+ return out;
1880
+ }
1881
+ startOfYear(calId, year) {
1882
+ return import_polyfill.Temporal.PlainDate.from({ calendar: calId, year, month: 1, day: 1 });
1883
+ }
1884
+ endOfYear(calId, year) {
1885
+ return this.startOfYear(calId, year + 1).subtract({ days: 1 });
1886
+ }
1887
+ rscaleFirstWeekStart(calId, year, wkst) {
1888
+ const jan4 = import_polyfill.Temporal.PlainDate.from({ calendar: calId, year, month: 1, day: 4 });
1889
+ const delta = (jan4.dayOfWeek - wkst + 7) % 7;
1890
+ return jan4.subtract({ days: delta });
1891
+ }
1892
+ rscaleLastWeekCount(calId, year, wkst) {
1893
+ const firstWeekStart = this.rscaleFirstWeekStart(calId, year, wkst);
1894
+ const lastDay = this.endOfYear(calId, year);
1895
+ const diffDays = lastDay.since(firstWeekStart).days;
1896
+ return Math.floor(diffDays / 7) + 1;
1897
+ }
1898
+ lastDayOfMonth(pd) {
1899
+ return pd.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
1900
+ }
1901
+ buildZdtFromPlainDate(pd) {
1902
+ const t = this.originalDtstart;
1903
+ const pdt = import_polyfill.Temporal.PlainDateTime.from({
1904
+ calendar: pd.calendarId,
1905
+ year: pd.year,
1906
+ month: pd.month,
1907
+ day: pd.day,
1908
+ hour: t.hour,
1909
+ minute: t.minute,
1910
+ second: t.second
1911
+ });
1912
+ return pdt.toZonedDateTime(this.tzid);
1913
+ }
1914
+ rscaleMatchesByYearDay(calId, pd) {
1915
+ const list = this.opts.byYearDay;
1916
+ if (!list || list.length === 0) return true;
1917
+ const last = this.endOfYear(calId, pd.year).dayOfYear;
1918
+ return list.some((d) => d > 0 ? pd.dayOfYear === d : pd.dayOfYear === last + d + 1);
1919
+ }
1920
+ rscaleMatchesByWeekNo(calId, pd) {
1921
+ const list = this.opts.byWeekNo;
1922
+ if (!list || list.length === 0) return true;
1923
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1924
+ const wkst = dayMap[this.opts.wkst || "MO"];
1925
+ const weekStart = pd.subtract({ days: (pd.dayOfWeek - wkst + 7) % 7 });
1926
+ const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
1927
+ const weekYear = thursday.year;
1928
+ const firstStart = this.rscaleFirstWeekStart(calId, weekYear, wkst);
1929
+ const lastWeek = this.rscaleLastWeekCount(calId, weekYear, wkst);
1930
+ const idx = Math.floor(pd.since(firstStart).days / 7) + 1;
1931
+ return list.some((wn) => wn > 0 ? idx === wn : idx === lastWeek + wn + 1);
1932
+ }
1933
+ rscaleMatchesByMonth(calId, pd) {
1934
+ const tokens = this.opts.byMonth;
1935
+ if (!tokens || tokens.length === 0) return true;
1936
+ return tokens.some((tok) => this.monthMatchesToken(pd.monthCode, tok));
1937
+ }
1938
+ rscaleMatchesByMonthDay(pd) {
1939
+ const list = this.opts.byMonthDay;
1940
+ if (!list || list.length === 0) return true;
1941
+ const last = pd.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
1942
+ const value = pd.day;
1943
+ return list.some((d) => d > 0 ? value === d : value === last + d + 1);
1944
+ }
1945
+ rscaleMatchesByDayBasic(pd) {
1946
+ const byDay = this.opts.byDay;
1947
+ if (!byDay || byDay.length === 0) return true;
1948
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1949
+ const tokens = byDay.map((tok) => {
1950
+ var _a;
1951
+ return (_a = tok.match(/^(?:[+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
1952
+ }).filter((x) => !!x);
1953
+ if (tokens.length === 0) return true;
1954
+ return tokens.some((wd) => dayMap[wd] === pd.dayOfWeek);
1955
+ }
1956
+ rscaleDateMatches(calId, pd) {
1957
+ return this.rscaleMatchesByMonth(calId, pd) && this.rscaleMatchesByYearDay(calId, pd) && this.rscaleMatchesByWeekNo(calId, pd) && this.rscaleMatchesByMonthDay(pd) && this.rscaleMatchesByDayBasic(pd);
1958
+ }
1959
+ applySkipForDay(calId, year, monthStart, targetDay) {
1960
+ const last = this.lastDayOfMonth(monthStart);
1961
+ const skip = this.opts.skip || "OMIT";
1962
+ if (targetDay >= 1 && targetDay <= last) {
1963
+ return monthStart.with({ day: targetDay });
1964
+ }
1965
+ if (skip === "BACKWARD") {
1966
+ return monthStart.with({ day: last });
1967
+ }
1968
+ if (skip === "FORWARD") {
1969
+ const nextMonthStart = monthStart.add({ months: 1 });
1970
+ return nextMonthStart.with({ day: 1 });
1971
+ }
1972
+ return null;
1973
+ }
1974
+ generateMonthlyOccurrencesRscale(calId, year, monthStart) {
1975
+ const occs = [];
1976
+ const byMonthDay = this.opts.byMonthDay;
1977
+ const byDay = this.opts.byDay;
1978
+ if (!byDay && !byMonthDay) {
1979
+ const targetDay = this.originalDtstart.withCalendar(calId).day;
1980
+ const pd = this.applySkipForDay(calId, year, monthStart, targetDay);
1981
+ if (pd) occs.push(this.buildZdtFromPlainDate(pd));
1982
+ return occs;
1983
+ }
1984
+ const addZ = (pd) => {
1985
+ occs.push(this.buildZdtFromPlainDate(pd));
1986
+ };
1987
+ const last = this.lastDayOfMonth(monthStart);
1988
+ const resolveDay = (d) => d > 0 ? d : last + d + 1;
1989
+ if (byMonthDay && byMonthDay.length > 0) {
1990
+ for (const raw of byMonthDay) {
1991
+ const dayNum = resolveDay(raw);
1992
+ const pd = this.applySkipForDay(calId, year, monthStart, dayNum);
1993
+ if (pd) addZ(pd);
1994
+ }
1995
+ }
1996
+ if (byDay && byDay.length > 0) {
1997
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1998
+ const buckets = {};
1999
+ let cur = monthStart;
2000
+ while (cur.month === monthStart.month && cur.year === monthStart.year) {
2001
+ const wd = cur.dayOfWeek;
2002
+ (buckets[wd] || (buckets[wd] = [])).push(cur);
2003
+ cur = cur.add({ days: 1 });
2004
+ }
2005
+ for (const tok of byDay) {
2006
+ const m = tok.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
2007
+ if (!m) continue;
2008
+ const ord = m[1] ? parseInt(m[1], 10) : 0;
2009
+ const wd = dayMap[m[2]];
2010
+ const list = buckets[wd] || [];
2011
+ if (list.length === 0) continue;
2012
+ if (ord === 0) {
2013
+ for (const pd of list) addZ(pd);
2014
+ } else {
2015
+ const idx = ord > 0 ? ord - 1 : list.length + ord;
2016
+ const pd = list[idx];
2017
+ if (pd) addZ(pd);
2018
+ }
2019
+ }
2020
+ }
2021
+ return this.applyBySetPos(occs).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2022
+ }
2023
+ _allRscaleNonGregorian(iterator) {
2024
+ var _a, _b, _c, _d, _e, _f, _g;
2025
+ const calId = this.getRscaleCalendarId();
2026
+ if (!calId) return this._allFallback(iterator);
2027
+ const dates = [];
2028
+ let iterationCount = 0;
2029
+ const start = this.originalDtstart;
2030
+ const seed = start.withCalendar(calId);
2031
+ const interval = (_a = this.opts.interval) != null ? _a : 1;
2032
+ if (!this.addDtstartIfNeeded(dates, iterator)) {
2033
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2034
+ }
2035
+ if (this.opts.freq === "YEARLY") {
2036
+ let yearOffset = 0;
2037
+ while (true) {
2038
+ if (++iterationCount > this.maxIterations) {
2039
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2040
+ }
2041
+ const tgtYear = seed.year + yearOffset * interval;
2042
+ let occs = [];
2043
+ const monthsTokens = this.opts.byMonth;
2044
+ const months = this.monthsOfYear(calId, tgtYear);
2045
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2046
+ const wkst = dayMap[this.opts.wkst || "MO"];
2047
+ if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
2048
+ const firstStart = this.rscaleFirstWeekStart(calId, tgtYear, wkst);
2049
+ const lastWeek = this.rscaleLastWeekCount(calId, tgtYear, wkst);
2050
+ const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) => {
2051
+ var _a2;
2052
+ return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2053
+ }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2054
+ for (const wn of this.opts.byWeekNo) {
2055
+ let idx = wn > 0 ? wn - 1 : lastWeek + wn;
2056
+ if (idx < 0 || idx >= lastWeek) continue;
2057
+ const weekStart = firstStart.add({ weeks: idx });
2058
+ for (const tok of tokens) {
2059
+ const targetDow = dayMap[tok];
2060
+ const pd = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
2061
+ if (monthsTokens && monthsTokens.length > 0) {
2062
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2063
+ }
2064
+ if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2065
+ const lastDay = this.endOfYear(calId, tgtYear).dayOfYear;
2066
+ const matches = this.opts.byYearDay.some((d) => {
2067
+ const target = d > 0 ? d : lastDay + d + 1;
2068
+ return pd.dayOfYear === target;
2069
+ });
2070
+ if (!matches) continue;
2071
+ }
2072
+ occs.push(this.buildZdtFromPlainDate(pd));
2073
+ }
2074
+ }
2075
+ } else if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2076
+ const startOfYear = this.startOfYear(calId, tgtYear);
2077
+ const lastDay = this.endOfYear(calId, tgtYear).dayOfYear;
2078
+ for (const d of this.opts.byYearDay) {
2079
+ const target = d > 0 ? d : lastDay + d + 1;
2080
+ if (target < 1 || target > lastDay) continue;
2081
+ let pd = startOfYear.add({ days: target - 1 });
2082
+ if (monthsTokens && monthsTokens.length > 0) {
2083
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2084
+ }
2085
+ occs.push(this.buildZdtFromPlainDate(pd));
2086
+ }
2087
+ } else if (!monthsTokens || monthsTokens.length === 0) {
2088
+ try {
2089
+ const pd = import_polyfill.Temporal.PlainDate.from({
2090
+ calendar: calId,
2091
+ year: tgtYear,
2092
+ monthCode: seed.monthCode,
2093
+ day: seed.day
2094
+ });
2095
+ occs.push(this.buildZdtFromPlainDate(pd));
2096
+ } catch (e) {
2097
+ const skip = this.opts.skip || "OMIT";
2098
+ if (skip === "FORWARD" || skip === "BACKWARD") {
2099
+ const mapped = seed.with({ year: tgtYear });
2100
+ const adjusted = skip === "BACKWARD" ? mapped.subtract({ days: 1 }) : mapped;
2101
+ occs.push(adjusted.withCalendar("iso8601"));
2102
+ }
2103
+ }
2104
+ } else {
2105
+ const monthStarts = months.filter((m) => monthsTokens.some((tok) => this.monthMatchesToken(m.monthCode, tok)));
2106
+ for (const ms of monthStarts) {
2107
+ occs.push(...this.generateMonthlyOccurrencesRscale(calId, tgtYear, ms));
2108
+ }
2109
+ }
2110
+ if (occs.length > 0) {
2111
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2112
+ const sorted = expanded.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2113
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2114
+ if (shouldBreak) break;
2115
+ }
2116
+ yearOffset++;
2117
+ if (this.opts.until && tgtYear > this.opts.until.withCalendar(calId).year) break;
2118
+ }
2119
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2120
+ }
2121
+ if (this.opts.freq === "WEEKLY") {
2122
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2123
+ const wkst = dayMap[this.opts.wkst || "MO"];
2124
+ const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) => {
2125
+ var _a2;
2126
+ return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2127
+ }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2128
+ let weekStart = seed.toPlainDate().subtract({ days: (seed.dayOfWeek - wkst + 7) % 7 });
2129
+ while (true) {
2130
+ if (++iterationCount > this.maxIterations) {
2131
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2132
+ }
2133
+ const occs = [];
2134
+ for (const tok of tokens) {
2135
+ const targetDow = dayMap[tok];
2136
+ const pd = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
2137
+ if (import_polyfill.Temporal.ZonedDateTime.compare(this.buildZdtFromPlainDate(pd), this.originalDtstart) < 0) {
2138
+ continue;
2139
+ }
2140
+ if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
2141
+ const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
2142
+ const weekYear = thursday.year;
2143
+ const firstStart = this.rscaleFirstWeekStart(calId, weekYear, wkst);
2144
+ const lastWeek = this.rscaleLastWeekCount(calId, weekYear, wkst);
2145
+ const idx = Math.floor(pd.since(firstStart).days / 7) + 1;
2146
+ const match = this.opts.byWeekNo.some((wn) => wn > 0 ? idx === wn : idx === lastWeek + wn + 1);
2147
+ if (!match) continue;
2148
+ }
2149
+ if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2150
+ const last = this.endOfYear(calId, pd.year).dayOfYear;
2151
+ const match = this.opts.byYearDay.some((d) => d > 0 ? pd.dayOfYear === d : pd.dayOfYear === last + d + 1);
2152
+ if (!match) continue;
2153
+ }
2154
+ const monthsTokens = this.opts.byMonth;
2155
+ if (monthsTokens && monthsTokens.length > 0) {
2156
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2157
+ }
2158
+ occs.push(this.buildZdtFromPlainDate(pd));
2159
+ }
2160
+ if (occs.length) {
2161
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2162
+ const sorted = expanded.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2163
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2164
+ if (shouldBreak) return this.applyCountLimitAndMergeRDates(dates, iterator);
2165
+ }
2166
+ weekStart = weekStart.add({ weeks: (_d = this.opts.interval) != null ? _d : 1 });
2167
+ if (this.opts.until) {
2168
+ const z = this.buildZdtFromPlainDate(weekStart.add({ days: 6 }));
2169
+ if (import_polyfill.Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2170
+ }
2171
+ }
2172
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2173
+ }
2174
+ if (this.opts.freq === "MONTHLY") {
2175
+ let cursor = seed.toPlainDate().with({ day: 1 });
2176
+ while (true) {
2177
+ if (++iterationCount > this.maxIterations) {
2178
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2179
+ }
2180
+ const year = cursor.year;
2181
+ const monthStart = cursor;
2182
+ let proceed = true;
2183
+ const monthsTokens = this.opts.byMonth;
2184
+ if (monthsTokens && monthsTokens.length > 0) {
2185
+ proceed = monthsTokens.some((tok) => this.monthMatchesToken(monthStart.monthCode, tok));
2186
+ }
2187
+ if (proceed) {
2188
+ const occs = this.generateMonthlyOccurrencesRscale(calId, year, monthStart);
2189
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2190
+ const sorted = expanded.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
2191
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2192
+ if (shouldBreak) break;
2193
+ }
2194
+ cursor = cursor.add({ months: (_e = this.opts.interval) != null ? _e : 1 });
2195
+ if (this.opts.until) {
2196
+ const z = this.buildZdtFromPlainDate(cursor);
2197
+ if (import_polyfill.Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2198
+ }
2199
+ }
2200
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2201
+ }
2202
+ if (this.opts.freq === "DAILY") {
2203
+ let pd = seed.toPlainDate();
2204
+ while (true) {
2205
+ if (++iterationCount > this.maxIterations) {
2206
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2207
+ }
2208
+ if (this.rscaleDateMatches(calId, pd)) {
2209
+ const base = this.buildZdtFromPlainDate(pd);
2210
+ let occs = this.expandByTime(base);
2211
+ occs = this.applyBySetPos(occs);
2212
+ const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
2213
+ if (shouldBreak) break;
2214
+ }
2215
+ pd = pd.add({ days: (_f = this.opts.interval) != null ? _f : 1 });
2216
+ if (this.opts.until) {
2217
+ const z = this.buildZdtFromPlainDate(pd);
2218
+ if (import_polyfill.Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2219
+ }
2220
+ }
2221
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2222
+ }
2223
+ if (this.opts.freq === "HOURLY" || this.opts.freq === "MINUTELY") {
2224
+ const unit = this.opts.freq === "HOURLY" ? "hour" : "minute";
2225
+ const unitMs = this.opts.freq === "HOURLY" ? 36e5 : 6e4;
2226
+ const interval2 = (_g = this.opts.interval) != null ? _g : 1;
2227
+ let pd = seed.toPlainDate();
2228
+ const startInstantMs = this.originalDtstart.toInstant().epochMilliseconds;
2229
+ while (true) {
2230
+ if (++iterationCount > this.maxIterations) {
2231
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2232
+ }
2233
+ if (this.rscaleDateMatches(calId, pd)) {
2234
+ const base = this.buildZdtFromPlainDate(pd);
2235
+ let occs = this.expandByTime(base);
2236
+ occs = occs.filter((occ) => {
2237
+ const delta = occ.toInstant().epochMilliseconds - startInstantMs;
2238
+ const steps = Math.floor(delta / unitMs);
2239
+ return steps % interval2 === 0;
2240
+ });
2241
+ const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
2242
+ if (shouldBreak) break;
2243
+ }
2244
+ pd = pd.add({ days: 1 });
2245
+ if (this.opts.until) {
2246
+ const z = this.buildZdtFromPlainDate(pd);
2247
+ if (import_polyfill.Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2248
+ }
2249
+ }
2250
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2251
+ }
2252
+ return this._allFallback(iterator);
2253
+ }
1711
2254
  };
1712
2255
  // Annotate the CommonJS export names for ESM import in node:
1713
2256
  0 && (module.exports = {