rrule-temporal 2.1.0 → 2.2.1

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/README.md CHANGED
@@ -111,9 +111,11 @@ below. These correspond to the recurrence rule parts defined in RFC 5545:
111
111
  | `rDate` | Additional dates to include. |
112
112
  | `exDate` | Exception dates to exclude. |
113
113
  | `tzid` | Time zone identifier for interpreting dates. |
114
- | `maxIterations` | Safety cap when generating occurrences. |
114
+ | `maxIterations` | Safety cap for advancing outer recurrence periods (defaults to 10,000). |
115
+ | `maxCandidateEvaluations` | Safety cap for candidate datetimes evaluated within recurrence periods (defaults to 1,000,000). |
115
116
  | `includeDtstart` | Include `DTSTART` even if it does not match the pattern. |
116
117
  | `strict` | Enforce RFC 5545 constraints strictly (defaults to false). |
118
+ | `temporal` | Optional Temporal namespace used for public output values and their inferred types. |
117
119
  | `dtstart` | First occurrence as `Temporal.ZonedDateTime`. |
118
120
 
119
121
  ### Reusable Option Lists
@@ -324,36 +326,36 @@ warmed path reuses both that table and the immutable rule's numeric query plan.
324
326
 
325
327
  ### Full recurrence generation
326
328
 
327
- Uncached median ops/s from the benchmark suite on a MacBook Pro M2 Max
328
- (Node 25, polyfill backend). The full three-library comparison, including
329
- `rrule-rust`, query methodology, and cached-mode results, lives in
330
- [`benchmarks/README.md`](benchmarks/README.md).
329
+ Uncached median ops/s for `rrule-temporal` v2.1.0 on a MacBook Pro M2 Max
330
+ (Node 25, polyfill backend). Each result is the median of five 200 ms samples
331
+ after a 200 ms warmup. The three-library comparison, query methodology, and
332
+ cached-mode summary live in [`benchmarks/README.md`](benchmarks/README.md).
331
333
 
332
334
  | Scenario | TZ | rrule-temporal median ops/s | rrule median ops/s | vs rrule |
333
335
  | --- | --- | ---: | ---: | ---: |
334
- | 30 daily occurrences | UTC | 22,308 | 17,932 | 1.24x |
335
- | 30 daily occurrences | America/Chicago | 15,358 | 384 | 40.00x |
336
- | Daily weekdays across many cycles | UTC | 1,192 | 830 | 1.44x |
337
- | Daily weekdays across many cycles | America/Chicago | 873 | 20.9 | 41.77x |
338
- | Daily time-slot expansion | UTC | 611 | 1,199 | 0.51x |
339
- | Daily time-slot expansion | America/Chicago | 448 | 11.7 | 38.29x |
340
- | 720 hourly occurrences | UTC | 817 | 757 | 1.08x |
341
- | 720 hourly occurrences | America/Chicago | 588 | 13.9 | 42.30x |
342
- | 1,440 minutely occurrences | UTC | 392 | 364 | 1.08x |
343
- | 1,440 minutely occurrences | America/Chicago | 287 | 7.4 | 38.78x |
344
- | 3,600 secondly occurrences | UTC | 152 | 144 | 1.06x |
345
- | 3,600 secondly occurrences | America/Chicago | 113 | 2.9 | 38.97x |
346
- | Weekly MO/WE/FR across many cycles | UTC | 662 | 1,137 | 0.58x |
347
- | Weekly MO/WE/FR across many cycles | America/Chicago | 493 | 14.7 | 33.54x |
348
- | Weekly day and time-slot expansion | UTC | 502 | 1,207 | 0.42x |
349
- | Weekly day and time-slot expansion | America/Chicago | 394 | 12.2 | 32.30x |
350
- | Monthly last weekday across 20 years | UTC | 1,314 | 1,119 | 1.17x |
351
- | Monthly last weekday across 20 years | America/Chicago | 1,043 | 41.7 | 25.01x |
352
- | Monthly first and last weekday across 20 years | UTC | 804 | 1,326 | 0.61x |
353
- | Monthly first and last weekday across 20 years | America/Chicago | 622 | 24.9 | 24.98x |
336
+ | 30 daily occurrences | UTC | 18,847 | 14,581 | 1.29x |
337
+ | 30 daily occurrences | America/Chicago | 12,796 | 328 | 39.01x |
338
+ | Daily weekdays across many cycles | UTC | 961 | 713 | 1.35x |
339
+ | Daily weekdays across many cycles | America/Chicago | 723 | 18.4 | 39.29x |
340
+ | Daily time-slot expansion | UTC | 488 | 1,006 | 0.49x |
341
+ | Daily time-slot expansion | America/Chicago | 371 | 10.7 | 34.67x |
342
+ | 720 hourly occurrences | UTC | 685 | 723 | 0.95x |
343
+ | 720 hourly occurrences | America/Chicago | 491 | 13.2 | 37.20x |
344
+ | 1,440 minutely occurrences | UTC | 326 | 332 | 0.98x |
345
+ | 1,440 minutely occurrences | America/Chicago | 245 | 6.8 | 36.03x |
346
+ | 3,600 secondly occurrences | UTC | 121 | 130 | 0.93x |
347
+ | 3,600 secondly occurrences | America/Chicago | 101 | 2.8 | 36.07x |
348
+ | Weekly MO/WE/FR across many cycles | UTC | 538 | 1,126 | 0.48x |
349
+ | Weekly MO/WE/FR across many cycles | America/Chicago | 418 | 13.8 | 30.29x |
350
+ | Weekly day and time-slot expansion | UTC | 426 | 1,197 | 0.36x |
351
+ | Weekly day and time-slot expansion | America/Chicago | 343 | 11.7 | 29.32x |
352
+ | Monthly last weekday across 20 years | UTC | 1,114 | 1,146 | 0.97x |
353
+ | Monthly last weekday across 20 years | America/Chicago | 921 | 43.5 | 21.17x |
354
+ | Monthly first and last weekday across 20 years | UTC | 664 | 1,287 | 0.52x |
355
+ | Monthly first and last weekday across 20 years | America/Chicago | 553 | 23.4 | 23.63x |
354
356
 
