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.
@@ -58,6 +58,14 @@ function parseNumberArray(val, sort = false) {
58
58
  }
59
59
  return arr;
60
60
  }
61
+ function parseByMonthArray(val) {
62
+ return val.split(",").map((tok) => {
63
+ const t = tok.trim();
64
+ if (/^\d+L$/i.test(t)) return t.toUpperCase();
65
+ const n = parseInt(t, 10);
66
+ return Number.isFinite(n) ? n : t;
67
+ });
68
+ }
61
69
  function parseRRuleString(input, targetTimezone) {
62
70
  var _a;
63
71
  const unfoldedInput = unfoldLine(input).trim();
@@ -90,10 +98,32 @@ function parseRRuleString(input, targetTimezone) {
90
98
  exDate: exDate.length > 0 ? exDate : void 0,
91
99
  rDate: rDate.length > 0 ? rDate : void 0
92
100
  };
101
+ let pendingSkip;
93
102
  for (const part of parts) {
94
103
  const [key, val] = part.split("=");
95
104
  if (!key) continue;
96
105
  switch (key.toUpperCase()) {
106
+ case "RSCALE":
107
+ if (val) {
108
+ opts.rscale = val.toUpperCase();
109
+ if (pendingSkip && !opts.skip) {
110
+ opts.skip = pendingSkip;
111
+ pendingSkip = void 0;
112
+ }
113
+ }
114
+ break;
115
+ case "SKIP": {
116
+ const v = (val || "").toUpperCase();
117
+ if (!["OMIT", "BACKWARD", "FORWARD"].includes(v)) {
118
+ throw new Error(`Invalid SKIP value: ${val}`);
119
+ }
120
+ if (opts.rscale) {
121
+ opts.skip = v;
122
+ } else {
123
+ pendingSkip = v;
124
+ }
125
+ break;
126
+ }
97
127
  case "FREQ":
98
128
  opts.freq = val.toUpperCase();
99
129
  break;
@@ -123,7 +153,7 @@ function parseRRuleString(input, targetTimezone) {
123
153
  opts.byDay = val.split(",");
124
154
  break;
125
155
  case "BYMONTH":
126
- opts.byMonth = parseNumberArray(val);
156
+ opts.byMonth = parseByMonthArray(val);
127
157
  break;
128
158
  case "BYMONTHDAY":
129
159
  opts.byMonthDay = parseNumberArray(val);
@@ -142,6 +172,12 @@ function parseRRuleString(input, targetTimezone) {
142
172
  break;
143
173
  }
144
174
  }
175
+ if (pendingSkip && !opts.rscale) {
176
+ throw new Error("SKIP MUST NOT be present unless RSCALE is present");
177
+ }
178
+ if (pendingSkip && opts.rscale && !opts.skip) {
179
+ opts.skip = pendingSkip;
180
+ }
145
181
  return opts;
146
182
  }
147
183
  var RRuleTemporal = class _RRuleTemporal {
@@ -203,8 +239,18 @@ var RRuleTemporal = class _RRuleTemporal {
203
239
  return days.length > 0 ? days : void 0;
204
240
  }
205
241
  sanitizeOpts(opts) {
242
+ var _a;
206
243
  opts.byDay = this.sanitizeByDay(opts.byDay);
207
- opts.byMonth = this.sanitizeNumericArray(opts.byMonth, 1, 12, false, false);
244
+ if (opts.byMonth) {
245
+ const numeric = opts.byMonth.filter((v) => typeof v === "number");
246
+ const stringy = opts.byMonth.filter((v) => typeof v === "string");
247
+ const sanitizedNum = (_a = this.sanitizeNumericArray(numeric, 1, 12, false, false)) != null ? _a : [];
248
+ const merged = [...sanitizedNum, ...stringy];
249
+ opts.byMonth = merged.length > 0 ? merged : void 0;
250
+ }
251
+ if (opts.rscale && !opts.skip) {
252
+ opts.skip = "OMIT";
253
+ }
208
254
  opts.byMonthDay = this.sanitizeNumericArray(opts.byMonthDay, -31, 31, false, false);
209
255
  opts.byYearDay = this.sanitizeNumericArray(opts.byYearDay, -366, 366, false, false);
210
256
  opts.byWeekNo = this.sanitizeNumericArray(opts.byWeekNo, -53, 53, false, false);
@@ -438,7 +484,7 @@ var RRuleTemporal = class _RRuleTemporal {
438
484
  const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
439
485
  const hasOrdinalTokens = this.opts.byDay.some((tok) => /^[+-]?\d/.test(tok));
440
486
  if (hasOrdinalTokens && this.opts.byMonth && (this.opts.freq === "MINUTELY" || this.opts.freq === "SECONDLY")) {
441
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
487
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
442
488
  let foundFirst = false;
443
489
  for (let year = zdt.year; year <= zdt.year + 10 && !foundFirst; year++) {
444
490
  for (const month of months) {
@@ -541,7 +587,9 @@ var RRuleTemporal = class _RRuleTemporal {
541
587
  matchesByMonth(zdt) {
542
588
  const { byMonth } = this.opts;
543
589
  if (!byMonth) return true;
544
- return byMonth.includes(zdt.month);
590
+ const nums = byMonth.filter((v) => typeof v === "number");
591
+ if (nums.length === 0) return true;
592
+ return nums.includes(zdt.month);
545
593
  }
546
594
  matchesNumericConstraint(value, constraints, maxPositiveValue) {
547
595
  return constraints.some((c) => {
@@ -738,7 +786,7 @@ var RRuleTemporal = class _RRuleTemporal {
738
786
  if (!this.addDtstartIfNeeded(dates, iterator)) {
739
787
  return this.applyCountLimitAndMergeRDates(dates, iterator);
740
788
  }
741
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
789
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
742
790
  let monthOffset = 0;
743
791
  let startMonthIndex = months.findIndex((m) => m >= start.month);
744
792
  if (startMonthIndex === -1) {
@@ -782,7 +830,7 @@ var RRuleTemporal = class _RRuleTemporal {
782
830
  if (!this.addDtstartIfNeeded(dates, iterator)) {
783
831
  return this.applyCountLimitAndMergeRDates(dates, iterator);
784
832
  }
785
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
833
+ const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
786
834
  let yearOffset = 0;
787
835
  while (true) {
788
836
  if (++iterationCount > this.maxIterations) {
@@ -1077,6 +1125,11 @@ var RRuleTemporal = class _RRuleTemporal {
1077
1125
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
1078
1126
  */
1079
1127
  all(iterator) {
1128
+ if (this.opts.rscale && ["CHINESE", "HEBREW", "INDIAN"].includes(this.opts.rscale)) {
1129
+ if (["YEARLY", "MONTHLY", "WEEKLY"].includes(this.opts.freq) || !!this.opts.byYearDay || !!this.opts.byWeekNo || this.opts.byMonthDay && this.opts.byMonthDay.length > 0) {
1130
+ return this._allRscaleNonGregorian(iterator);
1131
+ }
1132
+ }
1080
1133
  if (this.opts.byWeekNo && this.opts.byYearDay) {
1081
1134
  const yearStart = this.originalDtstart.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 });
1082
1135
  const yearDays = this.opts.byYearDay.map((yd) => {
@@ -1122,11 +1175,68 @@ var RRuleTemporal = class _RRuleTemporal {
1122
1175
  if (this.opts.freq === "MONTHLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 && !this.opts.byDay && !this.opts.byMonthDay) {
1123
1176
  return this._allMonthlyByYearDay(iterator);
1124
1177
  }
1178
+ if (this.opts.rscale && this.opts.freq === "MONTHLY" && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byWeekNo && !this.opts.byYearDay) {
1179
+ return this._allMonthlyRscaleSimple(iterator);
1180
+ }
1125
1181
  if ((this.opts.freq === "MINUTELY" || this.opts.freq === "HOURLY" || this.opts.freq === "DAILY") && this.opts.bySetPos) {
1126
1182
  return this._allDailyMinutelyHourlyWithBySetPos(iterator);
1127
1183
  }
1128
1184
  return this._allFallback(iterator);
1129
1185
  }
1186
+ /**
1187
+ * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
1188
+ * Handles month-to-month stepping from DTSTART's year/month aiming for DTSTART's day-of-month.
1189
+ * Applies SKIP=OMIT (skip invalid months), BACKWARD (clamp to last day), FORWARD (first day of next month).
1190
+ */
1191
+ _allMonthlyRscaleSimple(iterator) {
1192
+ var _a;
1193
+ const dates = [];
1194
+ let iterationCount = 0;
1195
+ const start = this.originalDtstart;
1196
+ const interval = (_a = this.opts.interval) != null ? _a : 1;
1197
+ const targetDom = start.day;
1198
+ if (!this.addDtstartIfNeeded(dates, iterator)) {
1199
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
1200
+ }
1201
+ let cursor = start.with({ day: 1 });
1202
+ while (true) {
1203
+ if (++iterationCount > this.maxIterations) {
1204
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
1205
+ }
1206
+ const lastDay = cursor.add({ months: 1 }).subtract({ days: 1 }).day;
1207
+ let occ = null;
1208
+ if (targetDom <= lastDay) {
1209
+ occ = cursor.with({ day: targetDom });
1210
+ } else {
1211
+ const skip = this.opts.skip || "OMIT";
1212
+ if (skip === "BACKWARD") {
1213
+ occ = cursor.with({ day: lastDay });
1214
+ } else if (skip === "FORWARD") {
1215
+ occ = cursor.add({ months: 1 }).with({ day: 1 });
1216
+ } else {
1217
+ occ = null;
1218
+ }
1219
+ }
1220
+ if (occ) {
1221
+ occ = occ.with({ hour: start.hour, minute: start.minute, second: start.second });
1222
+ if (!(iterator && this.isExcluded(occ))) {
1223
+ if (Temporal.ZonedDateTime.compare(occ, start) >= 0) {
1224
+ if (!iterator || iterator(occ, dates.length)) {
1225
+ dates.push(occ);
1226
+ if (this.shouldBreakForCountLimit(dates.length)) break;
1227
+ } else {
1228
+ break;
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+ cursor = cursor.add({ months: interval });
1234
+ if (this.opts.until && Temporal.ZonedDateTime.compare(cursor, this.opts.until) > 0) {
1235
+ break;
1236
+ }
1237
+ }
1238
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
1239
+ }
1130
1240
  /**
1131
1241
  * Converts rDate entries to ZonedDateTime and merges with existing dates.
1132
1242
  * @param dates - Array of dates to merge with
@@ -1347,6 +1457,8 @@ var RRuleTemporal = class _RRuleTemporal {
1347
1457
  rDate,
1348
1458
  exDate
1349
1459
  } = this.opts;
1460
+ if (this.opts.rscale) rule.push(`RSCALE=${this.opts.rscale}`);
1461
+ if (this.opts.rscale && this.opts.skip) rule.push(`SKIP=${this.opts.skip}`);
1350
1462
  rule.push(`FREQ=${freq}`);
1351
1463
  if (interval !== 1) rule.push(`INTERVAL=${interval}`);
1352
1464
  if (count !== void 0) rule.push(`COUNT=${count}`);
@@ -1442,7 +1554,7 @@ var RRuleTemporal = class _RRuleTemporal {
1442
1554
  * if BYMONTH is not specified.
1443
1555
  */
1444
1556
  generateYearlyOccurrences(sample) {
1445
- 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];
1557
+ 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];
1446
1558
  let occs = [];
1447
1559
  const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
1448
1560
  if (hasOrdinalByDay && !this.opts.byMonth) {
@@ -1465,10 +1577,28 @@ var RRuleTemporal = class _RRuleTemporal {
1465
1577
  occs.push(...this.expandByTime(dt));
1466
1578
  }
1467
1579
  } else if (!this.opts.byYearDay && !this.opts.byWeekNo) {
1468
- occs = months.flatMap((m) => {
1580
+ occs = [];
1581
+ for (const m of months) {
1469
1582
  const monthSample = sample.with({ month: m, day: 1 });
1470
- return this.generateMonthlyOccurrences(monthSample);
1471
- });
1583
+ const monthOccs = this.generateMonthlyOccurrences(monthSample);
1584
+ if (monthOccs.length === 0 && this.opts.rscale && this.opts.byMonthDay && this.opts.byMonthDay.length > 0) {
1585
+ const lastDay = monthSample.add({ months: 1 }).subtract({ days: 1 }).day;
1586
+ const target = this.opts.byMonthDay[0];
1587
+ const absTarget = target > 0 ? target : lastDay + target + 1;
1588
+ if (absTarget > lastDay || absTarget <= 0) {
1589
+ const skip = this.opts.skip || "OMIT";
1590
+ if (skip === "BACKWARD") {
1591
+ occs.push(...this.expandByTime(monthSample.with({ day: lastDay })));
1592
+ } else if (skip === "FORWARD") {
1593
+ const nextMonth = monthSample.add({ months: 1 }).with({ day: 1 });
1594
+ occs.push(...this.expandByTime(nextMonth));
1595
+ } else {
1596
+ }
1597
+ }
1598
+ } else {
1599
+ occs.push(...monthOccs);
1600
+ }
1601
+ }
1472
1602
  }
1473
1603
  if (this.opts.byYearDay) {
1474
1604
  const last = sample.with({ month: 12, day: 31 }).dayOfYear;
@@ -1534,16 +1664,19 @@ var RRuleTemporal = class _RRuleTemporal {
1534
1664
  }
1535
1665
  }
1536
1666
  }
1537
- if (this.opts.byMonth && !this.opts.byMonth.includes(current.month)) {
1538
- const months = [...this.opts.byMonth].sort((a, b) => a - b);
1539
- const nextMonth = this.findNextValidValue(current.month, months, (a, b) => a - b);
1540
- if (nextMonth) {
1541
- current = current.with({ month: nextMonth, day: 1, hour: 0, minute: 0, second: 0 });
1542
- } else {
1543
- current = current.add({ years: 1 }).with({ month: months[0], day: 1, hour: 0, minute: 0, second: 0 });
1667
+ if (this.opts.byMonth) {
1668
+ const numericMonths = this.opts.byMonth.filter((v) => typeof v === "number");
1669
+ if (numericMonths.length && !numericMonths.includes(current.month)) {
1670
+ const months = [...numericMonths].sort((a, b) => a - b);
1671
+ const nextMonth = this.findNextValidValue(current.month, months, (a, b) => a - b);
1672
+ if (nextMonth) {
1673
+ current = current.with({ month: nextMonth, day: 1, hour: 0, minute: 0, second: 0 });
1674
+ } else {
1675
+ current = current.add({ years: 1 }).with({ month: months[0], day: 1, hour: 0, minute: 0, second: 0 });
1676
+ }
1677
+ current = this.applyTimeOverride(current);
1678
+ return current;
1544
1679
  }
1545
- current = this.applyTimeOverride(current);
1546
- return current;
1547
1680
  }
1548
1681
  if (this.opts.byWeekNo && !this.matchesByWeekNo(current)) {
1549
1682
  current = current.add({ weeks: 1 }).with({ hour: 0, minute: 0, second: 0 });
@@ -1687,6 +1820,416 @@ var RRuleTemporal = class _RRuleTemporal {
1687
1820
  occs.push(...this.addByDay(tokens, weekStart));
1688
1821
  return occs.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
1689
1822
  }
1823
+ // ===== RSCALE (non-Gregorian) support: Chinese and Hebrew =====
1824
+ getRscaleCalendarId() {
1825
+ var _a;
1826
+ const map = {
1827
+ GREGORIAN: "gregory",
1828
+ CHINESE: "chinese",
1829
+ HEBREW: "hebrew",
1830
+ INDIAN: "indian"
1831
+ };
1832
+ const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
1833
+ return map[r] || null;
1834
+ }
1835
+ pad2(n) {
1836
+ return String(n).padStart(2, "0");
1837
+ }
1838
+ monthMatchesToken(monthCode, token) {
1839
+ if (typeof token === "number") {
1840
+ return monthCode === `M${this.pad2(token)}`;
1841
+ }
1842
+ if (/^\d+L$/i.test(token)) {
1843
+ const n = parseInt(token, 10);
1844
+ return monthCode === `M${this.pad2(n)}L`;
1845
+ }
1846
+ return false;
1847
+ }
1848
+ monthsOfYear(calId, year) {
1849
+ const out = [];
1850
+ for (let m = 1; m <= 20; m++) {
1851
+ try {
1852
+ const d = Temporal.PlainDate.from({ calendar: calId, year, month: m, day: 1 });
1853
+ out.push(d);
1854
+ } catch (e) {
1855
+ break;
1856
+ }
1857
+ }
1858
+ return out;
1859
+ }
1860
+ startOfYear(calId, year) {
1861
+ return Temporal.PlainDate.from({ calendar: calId, year, month: 1, day: 1 });
1862
+ }
1863
+ endOfYear(calId, year) {
1864
+ return this.startOfYear(calId, year + 1).subtract({ days: 1 });
1865
+ }
1866
+ rscaleFirstWeekStart(calId, year, wkst) {
1867
+ const jan4 = Temporal.PlainDate.from({ calendar: calId, year, month: 1, day: 4 });
1868
+ const delta = (jan4.dayOfWeek - wkst + 7) % 7;
1869
+ return jan4.subtract({ days: delta });
1870
+ }
1871
+ rscaleLastWeekCount(calId, year, wkst) {
1872
+ const firstWeekStart = this.rscaleFirstWeekStart(calId, year, wkst);
1873
+ const lastDay = this.endOfYear(calId, year);
1874
+ const diffDays = lastDay.since(firstWeekStart).days;
1875
+ return Math.floor(diffDays / 7) + 1;
1876
+ }
1877
+ lastDayOfMonth(pd) {
1878
+ return pd.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
1879
+ }
1880
+ buildZdtFromPlainDate(pd) {
1881
+ const t = this.originalDtstart;
1882
+ const pdt = Temporal.PlainDateTime.from({
1883
+ calendar: pd.calendarId,
1884
+ year: pd.year,
1885
+ month: pd.month,
1886
+ day: pd.day,
1887
+ hour: t.hour,
1888
+ minute: t.minute,
1889
+ second: t.second
1890
+ });
1891
+ return pdt.toZonedDateTime(this.tzid);
1892
+ }
1893
+ rscaleMatchesByYearDay(calId, pd) {
1894
+ const list = this.opts.byYearDay;
1895
+ if (!list || list.length === 0) return true;
1896
+ const last = this.endOfYear(calId, pd.year).dayOfYear;
1897
+ return list.some((d) => d > 0 ? pd.dayOfYear === d : pd.dayOfYear === last + d + 1);
1898
+ }
1899
+ rscaleMatchesByWeekNo(calId, pd) {
1900
+ const list = this.opts.byWeekNo;
1901
+ if (!list || list.length === 0) return true;
1902
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1903
+ const wkst = dayMap[this.opts.wkst || "MO"];
1904
+ const weekStart = pd.subtract({ days: (pd.dayOfWeek - wkst + 7) % 7 });
1905
+ const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
1906
+ const weekYear = thursday.year;
1907
+ const firstStart = this.rscaleFirstWeekStart(calId, weekYear, wkst);
1908
+ const lastWeek = this.rscaleLastWeekCount(calId, weekYear, wkst);
1909
+ const idx = Math.floor(pd.since(firstStart).days / 7) + 1;
1910
+ return list.some((wn) => wn > 0 ? idx === wn : idx === lastWeek + wn + 1);
1911
+ }
1912
+ rscaleMatchesByMonth(calId, pd) {
1913
+ const tokens = this.opts.byMonth;
1914
+ if (!tokens || tokens.length === 0) return true;
1915
+ return tokens.some((tok) => this.monthMatchesToken(pd.monthCode, tok));
1916
+ }
1917
+ rscaleMatchesByMonthDay(pd) {
1918
+ const list = this.opts.byMonthDay;
1919
+ if (!list || list.length === 0) return true;
1920
+ const last = pd.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
1921
+ const value = pd.day;
1922
+ return list.some((d) => d > 0 ? value === d : value === last + d + 1);
1923
+ }
1924
+ rscaleMatchesByDayBasic(pd) {
1925
+ const byDay = this.opts.byDay;
1926
+ if (!byDay || byDay.length === 0) return true;
1927
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1928
+ const tokens = byDay.map((tok) => {
1929
+ var _a;
1930
+ return (_a = tok.match(/^(?:[+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
1931
+ }).filter((x) => !!x);
1932
+ if (tokens.length === 0) return true;
1933
+ return tokens.some((wd) => dayMap[wd] === pd.dayOfWeek);
1934
+ }
1935
+ rscaleDateMatches(calId, pd) {
1936
+ return this.rscaleMatchesByMonth(calId, pd) && this.rscaleMatchesByYearDay(calId, pd) && this.rscaleMatchesByWeekNo(calId, pd) && this.rscaleMatchesByMonthDay(pd) && this.rscaleMatchesByDayBasic(pd);
1937
+ }
1938
+ applySkipForDay(calId, year, monthStart, targetDay) {
1939
+ const last = this.lastDayOfMonth(monthStart);
1940
+ const skip = this.opts.skip || "OMIT";
1941
+ if (targetDay >= 1 && targetDay <= last) {
1942
+ return monthStart.with({ day: targetDay });
1943
+ }
1944
+ if (skip === "BACKWARD") {
1945
+ return monthStart.with({ day: last });
1946
+ }
1947
+ if (skip === "FORWARD") {
1948
+ const nextMonthStart = monthStart.add({ months: 1 });
1949
+ return nextMonthStart.with({ day: 1 });
1950
+ }
1951
+ return null;
1952
+ }
1953
+ generateMonthlyOccurrencesRscale(calId, year, monthStart) {
1954
+ const occs = [];
1955
+ const byMonthDay = this.opts.byMonthDay;
1956
+ const byDay = this.opts.byDay;
1957
+ if (!byDay && !byMonthDay) {
1958
+ const targetDay = this.originalDtstart.withCalendar(calId).day;
1959
+ const pd = this.applySkipForDay(calId, year, monthStart, targetDay);
1960
+ if (pd) occs.push(this.buildZdtFromPlainDate(pd));
1961
+ return occs;
1962
+ }
1963
+ const addZ = (pd) => {
1964
+ occs.push(this.buildZdtFromPlainDate(pd));
1965
+ };
1966
+ const last = this.lastDayOfMonth(monthStart);
1967
+ const resolveDay = (d) => d > 0 ? d : last + d + 1;
1968
+ if (byMonthDay && byMonthDay.length > 0) {
1969
+ for (const raw of byMonthDay) {
1970
+ const dayNum = resolveDay(raw);
1971
+ const pd = this.applySkipForDay(calId, year, monthStart, dayNum);
1972
+ if (pd) addZ(pd);
1973
+ }
1974
+ }
1975
+ if (byDay && byDay.length > 0) {
1976
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
1977
+ const buckets = {};
1978
+ let cur = monthStart;
1979
+ while (cur.month === monthStart.month && cur.year === monthStart.year) {
1980
+ const wd = cur.dayOfWeek;
1981
+ (buckets[wd] || (buckets[wd] = [])).push(cur);
1982
+ cur = cur.add({ days: 1 });
1983
+ }
1984
+ for (const tok of byDay) {
1985
+ const m = tok.match(/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/);
1986
+ if (!m) continue;
1987
+ const ord = m[1] ? parseInt(m[1], 10) : 0;
1988
+ const wd = dayMap[m[2]];
1989
+ const list = buckets[wd] || [];
1990
+ if (list.length === 0) continue;
1991
+ if (ord === 0) {
1992
+ for (const pd of list) addZ(pd);
1993
+ } else {
1994
+ const idx = ord > 0 ? ord - 1 : list.length + ord;
1995
+ const pd = list[idx];
1996
+ if (pd) addZ(pd);
1997
+ }
1998
+ }
1999
+ }
2000
+ return this.applyBySetPos(occs).sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
2001
+ }
2002
+ _allRscaleNonGregorian(iterator) {
2003
+ var _a, _b, _c, _d, _e, _f, _g;
2004
+ const calId = this.getRscaleCalendarId();
2005
+ if (!calId) return this._allFallback(iterator);
2006
+ const dates = [];
2007
+ let iterationCount = 0;
2008
+ const start = this.originalDtstart;
2009
+ const seed = start.withCalendar(calId);
2010
+ const interval = (_a = this.opts.interval) != null ? _a : 1;
2011
+ if (!this.addDtstartIfNeeded(dates, iterator)) {
2012
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2013
+ }
2014
+ if (this.opts.freq === "YEARLY") {
2015
+ let yearOffset = 0;
2016
+ while (true) {
2017
+ if (++iterationCount > this.maxIterations) {
2018
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2019
+ }
2020
+ const tgtYear = seed.year + yearOffset * interval;
2021
+ let occs = [];
2022
+ const monthsTokens = this.opts.byMonth;
2023
+ const months = this.monthsOfYear(calId, tgtYear);
2024
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2025
+ const wkst = dayMap[this.opts.wkst || "MO"];
2026
+ if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
2027
+ const firstStart = this.rscaleFirstWeekStart(calId, tgtYear, wkst);
2028
+ const lastWeek = this.rscaleLastWeekCount(calId, tgtYear, wkst);
2029
+ const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) => {
2030
+ var _a2;
2031
+ return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2032
+ }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2033
+ for (const wn of this.opts.byWeekNo) {
2034
+ let idx = wn > 0 ? wn - 1 : lastWeek + wn;
2035
+ if (idx < 0 || idx >= lastWeek) continue;
2036
+ const weekStart = firstStart.add({ weeks: idx });
2037
+ for (const tok of tokens) {
2038
+ const targetDow = dayMap[tok];
2039
+ const pd = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
2040
+ if (monthsTokens && monthsTokens.length > 0) {
2041
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2042
+ }
2043
+ if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2044
+ const lastDay = this.endOfYear(calId, tgtYear).dayOfYear;
2045
+ const matches = this.opts.byYearDay.some((d) => {
2046
+ const target = d > 0 ? d : lastDay + d + 1;
2047
+ return pd.dayOfYear === target;
2048
+ });
2049
+ if (!matches) continue;
2050
+ }
2051
+ occs.push(this.buildZdtFromPlainDate(pd));
2052
+ }
2053
+ }
2054
+ } else if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2055
+ const startOfYear = this.startOfYear(calId, tgtYear);
2056
+ const lastDay = this.endOfYear(calId, tgtYear).dayOfYear;
2057
+ for (const d of this.opts.byYearDay) {
2058
+ const target = d > 0 ? d : lastDay + d + 1;
2059
+ if (target < 1 || target > lastDay) continue;
2060
+ let pd = startOfYear.add({ days: target - 1 });
2061
+ if (monthsTokens && monthsTokens.length > 0) {
2062
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2063
+ }
2064
+ occs.push(this.buildZdtFromPlainDate(pd));
2065
+ }
2066
+ } else if (!monthsTokens || monthsTokens.length === 0) {
2067
+ try {
2068
+ const pd = Temporal.PlainDate.from({
2069
+ calendar: calId,
2070
+ year: tgtYear,
2071
+ monthCode: seed.monthCode,
2072
+ day: seed.day
2073
+ });
2074
+ occs.push(this.buildZdtFromPlainDate(pd));
2075
+ } catch (e) {
2076
+ const skip = this.opts.skip || "OMIT";
2077
+ if (skip === "FORWARD" || skip === "BACKWARD") {
2078
+ const mapped = seed.with({ year: tgtYear });
2079
+ const adjusted = skip === "BACKWARD" ? mapped.subtract({ days: 1 }) : mapped;
2080
+ occs.push(adjusted.withCalendar("iso8601"));
2081
+ }
2082
+ }
2083
+ } else {
2084
+ const monthStarts = months.filter((m) => monthsTokens.some((tok) => this.monthMatchesToken(m.monthCode, tok)));
2085
+ for (const ms of monthStarts) {
2086
+ occs.push(...this.generateMonthlyOccurrencesRscale(calId, tgtYear, ms));
2087
+ }
2088
+ }
2089
+ if (occs.length > 0) {
2090
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2091
+ const sorted = expanded.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
2092
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2093
+ if (shouldBreak) break;
2094
+ }
2095
+ yearOffset++;
2096
+ if (this.opts.until && tgtYear > this.opts.until.withCalendar(calId).year) break;
2097
+ }
2098
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2099
+ }
2100
+ if (this.opts.freq === "WEEKLY") {
2101
+ const dayMap = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
2102
+ const wkst = dayMap[this.opts.wkst || "MO"];
2103
+ const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) => {
2104
+ var _a2;
2105
+ return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
2106
+ }) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
2107
+ let weekStart = seed.toPlainDate().subtract({ days: (seed.dayOfWeek - wkst + 7) % 7 });
2108
+ while (true) {
2109
+ if (++iterationCount > this.maxIterations) {
2110
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2111
+ }
2112
+ const occs = [];
2113
+ for (const tok of tokens) {
2114
+ const targetDow = dayMap[tok];
2115
+ const pd = weekStart.add({ days: (targetDow - wkst + 7) % 7 });
2116
+ if (Temporal.ZonedDateTime.compare(this.buildZdtFromPlainDate(pd), this.originalDtstart) < 0) {
2117
+ continue;
2118
+ }
2119
+ if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
2120
+ const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
2121
+ const weekYear = thursday.year;
2122
+ const firstStart = this.rscaleFirstWeekStart(calId, weekYear, wkst);
2123
+ const lastWeek = this.rscaleLastWeekCount(calId, weekYear, wkst);
2124
+ const idx = Math.floor(pd.since(firstStart).days / 7) + 1;
2125
+ const match = this.opts.byWeekNo.some((wn) => wn > 0 ? idx === wn : idx === lastWeek + wn + 1);
2126
+ if (!match) continue;
2127
+ }
2128
+ if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
2129
+ const last = this.endOfYear(calId, pd.year).dayOfYear;
2130
+ const match = this.opts.byYearDay.some((d) => d > 0 ? pd.dayOfYear === d : pd.dayOfYear === last + d + 1);
2131
+ if (!match) continue;
2132
+ }
2133
+ const monthsTokens = this.opts.byMonth;
2134
+ if (monthsTokens && monthsTokens.length > 0) {
2135
+ if (!monthsTokens.some((t) => this.monthMatchesToken(pd.monthCode, t))) continue;
2136
+ }
2137
+ occs.push(this.buildZdtFromPlainDate(pd));
2138
+ }
2139
+ if (occs.length) {
2140
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2141
+ const sorted = expanded.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
2142
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2143
+ if (shouldBreak) return this.applyCountLimitAndMergeRDates(dates, iterator);
2144
+ }
2145
+ weekStart = weekStart.add({ weeks: (_d = this.opts.interval) != null ? _d : 1 });
2146
+ if (this.opts.until) {
2147
+ const z = this.buildZdtFromPlainDate(weekStart.add({ days: 6 }));
2148
+ if (Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2149
+ }
2150
+ }
2151
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2152
+ }
2153
+ if (this.opts.freq === "MONTHLY") {
2154
+ let cursor = seed.toPlainDate().with({ day: 1 });
2155
+ while (true) {
2156
+ if (++iterationCount > this.maxIterations) {
2157
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2158
+ }
2159
+ const year = cursor.year;
2160
+ const monthStart = cursor;
2161
+ let proceed = true;
2162
+ const monthsTokens = this.opts.byMonth;
2163
+ if (monthsTokens && monthsTokens.length > 0) {
2164
+ proceed = monthsTokens.some((tok) => this.monthMatchesToken(monthStart.monthCode, tok));
2165
+ }
2166
+ if (proceed) {
2167
+ const occs = this.generateMonthlyOccurrencesRscale(calId, year, monthStart);
2168
+ const expanded = occs.flatMap((z) => this.expandByTime(z));
2169
+ const sorted = expanded.sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
2170
+ const { shouldBreak } = this.processOccurrences(sorted, dates, start, iterator);
2171
+ if (shouldBreak) break;
2172
+ }
2173
+ cursor = cursor.add({ months: (_e = this.opts.interval) != null ? _e : 1 });
2174
+ if (this.opts.until) {
2175
+ const z = this.buildZdtFromPlainDate(cursor);
2176
+ if (Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2177
+ }
2178
+ }
2179
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2180
+ }
2181
+ if (this.opts.freq === "DAILY") {
2182
+ let pd = seed.toPlainDate();
2183
+ while (true) {
2184
+ if (++iterationCount > this.maxIterations) {
2185
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2186
+ }
2187
+ if (this.rscaleDateMatches(calId, pd)) {
2188
+ const base = this.buildZdtFromPlainDate(pd);
2189
+ let occs = this.expandByTime(base);
2190
+ occs = this.applyBySetPos(occs);
2191
+ const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
2192
+ if (shouldBreak) break;
2193
+ }
2194
+ pd = pd.add({ days: (_f = this.opts.interval) != null ? _f : 1 });
2195
+ if (this.opts.until) {
2196
+ const z = this.buildZdtFromPlainDate(pd);
2197
+ if (Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2198
+ }
2199
+ }
2200
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2201
+ }
2202
+ if (this.opts.freq === "HOURLY" || this.opts.freq === "MINUTELY") {
2203
+ const unit = this.opts.freq === "HOURLY" ? "hour" : "minute";
2204
+ const unitMs = this.opts.freq === "HOURLY" ? 36e5 : 6e4;
2205
+ const interval2 = (_g = this.opts.interval) != null ? _g : 1;
2206
+ let pd = seed.toPlainDate();
2207
+ const startInstantMs = this.originalDtstart.toInstant().epochMilliseconds;
2208
+ while (true) {
2209
+ if (++iterationCount > this.maxIterations) {
2210
+ throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
2211
+ }
2212
+ if (this.rscaleDateMatches(calId, pd)) {
2213
+ const base = this.buildZdtFromPlainDate(pd);
2214
+ let occs = this.expandByTime(base);
2215
+ occs = occs.filter((occ) => {
2216
+ const delta = occ.toInstant().epochMilliseconds - startInstantMs;
2217
+ const steps = Math.floor(delta / unitMs);
2218
+ return steps % interval2 === 0;
2219
+ });
2220
+ const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
2221
+ if (shouldBreak) break;
2222
+ }
2223
+ pd = pd.add({ days: 1 });
2224
+ if (this.opts.until) {
2225
+ const z = this.buildZdtFromPlainDate(pd);
2226
+ if (Temporal.ZonedDateTime.compare(z, this.opts.until) > 0) break;
2227
+ }
2228
+ }
2229
+ return this.applyCountLimitAndMergeRDates(dates, iterator);
2230
+ }
2231
+ return this._allFallback(iterator);
2232
+ }
1690
2233
  };
1691
2234
 
1692
2235
  export {