rrule-temporal 2.0.2 → 2.0.3

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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-BQ3CQXjR.cjs");
2
+ const require_src = require("./src-DmTIBKXY.cjs");
3
3
  exports.RRuleTemporal = require_src.RRuleTemporal;
4
4
  exports.allowedFreq = require_src.allowedFreq;
5
5
  exports.allowedWeekdays = require_src.allowedWeekdays;
package/dist/index.d.cts CHANGED
@@ -255,17 +255,21 @@ declare class RRuleTemporal {
255
255
  */
256
256
  private excludeExDates;
257
257
  /**
258
- * Applies count limit and merges rDates with the rule-generated dates.
258
+ * Finalizes the recurrence set in RFC 5545 order: bound the RRULE-generated
259
+ * dates by COUNT, union RDATE, then subtract EXDATE.
259
260
  * @param dates - Array of dates generated by the rule
260
261
  * @param iterator - Optional iterator function
261
- * @returns Final array of dates after merging and applying count limit
262
+ * @returns Final recurrence set
262
263
  */
263
264
  private applyCountLimitAndMergeRDates;
264
265
  /**
265
- * Checks if the count limit should break the loop based on rDate presence.
266
- * @param matchCount - Current number of matches
267
- * @returns true if the loop should break
266
+ * Streams the final recurrence set without materializing the complete RRULE.
267
+ * A rule-only instance keeps COUNT/UNTIL scoped to RRULE generation while
268
+ * sorted RDATE values are merged and EXDATE values are filtered at emission.
268
269
  */
270
+ private iterateRecurrenceSet;
271
+ private applyIterator;
272
+ /** Stops RRULE generation once COUNT rule occurrences have been found. */
269
273
  private shouldBreakForCountLimit;
270
274
  private hasTimeOfDayBetween;
271
275
  /**
package/dist/index.d.ts CHANGED
@@ -255,17 +255,21 @@ declare class RRuleTemporal {
255
255
  */
256
256
  private excludeExDates;
257
257
  /**
258
- * Applies count limit and merges rDates with the rule-generated dates.
258
+ * Finalizes the recurrence set in RFC 5545 order: bound the RRULE-generated
259
+ * dates by COUNT, union RDATE, then subtract EXDATE.
259
260
  * @param dates - Array of dates generated by the rule
260
261
  * @param iterator - Optional iterator function
261
- * @returns Final array of dates after merging and applying count limit
262
+ * @returns Final recurrence set
262
263
  */
263
264
  private applyCountLimitAndMergeRDates;
264
265
  /**
265
- * Checks if the count limit should break the loop based on rDate presence.
266
- * @param matchCount - Current number of matches
267
- * @returns true if the loop should break
266
+ * Streams the final recurrence set without materializing the complete RRULE.
267
+ * A rule-only instance keeps COUNT/UNTIL scoped to RRULE generation while
268
+ * sorted RDATE values are merged and EXDATE values are filtered at emission.
268
269
  */
270
+ private iterateRecurrenceSet;
271
+ private applyIterator;
272
+ /** Stops RRULE generation once COUNT rule occurrences have been found. */
269
273
  private shouldBreakForCountLimit;
270
274
  private hasTimeOfDayBetween;
271
275
  /**
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as weekdayToIsoDay, n as allowedFreq, r as allowedWeekdays, t as RRuleTemporal } from "./src-PFG2hz2E.js";
1
+ import { i as weekdayToIsoDay, n as allowedFreq, r as allowedWeekdays, t as RRuleTemporal } from "./src-lJCsc0ll.js";
2
2
  export { RRuleTemporal, allowedFreq, allowedWeekdays, weekdayToIsoDay };
@@ -6542,6 +6542,7 @@ var RRuleTemporal = class RRuleTemporal {
6542
6542
  if (!possibleDate) return [];
6543
6543
  }
6544
6544
  if (!this.opts.count && !this.opts.until && !iterator) throw new Error("all() requires iterator when no COUNT/UNTIL");
6545
+ if (iterator && (this.opts.rDate || this.opts.exDate)) return this.iterateRecurrenceSet(iterator);
6545
6546
  const utcFastPathDates = this.allUtcFastPath(iterator);
6546
6547
  if (utcFastPathDates) return utcFastPathDates;
6547
6548
  const tzFastPathDates = this.allTzEpochFastPath(iterator);
@@ -6643,38 +6644,73 @@ var RRuleTemporal = class RRuleTemporal {
6643
6644
  });
6644
6645
  }
6645
6646
  /**
6646
- * Applies count limit and merges rDates with the rule-generated dates.
6647
+ * Finalizes the recurrence set in RFC 5545 order: bound the RRULE-generated
6648
+ * dates by COUNT, union RDATE, then subtract EXDATE.
6647
6649
  * @param dates - Array of dates generated by the rule
6648
6650
  * @param iterator - Optional iterator function
6649
- * @returns Final array of dates after merging and applying count limit
6651
+ * @returns Final recurrence set
6650
6652
  */
6651
6653
  applyCountLimitAndMergeRDates(dates, iterator) {
6652
- const merged = this.mergeAndDeduplicateRDates(dates);
6654
+ const ruleDates = this.opts.count === void 0 ? dates : dates.slice(0, Math.max(this.opts.count, 0));
6655
+ const merged = this.mergeAndDeduplicateRDates(ruleDates);
6653
6656
  const excluded = this.excludeExDates(merged);
6654
- const hasCountLimit = this.opts.count !== void 0;
6655
- if (!hasCountLimit && !iterator) return excluded;
6656
- let emitted = 0;
6657
- const max = hasCountLimit ? this.opts.count : Infinity;
6657
+ if (!iterator || !this.opts.rDate && !this.opts.exDate) return excluded;
6658
+ return this.applyIterator(excluded, iterator);
6659
+ }
6660
+ /**
6661
+ * Streams the final recurrence set without materializing the complete RRULE.
6662
+ * A rule-only instance keeps COUNT/UNTIL scoped to RRULE generation while
6663
+ * sorted RDATE values are merged and EXDATE values are filtered at emission.
6664
+ */
6665
+ iterateRecurrenceSet(iterator) {
6658
6666
  const finalDates = [];
6659
- for (const d of excluded) {
6660
- if (emitted >= max) break;
6661
- if (iterator && !iterator(d, emitted)) break;
6667
+ const rDates = [...this.opts.rDate ?? []].sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
6668
+ let rDateIndex = 0;
6669
+ let lastSeenEpoch;
6670
+ let stopped = false;
6671
+ const emit = (date) => {
6672
+ const epoch = date.epochNanoseconds;
6673
+ if (lastSeenEpoch === epoch) return true;
6674
+ lastSeenEpoch = epoch;
6675
+ if (this.isExcluded(date)) return true;
6676
+ if (!iterator(date, finalDates.length)) {
6677
+ stopped = true;
6678
+ return false;
6679
+ }
6680
+ finalDates.push(date);
6681
+ return true;
6682
+ };
6683
+ const emitRDatesBefore = (epoch) => {
6684
+ while (rDateIndex < rDates.length && rDates[rDateIndex].epochNanoseconds < epoch) if (!emit(rDates[rDateIndex++])) return false;
6685
+ return true;
6686
+ };
6687
+ const ruleIterator = (date) => {
6688
+ if (!emitRDatesBefore(date.epochNanoseconds)) return false;
6689
+ if (!emit(date)) return false;
6690
+ while (rDateIndex < rDates.length && rDates[rDateIndex].epochNanoseconds === date.epochNanoseconds) rDateIndex++;
6691
+ return true;
6692
+ };
6693
+ if (this.opts.count === void 0 || this.opts.count > 0) new RRuleTemporal({
6694
+ ...this.cloneOptions(),
6695
+ rDate: void 0,
6696
+ exDate: void 0,
6697
+ cache: false
6698
+ }).allInternal(ruleIterator);
6699
+ while (!stopped && rDateIndex < rDates.length) if (!emit(rDates[rDateIndex++])) break;
6700
+ return finalDates;
6701
+ }
6702
+ applyIterator(dates, iterator) {
6703
+ const finalDates = [];
6704
+ for (const d of dates) {
6705
+ if (!iterator(d, finalDates.length)) break;
6662
6706
  finalDates.push(d);
6663
- emitted++;
6664
6707
  }
6665
6708
  return finalDates;
6666
6709
  }
6667
- /**
6668
- * Checks if the count limit should break the loop based on rDate presence.
6669
- * @param matchCount - Current number of matches
6670
- * @returns true if the loop should break
6671
- */
6710
+ /** Stops RRULE generation once COUNT rule occurrences have been found. */
6672
6711
  shouldBreakForCountLimit(matchCount) {
6673
6712
  if (this.opts.count === void 0) return false;
6674
- if (!this.opts.rDate) return matchCount >= this.opts.count;
6675
- const rDateCount = this.opts.rDate.length;
6676
- const targetRuleCount = Math.max(this.opts.count - rDateCount, 0);
6677
- return matchCount >= targetRuleCount + Math.min(targetRuleCount, 10);
6713
+ return matchCount >= this.opts.count;
6678
6714
  }
6679
6715
  hasTimeOfDayBetween(startTime, endTime) {
6680
6716
  if (Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
@@ -6542,6 +6542,7 @@ var RRuleTemporal = class RRuleTemporal {
6542
6542
  if (!possibleDate) return [];
6543
6543
  }
6544
6544
  if (!this.opts.count && !this.opts.until && !iterator) throw new Error("all() requires iterator when no COUNT/UNTIL");
6545
+ if (iterator && (this.opts.rDate || this.opts.exDate)) return this.iterateRecurrenceSet(iterator);
6545
6546
  const utcFastPathDates = this.allUtcFastPath(iterator);
6546
6547
  if (utcFastPathDates) return utcFastPathDates;
6547
6548
  const tzFastPathDates = this.allTzEpochFastPath(iterator);
@@ -6643,38 +6644,73 @@ var RRuleTemporal = class RRuleTemporal {
6643
6644
  });
6644
6645
  }
6645
6646
  /**
6646
- * Applies count limit and merges rDates with the rule-generated dates.
6647
+ * Finalizes the recurrence set in RFC 5545 order: bound the RRULE-generated
6648
+ * dates by COUNT, union RDATE, then subtract EXDATE.
6647
6649
  * @param dates - Array of dates generated by the rule
6648
6650
  * @param iterator - Optional iterator function
6649
- * @returns Final array of dates after merging and applying count limit
6651
+ * @returns Final recurrence set
6650
6652
  */
6651
6653
  applyCountLimitAndMergeRDates(dates, iterator) {
6652
- const merged = this.mergeAndDeduplicateRDates(dates);
6654
+ const ruleDates = this.opts.count === void 0 ? dates : dates.slice(0, Math.max(this.opts.count, 0));
6655
+ const merged = this.mergeAndDeduplicateRDates(ruleDates);
6653
6656
  const excluded = this.excludeExDates(merged);
6654
- const hasCountLimit = this.opts.count !== void 0;
6655
- if (!hasCountLimit && !iterator) return excluded;
6656
- let emitted = 0;
6657
- const max = hasCountLimit ? this.opts.count : Infinity;
6657
+ if (!iterator || !this.opts.rDate && !this.opts.exDate) return excluded;
6658
+ return this.applyIterator(excluded, iterator);
6659
+ }
6660
+ /**
6661
+ * Streams the final recurrence set without materializing the complete RRULE.
6662
+ * A rule-only instance keeps COUNT/UNTIL scoped to RRULE generation while
6663
+ * sorted RDATE values are merged and EXDATE values are filtered at emission.
6664
+ */
6665
+ iterateRecurrenceSet(iterator) {
6658
6666
  const finalDates = [];
6659
- for (const d of excluded) {
6660
- if (emitted >= max) break;
6661
- if (iterator && !iterator(d, emitted)) break;
6667
+ const rDates = [...this.opts.rDate ?? []].sort((a, b) => Temporal.ZonedDateTime.compare(a, b));
6668
+ let rDateIndex = 0;
6669
+ let lastSeenEpoch;
6670
+ let stopped = false;
6671
+ const emit = (date) => {
6672
+ const epoch = date.epochNanoseconds;
6673
+ if (lastSeenEpoch === epoch) return true;
6674
+ lastSeenEpoch = epoch;
6675
+ if (this.isExcluded(date)) return true;
6676
+ if (!iterator(date, finalDates.length)) {
6677
+ stopped = true;
6678
+ return false;
6679
+ }
6680
+ finalDates.push(date);
6681
+ return true;
6682
+ };
6683
+ const emitRDatesBefore = (epoch) => {
6684
+ while (rDateIndex < rDates.length && rDates[rDateIndex].epochNanoseconds < epoch) if (!emit(rDates[rDateIndex++])) return false;
6685
+ return true;
6686
+ };
6687
+ const ruleIterator = (date) => {
6688
+ if (!emitRDatesBefore(date.epochNanoseconds)) return false;
6689
+ if (!emit(date)) return false;
6690
+ while (rDateIndex < rDates.length && rDates[rDateIndex].epochNanoseconds === date.epochNanoseconds) rDateIndex++;
6691
+ return true;
6692
+ };
6693
+ if (this.opts.count === void 0 || this.opts.count > 0) new RRuleTemporal({
6694
+ ...this.cloneOptions(),
6695
+ rDate: void 0,
6696
+ exDate: void 0,
6697
+ cache: false
6698
+ }).allInternal(ruleIterator);
6699
+ while (!stopped && rDateIndex < rDates.length) if (!emit(rDates[rDateIndex++])) break;
6700
+ return finalDates;
6701
+ }
6702
+ applyIterator(dates, iterator) {
6703
+ const finalDates = [];
6704
+ for (const d of dates) {
6705
+ if (!iterator(d, finalDates.length)) break;
6662
6706
  finalDates.push(d);
6663
- emitted++;
6664
6707
  }
6665
6708
  return finalDates;
6666
6709
  }
6667
- /**
6668
- * Checks if the count limit should break the loop based on rDate presence.
6669
- * @param matchCount - Current number of matches
6670
- * @returns true if the loop should break
6671
- */
6710
+ /** Stops RRULE generation once COUNT rule occurrences have been found. */
6672
6711
  shouldBreakForCountLimit(matchCount) {
6673
6712
  if (this.opts.count === void 0) return false;
6674
- if (!this.opts.rDate) return matchCount >= this.opts.count;
6675
- const rDateCount = this.opts.rDate.length;
6676
- const targetRuleCount = Math.max(this.opts.count - rDateCount, 0);
6677
- return matchCount >= targetRuleCount + Math.min(targetRuleCount, 10);
6713
+ return matchCount >= this.opts.count;
6678
6714
  }
6679
6715
  hasTimeOfDayBetween(startTime, endTime) {
6680
6716
  if (Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
package/dist/totext.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-BQ3CQXjR.cjs");
2
+ const require_src = require("./src-DmTIBKXY.cjs");
3
3
  //#region src/totext.ts
4
4
  const en = {
5
5
  weekdayNames: [
package/dist/totext.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as allowedWeekdays, t as RRuleTemporal } from "./src-PFG2hz2E.js";
1
+ import { r as allowedWeekdays, t as RRuleTemporal } from "./src-lJCsc0ll.js";
2
2
  //#region src/totext.ts
3
3
  const en = {
4
4
  weekdayNames: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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",