355
357
  Time-zone-aware rules iterate through an epoch-integer engine with a cached
356
- per-zone offset table, so named-zone scenarios now run 25–42x faster than
358
+ per-zone offset table, so named-zone scenarios now run 21–39x faster than
357
359
  `rrule` and within a small factor of their UTC equivalents. On UTC the two
358
360
  libraries are comparable on Node 25 (`rrule` stays ahead in several expanded
359
361
  and weekly/monthly scenarios where occurrence materialization dominates); on
@@ -428,30 +430,43 @@ Inputs are accepted from **any** Temporal implementation: `dtstart`, `until`,
428
430
  objects from `@js-temporal/polyfill`, `temporal-polyfill`, or native Temporal
429
431
  interchangeably.
430
432
 
431
- Returned occurrences come from the library's active implementation (native
432
- when available, the bundled polyfill otherwise). They are fully spec-shaped,
433
- but they will not satisfy `instanceof` checks against a *different*
434
- implementation's classes. If your app needs instances of its own Temporal
435
- implementation, re-hydrate them:
433
+ By default, returned occurrences come from the library's active implementation
434
+ (native when available, the bundled polyfill otherwise) and use
435
+ implementation-neutral `temporal-spec` types. To return instances from your
436
+ application's Temporal implementation with its exact inferred TypeScript
437
+ types, pass the optional `temporal` namespace:
436
438
 
