rrule-temporal 1.2.6 → 1.3.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.
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
 
21
33
  // src/index.ts
22
34
  import { Temporal } from "@js-temporal/polyfill";
@@ -188,7 +200,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
188
200
  }
189
201
  return opts;
190
202
  }
191
- var RRuleTemporal = class _RRuleTemporal {
203
+ var _RRuleTemporal = class _RRuleTemporal {
192
204
  constructor(params) {
193
205
  var _a, _b, _c, _d, _e, _f, _g;
194
206
  let manual;
@@ -678,6 +690,99 @@ var RRuleTemporal = class _RRuleTemporal {
678
690
  options() {
679
691
  return this.opts;
680
692
  }
693
+ cloneOptions() {
694
+ const _a = this.opts, {
695
+ byHour,
696
+ byMinute,
697
+ bySecond,
698
+ byDay,
699
+ byMonth,
700
+ byMonthDay,
701
+ byYearDay,
702
+ byWeekNo,
703
+ bySetPos,
704
+ rDate,
705
+ exDate
706
+ } = _a, rest = __objRest(_a, [
707
+ "byHour",
708
+ "byMinute",
709
+ "bySecond",
710
+ "byDay",
711
+ "byMonth",
712
+ "byMonthDay",
713
+ "byYearDay",
714
+ "byWeekNo",
715
+ "bySetPos",
716
+ "rDate",
717
+ "exDate"
718
+ ]);
719
+ return __spreadProps(__spreadValues({}, rest), {
720
+ byHour: byHour ? [...byHour] : void 0,
721
+ byMinute: byMinute ? [...byMinute] : void 0,
722
+ bySecond: bySecond ? [...bySecond] : void 0,
723
+ byDay: byDay ? [...byDay] : void 0,
724
+ byMonth: byMonth ? [...byMonth] : void 0,
725
+ byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
726
+ byYearDay: byYearDay ? [...byYearDay] : void 0,
727
+ byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
728
+ bySetPos: bySetPos ? [...bySetPos] : void 0,
729
+ rDate: rDate ? [...rDate] : void 0,
730
+ exDate: exDate ? [...exDate] : void 0
731
+ });
732
+ }
733
+ cloneUpdateOptions(updates) {
734
+ const cloned = {};
735
+ if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
736
+ cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
737
+ }
738
+ if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
739
+ cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
740
+ }
741
+ if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
742
+ cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
743
+ }
744
+ if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
745
+ cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
746
+ }
747
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
748
+ cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
749
+ }
750
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
751
+ cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
752
+ }
753
+ if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
754
+ cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
755
+ }
756
+ if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
757
+ cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
758
+ }
759
+ if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
760
+ cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
761
+ }
762
+ if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
763
+ cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
764
+ }
765
+ if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
766
+ cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
767
+ }
768
+ return cloned;
769
+ }
770
+ /**
771
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
772
+ *
773
+ * @example
774
+ * ```ts
775
+ * const updated = rule.with({byMonthDay: [3]});
776
+ * ```
777
+ */
778
+ with(updates) {
779
+ var _a, _b;
780
+ const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
781
+ tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
782
+ dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
783
+ });
784
+ return new _RRuleTemporal(merged);
785
+ }
681
786
  addDtstartIfNeeded(dates, iterator) {
682
787
  if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
683
788
  if (iterator && this.isExcluded(this.originalDtstart)) {
@@ -1298,18 +1403,20 @@ var RRuleTemporal = class _RRuleTemporal {
1298
1403
  applyCountLimitAndMergeRDates(dates, iterator) {
1299
1404
  const merged = this.mergeAndDeduplicateRDates(dates);
1300
1405
  const excluded = this.excludeExDates(merged);
1301
- if (this.opts.count !== void 0) {
1302
- let finalCount = 0;
1303
- const finalDates = [];
1304
- for (const d of excluded) {
1305
- if (finalCount >= this.opts.count) break;
1306
- if (iterator && !iterator(d, finalCount)) break;
1307
- finalDates.push(d);
1308
- finalCount++;
1309
- }
1310
- return finalDates;
1406
+ const hasCountLimit = this.opts.count !== void 0;
1407
+ if (!hasCountLimit && !iterator) {
1408
+ return excluded;
1311
1409
  }
1312
- return excluded;
1410
+ let emitted = 0;
1411
+ const max = hasCountLimit ? this.opts.count : Infinity;
1412
+ const finalDates = [];
1413
+ for (const d of excluded) {
1414
+ if (emitted >= max) break;
1415
+ if (iterator && !iterator(d, emitted)) break;
1416
+ finalDates.push(d);
1417
+ emitted++;
1418
+ }
1419
+ return finalDates;
1313
1420
  }
1314
1421
  /**
1315
1422
  * Checks if the count limit should break the loop based on rDate presence.
@@ -1424,7 +1531,9 @@ var RRuleTemporal = class _RRuleTemporal {
1424
1531
  const inst = occ.toInstant();
1425
1532
  const ok = inc ? Temporal.Instant.compare(inst, afterInst) >= 0 : Temporal.Instant.compare(inst, afterInst) > 0;
1426
1533
  if (ok) {
1427
- result = occ;
1534
+ if (!result || Temporal.ZonedDateTime.compare(occ, result) < 0) {
1535
+ result = occ;
1536
+ }
1428
1537
  return false;
1429
1538
  }
1430
1539
  return true;
@@ -1846,6 +1955,27 @@ var RRuleTemporal = class _RRuleTemporal {
1846
1955
  const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
1847
1956
  return map[r] || null;
1848
1957
  }
1958
+ assertRscaleCalendarSupported(calId) {
1959
+ if (calId === "gregory" || calId === "iso8601") return;
1960
+ const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
1961
+ if (cached === true) return;
1962
+ if (cached === false) {
1963
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
1964
+ }
1965
+ let supported = true;
1966
+ try {
1967
+ const probe = Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
1968
+ void probe.year;
1969
+ void probe.monthCode;
1970
+ void probe.day;
1971
+ } catch (e) {
1972
+ supported = false;
1973
+ }
1974
+ _RRuleTemporal.rscaleCalendarSupport[calId] = supported;
1975
+ if (!supported) {
1976
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
1977
+ }
1978
+ }
1849
1979
  pad2(n) {
1850
1980
  return String(n).padStart(2, "0");
1851
1981
  }
@@ -2017,6 +2147,7 @@ var RRuleTemporal = class _RRuleTemporal {
2017
2147
  var _a, _b, _c, _d, _e, _f, _g;
2018
2148
  const calId = this.getRscaleCalendarId();
2019
2149
  if (!calId) return this._allFallback(iterator);
2150
+ this.assertRscaleCalendarSupported(calId);
2020
2151
  const dates = [];
2021
2152
  let iterationCount = 0;
2022
2153
  const start = this.originalDtstart;
@@ -2245,6 +2376,8 @@ var RRuleTemporal = class _RRuleTemporal {
2245
2376
  return this._allFallback(iterator);
2246
2377
  }
2247
2378
  };
2379
+ _RRuleTemporal.rscaleCalendarSupport = {};
2380
+ var RRuleTemporal = _RRuleTemporal;
2248
2381
 
2249
2382
  export {
2250
2383
  RRuleTemporal
package/dist/index.cjs CHANGED
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
23
35
  var __export = (target, all) => {
24
36
  for (var name in all)
25
37
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -209,7 +221,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
209
221
  }
210
222
  return opts;
211
223
  }
212
- var RRuleTemporal = class _RRuleTemporal {
224
+ var _RRuleTemporal = class _RRuleTemporal {
213
225
  constructor(params) {
214
226
  var _a, _b, _c, _d, _e, _f, _g;
215
227
  let manual;
@@ -699,6 +711,99 @@ var RRuleTemporal = class _RRuleTemporal {
699
711
  options() {
700
712
  return this.opts;
701
713
  }
714
+ cloneOptions() {
715
+ const _a = this.opts, {
716
+ byHour,
717
+ byMinute,
718
+ bySecond,
719
+ byDay,
720
+ byMonth,
721
+ byMonthDay,
722
+ byYearDay,
723
+ byWeekNo,
724
+ bySetPos,
725
+ rDate,
726
+ exDate
727
+ } = _a, rest = __objRest(_a, [
728
+ "byHour",
729
+ "byMinute",
730
+ "bySecond",
731
+ "byDay",
732
+ "byMonth",
733
+ "byMonthDay",
734
+ "byYearDay",
735
+ "byWeekNo",
736
+ "bySetPos",
737
+ "rDate",
738
+ "exDate"
739
+ ]);
740
+ return __spreadProps(__spreadValues({}, rest), {
741
+ byHour: byHour ? [...byHour] : void 0,
742
+ byMinute: byMinute ? [...byMinute] : void 0,
743
+ bySecond: bySecond ? [...bySecond] : void 0,
744
+ byDay: byDay ? [...byDay] : void 0,
745
+ byMonth: byMonth ? [...byMonth] : void 0,
746
+ byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
747
+ byYearDay: byYearDay ? [...byYearDay] : void 0,
748
+ byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
749
+ bySetPos: bySetPos ? [...bySetPos] : void 0,
750
+ rDate: rDate ? [...rDate] : void 0,
751
+ exDate: exDate ? [...exDate] : void 0
752
+ });
753
+ }
754
+ cloneUpdateOptions(updates) {
755
+ const cloned = {};
756
+ if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
757
+ cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
758
+ }
759
+ if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
760
+ cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
761
+ }
762
+ if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
763
+ cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
764
+ }
765
+ if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
766
+ cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
767
+ }
768
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
769
+ cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
770
+ }
771
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
772
+ cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
773
+ }
774
+ if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
775
+ cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
776
+ }
777
+ if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
778
+ cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
779
+ }
780
+ if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
781
+ cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
782
+ }
783
+ if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
784
+ cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
785
+ }
786
+ if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
787
+ cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
788
+ }
789
+ return cloned;
790
+ }
791
+ /**
792
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
793
+ *
794
+ * @example
795
+ * ```ts
796
+ * const updated = rule.with({byMonthDay: [3]});
797
+ * ```
798
+ */
799
+ with(updates) {
800
+ var _a, _b;
801
+ const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
802
+ tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
803
+ dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
804
+ });
805
+ return new _RRuleTemporal(merged);
806
+ }
702
807
  addDtstartIfNeeded(dates, iterator) {
703
808
  if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
704
809
  if (iterator && this.isExcluded(this.originalDtstart)) {
@@ -1319,18 +1424,20 @@ var RRuleTemporal = class _RRuleTemporal {
1319
1424
  applyCountLimitAndMergeRDates(dates, iterator) {
1320
1425
  const merged = this.mergeAndDeduplicateRDates(dates);
1321
1426
  const excluded = this.excludeExDates(merged);
1322
- if (this.opts.count !== void 0) {
1323
- let finalCount = 0;
1324
- const finalDates = [];
1325
- for (const d of excluded) {
1326
- if (finalCount >= this.opts.count) break;
1327
- if (iterator && !iterator(d, finalCount)) break;
1328
- finalDates.push(d);
1329
- finalCount++;
1330
- }
1331
- return finalDates;
1427
+ const hasCountLimit = this.opts.count !== void 0;
1428
+ if (!hasCountLimit && !iterator) {
1429
+ return excluded;
1332
1430
  }
1333
- return excluded;
1431
+ let emitted = 0;
1432
+ const max = hasCountLimit ? this.opts.count : Infinity;
1433
+ const finalDates = [];
1434
+ for (const d of excluded) {
1435
+ if (emitted >= max) break;
1436
+ if (iterator && !iterator(d, emitted)) break;
1437
+ finalDates.push(d);
1438
+ emitted++;
1439
+ }
1440
+ return finalDates;
1334
1441
  }
1335
1442
  /**
1336
1443
  * Checks if the count limit should break the loop based on rDate presence.
@@ -1445,7 +1552,9 @@ var RRuleTemporal = class _RRuleTemporal {
1445
1552
  const inst = occ.toInstant();
1446
1553
  const ok = inc ? import_polyfill.Temporal.Instant.compare(inst, afterInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, afterInst) > 0;
1447
1554
  if (ok) {
1448
- result = occ;
1555
+ if (!result || import_polyfill.Temporal.ZonedDateTime.compare(occ, result) < 0) {
1556
+ result = occ;
1557
+ }
1449
1558
  return false;
1450
1559
  }
1451
1560
  return true;
@@ -1867,6 +1976,27 @@ var RRuleTemporal = class _RRuleTemporal {
1867
1976
  const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
1868
1977
  return map[r] || null;
1869
1978
  }
1979
+ assertRscaleCalendarSupported(calId) {
1980
+ if (calId === "gregory" || calId === "iso8601") return;
1981
+ const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
1982
+ if (cached === true) return;
1983
+ if (cached === false) {
1984
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
1985
+ }
1986
+ let supported = true;
1987
+ try {
1988
+ const probe = import_polyfill.Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
1989
+ void probe.year;
1990
+ void probe.monthCode;
1991
+ void probe.day;
1992
+ } catch (e) {
1993
+ supported = false;
1994
+ }
1995
+ _RRuleTemporal.rscaleCalendarSupport[calId] = supported;
1996
+ if (!supported) {
1997
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
1998
+ }
1999
+ }
1870
2000
  pad2(n) {
1871
2001
  return String(n).padStart(2, "0");
1872
2002
  }
@@ -2038,6 +2168,7 @@ var RRuleTemporal = class _RRuleTemporal {
2038
2168
  var _a, _b, _c, _d, _e, _f, _g;
2039
2169
  const calId = this.getRscaleCalendarId();
2040
2170
  if (!calId) return this._allFallback(iterator);
2171
+ this.assertRscaleCalendarSupported(calId);
2041
2172
  const dates = [];
2042
2173
  let iterationCount = 0;
2043
2174
  const start = this.originalDtstart;
@@ -2266,6 +2397,8 @@ var RRuleTemporal = class _RRuleTemporal {
2266
2397
  return this._allFallback(iterator);
2267
2398
  }
2268
2399
  };
2400
+ _RRuleTemporal.rscaleCalendarSupport = {};
2401
+ var RRuleTemporal = _RRuleTemporal;
2269
2402
  // Annotate the CommonJS export names for ESM import in node:
2270
2403
  0 && (module.exports = {
2271
2404
  RRuleTemporal
package/dist/index.d.cts CHANGED
@@ -73,6 +73,7 @@ declare class RRuleTemporal {
73
73
  private readonly opts;
74
74
  private readonly maxIterations;
75
75
  private readonly includeDtstart;
76
+ private static readonly rscaleCalendarSupport;
76
77
  constructor(params: RRuleOptions);
77
78
  private sanitizeNumericArray;
78
79
  private sanitizeByDay;
@@ -98,6 +99,17 @@ declare class RRuleTemporal {
98
99
  private getIsoWeekInfo;
99
100
  private matchesByWeekNo;
100
101
  options(): ManualOpts;
102
+ private cloneOptions;
103
+ private cloneUpdateOptions;
104
+ /**
105
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const updated = rule.with({byMonthDay: [3]});
110
+ * ```
111
+ */
112
+ with(updates: Partial<ManualOpts>): RRuleTemporal;
101
113
  private addDtstartIfNeeded;
102
114
  private processOccurrences;
103
115
  /**
@@ -211,6 +223,7 @@ declare class RRuleTemporal {
211
223
  */
212
224
  private generateOccurrencesForWeekInYear;
213
225
  private getRscaleCalendarId;
226
+ private assertRscaleCalendarSupported;
214
227
  private pad2;
215
228
  private monthMatchesToken;
216
229
  private monthsOfYear;
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare class RRuleTemporal {
73
73
  private readonly opts;
74
74
  private readonly maxIterations;
75
75
  private readonly includeDtstart;
76
+ private static readonly rscaleCalendarSupport;
76
77
  constructor(params: RRuleOptions);
77
78
  private sanitizeNumericArray;
78
79
  private sanitizeByDay;
@@ -98,6 +99,17 @@ declare class RRuleTemporal {
98
99
  private getIsoWeekInfo;
99
100
  private matchesByWeekNo;
100
101
  options(): ManualOpts;
102
+ private cloneOptions;
103
+ private cloneUpdateOptions;
104
+ /**
105
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const updated = rule.with({byMonthDay: [3]});
110
+ * ```
111
+ */
112
+ with(updates: Partial<ManualOpts>): RRuleTemporal;
101
113
  private addDtstartIfNeeded;
102
114
  private processOccurrences;
103
115
  /**
@@ -211,6 +223,7 @@ declare class RRuleTemporal {
211
223
  */
212
224
  private generateOccurrencesForWeekInYear;
213
225
  private getRscaleCalendarId;
226
+ private assertRscaleCalendarSupported;
214
227
  private pad2;
215
228
  private monthMatchesToken;
216
229
  private monthsOfYear;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-UCJETDYT.js";
3
+ } from "./chunk-R242V3P5.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
23
35
  var __export = (target, all) => {
24
36
  for (var name in all)
25
37
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -211,7 +223,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
211
223
  }
212
224
  return opts;
213
225
  }
214
- var RRuleTemporal = class _RRuleTemporal {
226
+ var _RRuleTemporal = class _RRuleTemporal {
215
227
  constructor(params) {
216
228
  var _a, _b, _c, _d, _e, _f, _g;
217
229
  let manual;
@@ -701,6 +713,99 @@ var RRuleTemporal = class _RRuleTemporal {
701
713
  options() {
702
714
  return this.opts;
703
715
  }
716
+ cloneOptions() {
717
+ const _a = this.opts, {
718
+ byHour,
719
+ byMinute,
720
+ bySecond,
721
+ byDay,
722
+ byMonth,
723
+ byMonthDay,
724
+ byYearDay,
725
+ byWeekNo,
726
+ bySetPos,
727
+ rDate,
728
+ exDate
729
+ } = _a, rest = __objRest(_a, [
730
+ "byHour",
731
+ "byMinute",
732
+ "bySecond",
733
+ "byDay",
734
+ "byMonth",
735
+ "byMonthDay",
736
+ "byYearDay",
737
+ "byWeekNo",
738
+ "bySetPos",
739
+ "rDate",
740
+ "exDate"
741
+ ]);
742
+ return __spreadProps(__spreadValues({}, rest), {
743
+ byHour: byHour ? [...byHour] : void 0,
744
+ byMinute: byMinute ? [...byMinute] : void 0,
745
+ bySecond: bySecond ? [...bySecond] : void 0,
746
+ byDay: byDay ? [...byDay] : void 0,
747
+ byMonth: byMonth ? [...byMonth] : void 0,
748
+ byMonthDay: byMonthDay ? [...byMonthDay] : void 0,
749
+ byYearDay: byYearDay ? [...byYearDay] : void 0,
750
+ byWeekNo: byWeekNo ? [...byWeekNo] : void 0,
751
+ bySetPos: bySetPos ? [...bySetPos] : void 0,
752
+ rDate: rDate ? [...rDate] : void 0,
753
+ exDate: exDate ? [...exDate] : void 0
754
+ });
755
+ }
756
+ cloneUpdateOptions(updates) {
757
+ const cloned = {};
758
+ if (Object.prototype.hasOwnProperty.call(updates, "byHour")) {
759
+ cloned.byHour = Array.isArray(updates.byHour) ? [...updates.byHour] : updates.byHour;
760
+ }
761
+ if (Object.prototype.hasOwnProperty.call(updates, "byMinute")) {
762
+ cloned.byMinute = Array.isArray(updates.byMinute) ? [...updates.byMinute] : updates.byMinute;
763
+ }
764
+ if (Object.prototype.hasOwnProperty.call(updates, "bySecond")) {
765
+ cloned.bySecond = Array.isArray(updates.bySecond) ? [...updates.bySecond] : updates.bySecond;
766
+ }
767
+ if (Object.prototype.hasOwnProperty.call(updates, "byDay")) {
768
+ cloned.byDay = Array.isArray(updates.byDay) ? [...updates.byDay] : updates.byDay;
769
+ }
770
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonth")) {
771
+ cloned.byMonth = Array.isArray(updates.byMonth) ? [...updates.byMonth] : updates.byMonth;
772
+ }
773
+ if (Object.prototype.hasOwnProperty.call(updates, "byMonthDay")) {
774
+ cloned.byMonthDay = Array.isArray(updates.byMonthDay) ? [...updates.byMonthDay] : updates.byMonthDay;
775
+ }
776
+ if (Object.prototype.hasOwnProperty.call(updates, "byYearDay")) {
777
+ cloned.byYearDay = Array.isArray(updates.byYearDay) ? [...updates.byYearDay] : updates.byYearDay;
778
+ }
779
+ if (Object.prototype.hasOwnProperty.call(updates, "byWeekNo")) {
780
+ cloned.byWeekNo = Array.isArray(updates.byWeekNo) ? [...updates.byWeekNo] : updates.byWeekNo;
781
+ }
782
+ if (Object.prototype.hasOwnProperty.call(updates, "bySetPos")) {
783
+ cloned.bySetPos = Array.isArray(updates.bySetPos) ? [...updates.bySetPos] : updates.bySetPos;
784
+ }
785
+ if (Object.prototype.hasOwnProperty.call(updates, "rDate")) {
786
+ cloned.rDate = Array.isArray(updates.rDate) ? [...updates.rDate] : updates.rDate;
787
+ }
788
+ if (Object.prototype.hasOwnProperty.call(updates, "exDate")) {
789
+ cloned.exDate = Array.isArray(updates.exDate) ? [...updates.exDate] : updates.exDate;
790
+ }
791
+ return cloned;
792
+ }
793
+ /**
794
+ * Create a new {@link RRuleTemporal} instance with modified options while keeping the current one unchanged.
795
+ *
796
+ * @example
797
+ * ```ts
798
+ * const updated = rule.with({byMonthDay: [3]});
799
+ * ```
800
+ */
801
+ with(updates) {
802
+ var _a, _b;
803
+ const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.cloneOptions()), updates), this.cloneUpdateOptions(updates)), {
804
+ tzid: (_a = updates.tzid) != null ? _a : this.opts.tzid,
805
+ dtstart: (_b = updates.dtstart) != null ? _b : this.opts.dtstart
806
+ });
807
+ return new _RRuleTemporal(merged);
808
+ }
704
809
  addDtstartIfNeeded(dates, iterator) {
705
810
  if (this.includeDtstart && !this.matchesAll(this.originalDtstart)) {
706
811
  if (iterator && this.isExcluded(this.originalDtstart)) {
@@ -1321,18 +1426,20 @@ var RRuleTemporal = class _RRuleTemporal {
1321
1426
  applyCountLimitAndMergeRDates(dates, iterator) {
1322
1427
  const merged = this.mergeAndDeduplicateRDates(dates);
1323
1428
  const excluded = this.excludeExDates(merged);
1324
- if (this.opts.count !== void 0) {
1325
- let finalCount = 0;
1326
- const finalDates = [];
1327
- for (const d of excluded) {
1328
- if (finalCount >= this.opts.count) break;
1329
- if (iterator && !iterator(d, finalCount)) break;
1330
- finalDates.push(d);
1331
- finalCount++;
1332
- }
1333
- return finalDates;
1429
+ const hasCountLimit = this.opts.count !== void 0;
1430
+ if (!hasCountLimit && !iterator) {
1431
+ return excluded;
1334
1432
  }
1335
- return excluded;
1433
+ let emitted = 0;
1434
+ const max = hasCountLimit ? this.opts.count : Infinity;
1435
+ const finalDates = [];
1436
+ for (const d of excluded) {
1437
+ if (emitted >= max) break;
1438
+ if (iterator && !iterator(d, emitted)) break;
1439
+ finalDates.push(d);
1440
+ emitted++;
1441
+ }
1442
+ return finalDates;
1336
1443
  }
1337
1444
  /**
1338
1445
  * Checks if the count limit should break the loop based on rDate presence.
@@ -1447,7 +1554,9 @@ var RRuleTemporal = class _RRuleTemporal {
1447
1554
  const inst = occ.toInstant();
1448
1555
  const ok = inc ? import_polyfill.Temporal.Instant.compare(inst, afterInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, afterInst) > 0;
1449
1556
  if (ok) {
1450
- result = occ;
1557
+ if (!result || import_polyfill.Temporal.ZonedDateTime.compare(occ, result) < 0) {
1558
+ result = occ;
1559
+ }
1451
1560
  return false;
1452
1561
  }
1453
1562
  return true;
@@ -1869,6 +1978,27 @@ var RRuleTemporal = class _RRuleTemporal {
1869
1978
  const r = ((_a = this.opts.rscale) == null ? void 0 : _a.toUpperCase()) || "";
1870
1979
  return map[r] || null;
1871
1980
  }
1981
+ assertRscaleCalendarSupported(calId) {
1982
+ if (calId === "gregory" || calId === "iso8601") return;
1983
+ const cached = _RRuleTemporal.rscaleCalendarSupport[calId];
1984
+ if (cached === true) return;
1985
+ if (cached === false) {
1986
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
1987
+ }
1988
+ let supported = true;
1989
+ try {
1990
+ const probe = import_polyfill.Temporal.ZonedDateTime.from("2000-01-01T00:00:00+00:00[UTC]").withCalendar(calId);
1991
+ void probe.year;
1992
+ void probe.monthCode;
1993
+ void probe.day;
1994
+ } catch (e) {
1995
+ supported = false;
1996
+ }
1997
+ _RRuleTemporal.rscaleCalendarSupport[calId] = supported;
1998
+ if (!supported) {
1999
+ throw new Error(`RSCALE=${this.opts.rscale} is not supported by the current Temporal/Intl implementation`);
2000
+ }
2001
+ }
1872
2002
  pad2(n) {
1873
2003
  return String(n).padStart(2, "0");
1874
2004
  }
@@ -2040,6 +2170,7 @@ var RRuleTemporal = class _RRuleTemporal {
2040
2170
  var _a, _b, _c, _d, _e, _f, _g;
2041
2171
  const calId = this.getRscaleCalendarId();
2042
2172
  if (!calId) return this._allFallback(iterator);
2173
+ this.assertRscaleCalendarSupported(calId);
2043
2174
  const dates = [];
2044
2175
  let iterationCount = 0;
2045
2176
  const start = this.originalDtstart;
@@ -2268,6 +2399,8 @@ var RRuleTemporal = class _RRuleTemporal {
2268
2399
  return this._allFallback(iterator);
2269
2400
  }
2270
2401
  };
2402
+ _RRuleTemporal.rscaleCalendarSupport = {};
2403
+ var RRuleTemporal = _RRuleTemporal;
2271
2404
 
2272
2405
  // src/totext.ts
2273
2406
  var en = {
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-UCJETDYT.js";
3
+ } from "./chunk-R242V3P5.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "description": "Recurrence rule (rrule) processing using Temporal PlainDate/PlainDateTime, with cross-timezone and cross-calendar rrule support",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",