437
439
  ```ts
438
- // your application's Temporal implementation
439
- import { Temporal as AppTemporal } from "temporal-polyfill";
440
-
440
+ import { Temporal } from "@js-temporal/polyfill";
441
441
  import { RRuleTemporal } from "rrule-temporal";
442
442
 
443
- /** Weekly rule that fires 4 times starting 5 May 2025, 10 AM America/Chicago. */
444
443
  const rule = new RRuleTemporal({
444
+ temporal: Temporal,
445
445
  freq: "WEEKLY",
446
446
  count: 4,
447
- dtstart: AppTemporal.ZonedDateTime.from(
448
- "2025-05-05T10:00[America/Chicago]"
447
+ dtstart: Temporal.ZonedDateTime.from(
448
+ "2030-05-05T10:00[America/Chicago]"
449
449
  ),
450
450
  });
451
451
 
452
- const rawOccurrences = rule.all();
452
+ const occurrence = rule.next(); // Temporal.ZonedDateTime | null
453
+ const date = occurrence?.toPlainDate(); // Temporal.PlainDate | undefined
454
+ ```
455
+
456
+ The selected implementation is used for values returned by `all()`,
457
+ `between()`, `next()`, `previous()`, iterator callbacks, `options()`, and
458
+ rules created with `with()`. Recurrence calculations still use the optimized
459
+ active implementation internally. Omitting `temporal` preserves the default
460
+ behavior.
461
+
462
+ Returned values from different implementations are fully spec-shaped but do
463
+ not satisfy `instanceof` checks against each other's classes. If a rule was
464
+ created without `temporal`, you can still re-hydrate individual results:
465
+
466
+ ```ts
467
+ import { Temporal as AppTemporal } from "@js-temporal/polyfill";
453
468
 
454
- /** Convert each ZonedDateTime into your app's implementation. */
469
+ const rawOccurrences = existingRule.all();
455
470
  const appOccurrences = rawOccurrences.map((zdt) =>
456
471
  AppTemporal.ZonedDateTime.from(zdt.toString())
457
472
  );
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-BL9G7GR8.cjs");
2
+ const require_src = require("./src-CxM15CdD.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
@@ -9,11 +9,15 @@ declare const weekdayToIsoDay: Record<Weekday, number>;
9
9
  /**
10
10
  * Shared options for all rule constructors.
11
11
  */
12
- interface BaseOpts {
12
+ interface BaseOpts<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
13
+ /** Temporal implementation used to construct public occurrence values. */
14
+ temporal?: TemporalImplementation<TOutput>;
13
15
  /** Time zone identifier as defined in RFC&nbsp;5545 §3.2.19. */
14
16
  tzid?: string;
15
- /** Safety cap when generating occurrences. */
17
+ /** Safety cap for advancing outer recurrence periods. */
16
18
  maxIterations?: number;
19
+ /** Safety cap for candidate datetimes evaluated inside recurrence periods. */
20
+ maxCandidateEvaluations?: number;
17
21
  /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
18
22
  includeDtstart?: boolean;
19
23
  /** Enforce RFC 5545 constraints strictly (defaults to false). */
@@ -34,13 +38,23 @@ interface TemporalZonedDateTimeInput {
34
38
  interface TemporalPlainDateInput {
35
39
  toString(): string;
36
40
  }
37
- type RRuleTemporalIterator = (date: TemporalZonedDateTime, i: number) => boolean;
41
+ /**
42
+ * The subset of a Temporal namespace needed to construct public occurrence
43
+ * values. Supplying an implementation makes output values and their inferred
44
+ * TypeScript types come from that implementation.
45
+ */
46
+ interface TemporalImplementation<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
47
+ readonly ZonedDateTime: {
48
+ from(value: string): TOutput;
49
+ };
50
+ }
51
+ type RRuleTemporalIterator<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = (date: TOutput, i: number) => boolean;
38
52
  type DateFilter = Date | TemporalZonedDateTimeInput;
39
53
  /**
40
54
  * Manual rule definition following the recurrence rule parts defined in
41
55
  * RFC 5545 §3.3.10.
42
56
  */
43
- interface ManualOptions extends BaseOpts {
57
+ interface ManualOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> extends BaseOpts<TOutput> {
44
58
  /** FREQ: recurrence frequency */
45
59
  freq: Freq;
46
60
  /** INTERVAL between each occurrence of {@link freq} */
@@ -76,7 +90,7 @@ interface ManualOptions extends BaseOpts {
76
90
  /** DTSTART: first occurrence */
77
91
  dtstart: TemporalZonedDateTimeInput;
78
92
  }
79
- interface IcsOptions extends BaseOpts {
93
+ interface IcsOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> extends BaseOpts<TOutput> {
80
94
  rruleString: string;
81
95
  dtstart?: TemporalZonedDateTimeInput;
82
96
  /** COUNT: total number of occurrences, used when missing from rruleString */
@@ -88,18 +102,20 @@ interface IcsOptions extends BaseOpts {
88
102
  /** EXDATE: exception dates to exclude */
89
103
  exDate?: TemporalZonedDateTimeInput[];
90
104
  }
91
- type RRuleOptions = ManualOptions | IcsOptions;
92
- type RRuleResolvedOptions = Omit<ManualOptions, 'dtstart' | 'until' | 'rDate' | 'exDate'> & {
93
- dtstart: TemporalZonedDateTime;
94
- until?: TemporalZonedDateTime;
95
- rDate?: TemporalZonedDateTime[];
96
- exDate?: TemporalZonedDateTime[];
105
+ type RRuleOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = ManualOptions<TOutput> | IcsOptions<TOutput>;
106
+ type RRuleResolvedOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = Omit<ManualOptions<TOutput>, 'dtstart' | 'until' | 'rDate' | 'exDate'> & {
107
+ dtstart: TOutput;
108
+ until?: TOutput;
109
+ rDate?: TOutput[];
110
+ exDate?: TOutput[];
97
111
  };
98
- declare class RRuleTemporal {
112
+ declare class RRuleTemporal<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
99
113
  private readonly tzid;
100
114
  private readonly originalDtstart;
101
115
  private readonly opts;
116
+ private readonly outputTemporal?;
102
117
  private readonly maxIterations;
118
+ private readonly maxCandidateEvaluations;
103
119
  private readonly includeDtstart;
104
120
  private readonly parsedByDayTokens?;
105
121
  private readonly simpleByDayIsoDays?;
@@ -120,10 +136,10 @@ declare class RRuleTemporal {
120
136
  * This prevents type mismatches when mixing native and polyfill Temporal objects.
121
137
  */
122
138
  private static normalizeToPolyfill;
123
- private static toInternalIterator;
124
- private static toPublicDate;
125
- private static toPublicDates;
126
- constructor(params: RRuleOptions);
139
+ private toInternalIterator;
140
+ private toPublicDate;
141
+ private toPublicDates;
142
+ constructor(params: RRuleOptions<TOutput>);
127
143
  private buildParsedByDayTokens;
128
144
  private buildByDayIsoDays;
129
145
  private sanitizeNumericArray;
@@ -136,6 +152,29 @@ declare class RRuleTemporal {
136
152
  * present the original date is returned unchanged.
137
153
  */
138
154
  private expandByTime;
155
+ private localDateKey;
156
+ private sortedUniqueDateCandidates;
157
+ private timeOfDayNanoseconds;
158
+ private timeSlotNanoseconds;
159
+ /**
160
+ * `ZonedDateTime.with()` can reorder or alias wall-clock slots on a day with
161
+ * an offset transition (notably when a spring-forward gap is resolved). On
162
+ * those uncommon dates we retain the legacy sort semantics with a bounded
163
+ * one-day fallback instead of ever materializing a whole recurrence period.
164
+ */
165
+ private needsSortedTimeFallback;
166
+ private createCandidateWorkBudget;
167
+ private recordCandidateEvaluation;
168
+ /**
169
+ * Visit BYHOUR x BYMINUTE x BYSECOND without allocating the Cartesian
170
+ * product. Returning false from `visit` terminates the innermost traversal
171
+ * immediately. The optional bounds are only supplied for the same local
172
+ * calendar date by `visitDateTimeCandidates`.
173
+ */
174
+ private visitTimeSlots;
175
+ private visitDateTimeCandidates;
176
+ /** Apply BYSETPOS with bounded forward/reverse passes over one period. */
177
+ private visitPeriodCandidates;
139
178
  private nextCandidateSameDate;
140
179
  private applyTimeOverride;
141
180
  private computeFirst;
@@ -150,7 +189,13 @@ declare class RRuleTemporal {
150
189
  private matchesByYearDay;
151
190
  private getIsoWeekInfo;
152
191
  private matchesByWeekNo;
153
- options(): RRuleResolvedOptions;
192
+ /**
193
+ * Gregorian weekday and leap-year patterns repeat every 400 years. Checking
194
+ * a complete cycle lets impossible BYYEARDAY + BYWEEKNO intersections stop
195
+ * without incorrectly judging the rule from DTSTART's year alone.
196
+ */
197
+ private hasPossibleYearDayWeekNoCombination;
198
+ options(): RRuleResolvedOptions<TOutput>;
154
199
  private cloneOptions;
155
200
  private cloneUpdateOptions;
156
201
  /**
@@ -161,7 +206,7 @@ declare class RRuleTemporal {
161
206
  * const updated = rule.with({byMonthDay: [3]});
162
207
  * ```
163
208
  */
164
- with(updates: Partial<ManualOptions>): RRuleTemporal;
209
+ with(updates: Partial<ManualOptions<TOutput>>): RRuleTemporal<TOutput>;
165
210
  private addDtstartIfNeeded;
166
211
  private canUseUtcLinearFastPath;
167
212
  private canUseUtcWeeklyFastPath;
@@ -190,7 +235,6 @@ declare class RRuleTemporal {
190
235
  private buildMonthlyOccurrenceOnDay;
191
236
  private applyBySetPosToSortedList;
192
237
  private generateMonthlyOccurrenceDays;
193
- private generateMonthlyOccurrencesOptimizedBySetPos;
194
238
  private isGregorianLeapYear;
195
239
  private daysInGregorianMonth;
196
240
  private gregorianIsoDayOfWeek;
@@ -218,6 +262,8 @@ declare class RRuleTemporal {
218
262
  private _allTzWeeklyExpanded;
219
263
  private _allTzMonthlyByDayOrMonthDay;
220
264
  private processOccurrences;
265
+ /** Process one occurrence and report whether generation should continue. */
266
+ private processOccurrence;
221
267
  /**
222
268
  * Returns all occurrences of the rule.
223
269
  * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
@@ -238,7 +284,7 @@ declare class RRuleTemporal {
238
284
  * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
239
285
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
240
286
  */
241
- all(iterator?: RRuleTemporalIterator): TemporalZonedDateTime[];
287
+ all(iterator?: RRuleTemporalIterator<TOutput>): TOutput[];
242
288
  private allInternal;
243
289
  /**
244
290
  * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
@@ -294,7 +340,7 @@ declare class RRuleTemporal {
294
340
  * @param inc - Optional boolean flag to include the start and end dates in the results.
295
341
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
296
342
  */
297
- between(after: DateFilter, before: DateFilter, inc?: boolean): TemporalZonedDateTime[];
343
+ between(after: DateFilter, before: DateFilter, inc?: boolean): TOutput[];
298
344
  /**
299
345
  * Compute a rule-phase-aligned DTSTART at or just before the given window
300
346
  * start, jumping forward from the original DTSTART in whole multiples of
@@ -319,7 +365,7 @@ declare class RRuleTemporal {
319
365
  * @param inc - Optional boolean flag to include occurrences on the start date.
320
366
  * @returns The next occurrence of the rule after the specified date or null if no occurrences are found.
321
367
  */
322
- next(after?: DateFilter, inc?: boolean): TemporalZonedDateTime | null;
368
+ next(after?: DateFilter, inc?: boolean): TOutput | null;
323
369
  /**
324
370
  * Build a temporary rule identical to this one but starting at the
325
371
  * phase-aligned DTSTART for the given window start. The synthetic DTSTART
@@ -332,24 +378,25 @@ declare class RRuleTemporal {
332
378
  * @param inc - Optional boolean flag to include occurrences on the end date.
333
379
  * @returns The previous occurrence of the rule before the specified date or null if no occurrences are found.
334
380
  */
335
- previous(before?: DateFilter, inc?: boolean): TemporalZonedDateTime | null;
381
+ previous(before?: DateFilter, inc?: boolean): TOutput | null;
336
382
  /** A duration of `count` steps in this rule's frequency unit. */
337
383
  private freqDuration;
338
384
  toString(): string;
339
385
  private formatIcsDateTime;
340
386
  private joinDates;
341
387
  /**
342
- * Given any date in a month, return all the ZonedDateTimes in that month
343
- * matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
388
+ * Resolve the calendar dates selected within a month without expanding any
389
+ * time BY-parts. This keeps the intermediate set bounded to calendar scale.
344
390
  */
391
+ private generateMonthlyDateCandidates;
345
392
  private generateMonthlyOccurrences;
346
393
  /**
347
- * Given any date in a year, return all ZonedDateTimes in that year matching
348
- * the BYDAY/BYMONTHDAY/BYMONTH constraints. Months default to DTSTART's month
349
- * if BYMONTH is not specified.
394
+ * Resolve one recurrence year's matching calendar dates. BYHOUR,
395
+ * BYMINUTE, BYSECOND, and BYSETPOS deliberately remain outside this helper;
396
+ * callers consume the date x time product incrementally.
350
397
  */
351
- private generateYearlyOccurrences;
352
- private addByDay;
398
+ private generateYearlyDateCandidates;
399
+ private addByDayDates;
353
400
  /**
354
401
  * Helper to find the next valid value from a sorted array
355
402
  */
@@ -364,7 +411,7 @@ declare class RRuleTemporal {
364
411
  /**
365
412
  * Generate occurrences for a specific week number in a given year
366
413
  */
367
- private generateOccurrencesForWeekInYear;
414
+ private generateDateCandidatesForWeekInYear;
368
415
  private getRscaleCalendarId;
369
416
  private assertRscaleCalendarSupported;
370
417
  private pad2;
@@ -389,4 +436,4 @@ declare class RRuleTemporal {
389
436
  private _allRscaleNonGregorian;
390
437
  }
391
438
  //#endregion
392
- export { DateFilter, Freq, RRuleOptions, RRuleResolvedOptions, RRuleTemporal, RRuleTemporalIterator, TemporalPlainDate, TemporalPlainDateInput, TemporalZonedDateTime, TemporalZonedDateTimeInput, Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
439
+ export { DateFilter, Freq, RRuleOptions, RRuleResolvedOptions, RRuleTemporal, RRuleTemporalIterator, TemporalImplementation, TemporalPlainDate, TemporalPlainDateInput, TemporalZonedDateTime, TemporalZonedDateTimeInput, Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
package/dist/index.d.ts CHANGED
@@ -9,11 +9,15 @@ declare const weekdayToIsoDay: Record<Weekday, number>;
9
9
  /**
10
10
  * Shared options for all rule constructors.
11
11
  */
12
- interface BaseOpts {
12
+ interface BaseOpts<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
13
+ /** Temporal implementation used to construct public occurrence values. */
14
+ temporal?: TemporalImplementation<TOutput>;
13
15
  /** Time zone identifier as defined in RFC&nbsp;5545 §3.2.19. */
14
16
  tzid?: string;
15
- /** Safety cap when generating occurrences. */
17
+ /** Safety cap for advancing outer recurrence periods. */
16
18
  maxIterations?: number;
19
+ /** Safety cap for candidate datetimes evaluated inside recurrence periods. */
20
+ maxCandidateEvaluations?: number;
17
21
  /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
18
22
  includeDtstart?: boolean;
19
23
  /** Enforce RFC 5545 constraints strictly (defaults to false). */
@@ -34,13 +38,23 @@ interface TemporalZonedDateTimeInput {
34
38
  interface TemporalPlainDateInput {
35
39
  toString(): string;
36
40
  }
37
- type RRuleTemporalIterator = (date: TemporalZonedDateTime, i: number) => boolean;
41
+ /**
42
+ * The subset of a Temporal namespace needed to construct public occurrence
43
+ * values. Supplying an implementation makes output values and their inferred
44
+ * TypeScript types come from that implementation.
45
+ */
46
+ interface TemporalImplementation<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
47
+ readonly ZonedDateTime: {
48
+ from(value: string): TOutput;
49
+ };
50
+ }
51
+ type RRuleTemporalIterator<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = (date: TOutput, i: number) => boolean;
38
52
  type DateFilter = Date | TemporalZonedDateTimeInput;
39
53
  /**
40
54
  * Manual rule definition following the recurrence rule parts defined in
41
55
  * RFC 5545 §3.3.10.
42
56
  */
43
- interface ManualOptions extends BaseOpts {
57
+ interface ManualOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> extends BaseOpts<TOutput> {
44
58
  /** FREQ: recurrence frequency */
45
59
  freq: Freq;
46
60
  /** INTERVAL between each occurrence of {@link freq} */
@@ -76,7 +90,7 @@ interface ManualOptions extends BaseOpts {
76
90
  /** DTSTART: first occurrence */
77
91
  dtstart: TemporalZonedDateTimeInput;
78
92
  }
79
- interface IcsOptions extends BaseOpts {
93
+ interface IcsOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> extends BaseOpts<TOutput> {
80
94
  rruleString: string;
81
95
  dtstart?: TemporalZonedDateTimeInput;
82
96
  /** COUNT: total number of occurrences, used when missing from rruleString */
@@ -88,18 +102,20 @@ interface IcsOptions extends BaseOpts {
88
102
  /** EXDATE: exception dates to exclude */
89
103
  exDate?: TemporalZonedDateTimeInput[];
90
104
  }
91
- type RRuleOptions = ManualOptions | IcsOptions;
92
- type RRuleResolvedOptions = Omit<ManualOptions, 'dtstart' | 'until' | 'rDate' | 'exDate'> & {
93
- dtstart: TemporalZonedDateTime;
94
- until?: TemporalZonedDateTime;
95
- rDate?: TemporalZonedDateTime[];
96
- exDate?: TemporalZonedDateTime[];
105
+ type RRuleOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = ManualOptions<TOutput> | IcsOptions<TOutput>;
106
+ type RRuleResolvedOptions<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> = Omit<ManualOptions<TOutput>, 'dtstart' | 'until' | 'rDate' | 'exDate'> & {
107
+ dtstart: TOutput;
108
+ until?: TOutput;
109
+ rDate?: TOutput[];
110
+ exDate?: TOutput[];
97
111
  };
98
- declare class RRuleTemporal {
112
+ declare class RRuleTemporal<TOutput extends TemporalZonedDateTimeInput = TemporalZonedDateTime> {
99
113
  private readonly tzid;
100
114
  private readonly originalDtstart;
101
115
  private readonly opts;
116
+ private readonly outputTemporal?;
102
117
  private readonly maxIterations;
118
+ private readonly maxCandidateEvaluations;
103
119
  private readonly includeDtstart;
104
120
  private readonly parsedByDayTokens?;
105
121
  private readonly simpleByDayIsoDays?;
@@ -120,10 +136,10 @@ declare class RRuleTemporal {
120
136
  * This prevents type mismatches when mixing native and polyfill Temporal objects.
121
137
  */
122
138
  private static normalizeToPolyfill;
123
- private static toInternalIterator;
124
- private static toPublicDate;
125
- private static toPublicDates;
126
- constructor(params: RRuleOptions);
139
+ private toInternalIterator;
140
+ private toPublicDate;
141
+ private toPublicDates;
142
+ constructor(params: RRuleOptions<TOutput>);
127
143
  private buildParsedByDayTokens;
128
144
  private buildByDayIsoDays;
129
145
  private sanitizeNumericArray;
@@ -136,6 +152,29 @@ declare class RRuleTemporal {
136
152
  * present the original date is returned unchanged.
137
153
  */
138
154
  private expandByTime;
155
+ private localDateKey;
156
+ private sortedUniqueDateCandidates;
157
+ private timeOfDayNanoseconds;
158
+ private timeSlotNanoseconds;
159
+ /**
160
+ * `ZonedDateTime.with()` can reorder or alias wall-clock slots on a day with
161
+ * an offset transition (notably when a spring-forward gap is resolved). On
162
+ * those uncommon dates we retain the legacy sort semantics with a bounded
163
+ * one-day fallback instead of ever materializing a whole recurrence period.
164
+ */
165
+ private needsSortedTimeFallback;
166
+ private createCandidateWorkBudget;
167
+ private recordCandidateEvaluation;
168
+ /**
169
+ * Visit BYHOUR x BYMINUTE x BYSECOND without allocating the Cartesian
170
+ * product. Returning false from `visit` terminates the innermost traversal
171
+ * immediately. The optional bounds are only supplied for the same local
172
+ * calendar date by `visitDateTimeCandidates`.
173
+ */
174
+ private visitTimeSlots;
175
+ private visitDateTimeCandidates;
176
+ /** Apply BYSETPOS with bounded forward/reverse passes over one period. */
177
+ private visitPeriodCandidates;
139
178
  private nextCandidateSameDate;
140
179
  private applyTimeOverride;
141
180
  private computeFirst;
@@ -150,7 +189,13 @@ declare class RRuleTemporal {
150
189
  private matchesByYearDay;
151
190
  private getIsoWeekInfo;
152
191
  private matchesByWeekNo;
153
- options(): RRuleResolvedOptions;
192
+ /**
193
+ * Gregorian weekday and leap-year patterns repeat every 400 years. Checking
194
+ * a complete cycle lets impossible BYYEARDAY + BYWEEKNO intersections stop
195
+ * without incorrectly judging the rule from DTSTART's year alone.
196
+ */
197
+ private hasPossibleYearDayWeekNoCombination;
198
+ options(): RRuleResolvedOptions<TOutput>;
154
199
  private cloneOptions;
155
200
  private cloneUpdateOptions;
156
201
  /**
@@ -161,7 +206,7 @@ declare class RRuleTemporal {
161
206
  * const updated = rule.with({byMonthDay: [3]});
162
207
  * ```
163
208
  */
164
- with(updates: Partial<ManualOptions>): RRuleTemporal;
209
+ with(updates: Partial<ManualOptions<TOutput>>): RRuleTemporal<TOutput>;
165
210
  private addDtstartIfNeeded;
166
211
  private canUseUtcLinearFastPath;
167
212
  private canUseUtcWeeklyFastPath;
@@ -190,7 +235,6 @@ declare class RRuleTemporal {
190
235
  private buildMonthlyOccurrenceOnDay;
191
236
  private applyBySetPosToSortedList;
192
237
  private generateMonthlyOccurrenceDays;
193
- private generateMonthlyOccurrencesOptimizedBySetPos;
194
238
  private isGregorianLeapYear;
195
239
  private daysInGregorianMonth;
196
240
  private gregorianIsoDayOfWeek;
@@ -218,6 +262,8 @@ declare class RRuleTemporal {
218
262
  private _allTzWeeklyExpanded;
219
263
  private _allTzMonthlyByDayOrMonthDay;
220
264
  private processOccurrences;
265
+ /** Process one occurrence and report whether generation should continue. */
266
+ private processOccurrence;
221
267
  /**
222
268
  * Returns all occurrences of the rule.
223
269
  * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
@@ -238,7 +284,7 @@ declare class RRuleTemporal {
238
284
  * @param iterator - An optional callback iterator function that can be used to filter or modify the occurrences.
239
285
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
240
286
  */
241
- all(iterator?: RRuleTemporalIterator): TemporalZonedDateTime[];
287
+ all(iterator?: RRuleTemporalIterator<TOutput>): TOutput[];
242
288
  private allInternal;
243
289
  /**
244
290
  * RFC 7529: RSCALE present, simple monthly iteration with SKIP behavior.
@@ -294,7 +340,7 @@ declare class RRuleTemporal {
294
340
  * @param inc - Optional boolean flag to include the start and end dates in the results.
295
341
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
296
342
  */
297
- between(after: DateFilter, before: DateFilter, inc?: boolean): TemporalZonedDateTime[];
343
+ between(after: DateFilter, before: DateFilter, inc?: boolean): TOutput[];
298
344
  /**
299
345
  * Compute a rule-phase-aligned DTSTART at or just before the given window
300
346
  * start, jumping forward from the original DTSTART in whole multiples of
@@ -319,7 +365,7 @@ declare class RRuleTemporal {
319
365
  * @param inc - Optional boolean flag to include occurrences on the start date.
320
366
  * @returns The next occurrence of the rule after the specified date or null if no occurrences are found.
321
367
  */
322
- next(after?: DateFilter, inc?: boolean): TemporalZonedDateTime | null;
368
+ next(after?: DateFilter, inc?: boolean): TOutput | null;
323
369
  /**
324
370
  * Build a temporary rule identical to this one but starting at the
325
371
  * phase-aligned DTSTART for the given window start. The synthetic DTSTART
@@ -332,24 +378,25 @@ declare class RRuleTemporal {
332
378
  * @param inc - Optional boolean flag to include occurrences on the end date.
333
379
  * @returns The previous occurrence of the rule before the specified date or null if no occurrences are found.
334
380
  */
335
- previous(before?: DateFilter, inc?: boolean): TemporalZonedDateTime | null;
381
+ previous(before?: DateFilter, inc?: boolean): TOutput | null;
336
382
  /** A duration of `count` steps in this rule's frequency unit. */
337
383
  private freqDuration;
338
384
  toString(): string;
339
385
  private formatIcsDateTime;
340
386
  private joinDates;
341
387
  /**
342
- * Given any date in a month, return all the ZonedDateTimes in that month
343
- * matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
388
+ * Resolve the calendar dates selected within a month without expanding any
389
+ * time BY-parts. This keeps the intermediate set bounded to calendar scale.
344
390
  */
391
+ private generateMonthlyDateCandidates;
345
392
  private generateMonthlyOccurrences;
346
393
  /**
347
- * Given any date in a year, return all ZonedDateTimes in that year matching
348
- * the BYDAY/BYMONTHDAY/BYMONTH constraints. Months default to DTSTART's month
349
- * if BYMONTH is not specified.
394
+ * Resolve one recurrence year's matching calendar dates. BYHOUR,
395
+ * BYMINUTE, BYSECOND, and BYSETPOS deliberately remain outside this helper;
396
+ * callers consume the date x time product incrementally.
350
397
  */
351
- private generateYearlyOccurrences;
352
- private addByDay;
398
+ private generateYearlyDateCandidates;
399
+ private addByDayDates;
353
400
  /**
354
401
  * Helper to find the next valid value from a sorted array
355
402
  */
@@ -364,7 +411,7 @@ declare class RRuleTemporal {
364
411
  /**
365
412
  * Generate occurrences for a specific week number in a given year
366
413
  */
367
- private generateOccurrencesForWeekInYear;
414
+ private generateDateCandidatesForWeekInYear;
368
415
  private getRscaleCalendarId;
369
416
  private assertRscaleCalendarSupported;
370
417
  private pad2;
@@ -389,4 +436,4 @@ declare class RRuleTemporal {
389
436
  private _allRscaleNonGregorian;
390
437
  }
391
438
  //#endregion
392
- export { DateFilter, Freq, RRuleOptions, RRuleResolvedOptions, RRuleTemporal, RRuleTemporalIterator, TemporalPlainDate, TemporalPlainDateInput, TemporalZonedDateTime, TemporalZonedDateTimeInput, Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
439
+ export { DateFilter, Freq, RRuleOptions, RRuleResolvedOptions, RRuleTemporal, RRuleTemporalIterator, TemporalImplementation, TemporalPlainDate, TemporalPlainDateInput, TemporalZonedDateTime, TemporalZonedDateTimeInput, Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
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-b3FbAWaY.js";
1
+ import { i as weekdayToIsoDay, n as allowedFreq, r as allowedWeekdays, t as RRuleTemporal } from "./src-CGqBFmHR.js";
2
2
  export { RRuleTemporal, allowedFreq, allowedWeekdays, weekdayToIsoDay };