rrule-temporal 1.3.0 → 1.4.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
@@ -105,6 +105,7 @@ below. These correspond to the recurrence rule parts defined in RFC 5545:
105
105
  | `tzid` | Time zone identifier for interpreting dates. |
106
106
  | `maxIterations` | Safety cap when generating occurrences. |
107
107
  | `includeDtstart` | Include `DTSTART` even if it does not match the pattern. |
108
+ | `strict` | Enforce RFC 5545 constraints strictly (defaults to false). |
108
109
  | `dtstart` | First occurrence as `Temporal.ZonedDateTime`. |
109
110
 
110
111
  ## Querying occurrences
@@ -267,6 +268,8 @@ Notes
267
268
  | `new RRuleTemporal(opts)` | Create a rule from an ICS snippet or manual options. |
268
269
  | `all(iterator?)` | Return every occurrence. When the rule has no end the optional iterator is required. |
269
270
  | `between(after, before, inclusive?)` | Occurrences within a time range. |
271
+ | `matches(date)` | Convenience helper: true if the exact instant is an occurrence (accepts `Date` or `Temporal.ZonedDateTime`). |
272
+ | `occursOn(date)` | Convenience helper: true if any occurrence falls on the given `Temporal.PlainDate` in the rule's time zone (date-only, ignores time). |
270
273
  | `next(after?, inclusive?)` | Next occurrence after a given date. |
271
274
  | `previous(before?, inclusive?)` | Previous occurrence before a date. |
272
275
  | `toString()` | Convert the rule back into `DTSTART` and `RRULE` lines. |
@@ -215,6 +215,7 @@ var _RRuleTemporal = class _RRuleTemporal {
215
215
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
216
216
  count: (_c = params.count) != null ? _c : parsed.count,
217
217
  until: (_d = params.until) != null ? _d : parsed.until,
218
+ strict: params.strict,
218
219
  maxIterations: params.maxIterations,
219
220
  includeDtstart: params.includeDtstart,
220
221
  tzid: this.tzid
@@ -264,6 +265,33 @@ var _RRuleTemporal = class _RRuleTemporal {
264
265
  }
265
266
  return days.length > 0 ? days : void 0;
266
267
  }
268
+ enforceStrictRfc(opts) {
269
+ var _a;
270
+ if (!opts.strict) return;
271
+ const freq = opts.freq;
272
+ if (opts.byWeekNo && freq !== "YEARLY") {
273
+ throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
274
+ }
275
+ if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
276
+ throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
277
+ }
278
+ if (opts.byMonthDay && freq === "WEEKLY") {
279
+ throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
280
+ }
281
+ const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
282
+ if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
283
+ throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
284
+ }
285
+ if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
286
+ throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
287
+ }
288
+ const hasOtherBy = Boolean(
289
+ opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
290
+ );
291
+ if (opts.bySetPos && !hasOtherBy) {
292
+ throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
293
+ }
294
+ }
267
295
  sanitizeOpts(opts) {
268
296
  var _a;
269
297
  opts.byDay = this.sanitizeByDay(opts.byDay);
@@ -289,6 +317,7 @@ var _RRuleTemporal = class _RRuleTemporal {
289
317
  }
290
318
  opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
291
319
  }
320
+ this.enforceStrictRfc(opts);
292
321
  return opts;
293
322
  }
294
323
  rawAdvance(zdt) {
@@ -1518,6 +1547,25 @@ var _RRuleTemporal = class _RRuleTemporal {
1518
1547
  return afterStart && beforeEnd;
1519
1548
  });
1520
1549
  }
1550
+ /**
1551
+ * Convenience helper: true if the exact instant is an occurrence of the rule.
1552
+ * This checks full date-time equality (including time and time zone).
1553
+ */
1554
+ matches(date) {
1555
+ return this.between(date, date, true).length > 0;
1556
+ }
1557
+ /**
1558
+ * Convenience helper: true if any occurrence falls on the given calendar day
1559
+ * in the rule's time zone. This ignores time-of-day granularity.
1560
+ */
1561
+ occursOn(date) {
1562
+ const startOfDay = date.toZonedDateTime({
1563
+ timeZone: this.tzid,
1564
+ plainTime: Temporal.PlainTime.from("00:00")
1565
+ });
1566
+ const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
1567
+ return this.between(startOfDay, endOfDay, true).length > 0;
1568
+ }
1521
1569
  /**
1522
1570
  * Returns the next occurrence of the rule after a specified date.
1523
1571
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.cjs CHANGED
@@ -236,6 +236,7 @@ var _RRuleTemporal = class _RRuleTemporal {
236
236
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
237
237
  count: (_c = params.count) != null ? _c : parsed.count,
238
238
  until: (_d = params.until) != null ? _d : parsed.until,
239
+ strict: params.strict,
239
240
  maxIterations: params.maxIterations,
240
241
  includeDtstart: params.includeDtstart,
241
242
  tzid: this.tzid
@@ -285,6 +286,33 @@ var _RRuleTemporal = class _RRuleTemporal {
285
286
  }
286
287
  return days.length > 0 ? days : void 0;
287
288
  }
289
+ enforceStrictRfc(opts) {
290
+ var _a;
291
+ if (!opts.strict) return;
292
+ const freq = opts.freq;
293
+ if (opts.byWeekNo && freq !== "YEARLY") {
294
+ throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
295
+ }
296
+ if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
297
+ throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
298
+ }
299
+ if (opts.byMonthDay && freq === "WEEKLY") {
300
+ throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
301
+ }
302
+ const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
303
+ if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
304
+ throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
305
+ }
306
+ if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
307
+ throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
308
+ }
309
+ const hasOtherBy = Boolean(
310
+ opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
311
+ );
312
+ if (opts.bySetPos && !hasOtherBy) {
313
+ throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
314
+ }
315
+ }
288
316
  sanitizeOpts(opts) {
289
317
  var _a;
290
318
  opts.byDay = this.sanitizeByDay(opts.byDay);
@@ -310,6 +338,7 @@ var _RRuleTemporal = class _RRuleTemporal {
310
338
  }
311
339
  opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
312
340
  }
341
+ this.enforceStrictRfc(opts);
313
342
  return opts;
314
343
  }
315
344
  rawAdvance(zdt) {
@@ -1539,6 +1568,25 @@ var _RRuleTemporal = class _RRuleTemporal {
1539
1568
  return afterStart && beforeEnd;
1540
1569
  });
1541
1570
  }
1571
+ /**
1572
+ * Convenience helper: true if the exact instant is an occurrence of the rule.
1573
+ * This checks full date-time equality (including time and time zone).
1574
+ */
1575
+ matches(date) {
1576
+ return this.between(date, date, true).length > 0;
1577
+ }
1578
+ /**
1579
+ * Convenience helper: true if any occurrence falls on the given calendar day
1580
+ * in the rule's time zone. This ignores time-of-day granularity.
1581
+ */
1582
+ occursOn(date) {
1583
+ const startOfDay = date.toZonedDateTime({
1584
+ timeZone: this.tzid,
1585
+ plainTime: import_polyfill.Temporal.PlainTime.from("00:00")
1586
+ });
1587
+ const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
1588
+ return this.between(startOfDay, endOfDay, true).length > 0;
1589
+ }
1542
1590
  /**
1543
1591
  * Returns the next occurrence of the rule after a specified date.
1544
1592
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.d.cts CHANGED
@@ -11,6 +11,8 @@ interface BaseOpts {
11
11
  maxIterations?: number;
12
12
  /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
13
13
  includeDtstart?: boolean;
14
+ /** Enforce RFC 5545 constraints strictly (defaults to false). */
15
+ strict?: boolean;
14
16
  /** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
15
17
  rscale?: string;
16
18
  /** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
@@ -77,6 +79,7 @@ declare class RRuleTemporal {
77
79
  constructor(params: RRuleOptions);
78
80
  private sanitizeNumericArray;
79
81
  private sanitizeByDay;
82
+ private enforceStrictRfc;
80
83
  private sanitizeOpts;
81
84
  private rawAdvance;
82
85
  /** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
@@ -178,6 +181,16 @@ declare class RRuleTemporal {
178
181
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
179
182
  */
180
183
  between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
184
+ /**
185
+ * Convenience helper: true if the exact instant is an occurrence of the rule.
186
+ * This checks full date-time equality (including time and time zone).
187
+ */
188
+ matches(date: DateFilter): boolean;
189
+ /**
190
+ * Convenience helper: true if any occurrence falls on the given calendar day
191
+ * in the rule's time zone. This ignores time-of-day granularity.
192
+ */
193
+ occursOn(date: Temporal.PlainDate): boolean;
181
194
  /**
182
195
  * Returns the next occurrence of the rule after a specified date.
183
196
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ interface BaseOpts {
11
11
  maxIterations?: number;
12
12
  /** Include DTSTART as an occurrence even if it does not match the rule pattern. */
13
13
  includeDtstart?: boolean;
14
+ /** Enforce RFC 5545 constraints strictly (defaults to false). */
15
+ strict?: boolean;
14
16
  /** RSCALE per RFC 7529: calendar system for recurrence generation (e.g., GREGORIAN). */
15
17
  rscale?: string;
16
18
  /** SKIP behavior per RFC 7529: OMIT (default), BACKWARD, FORWARD (requires RSCALE). */
@@ -77,6 +79,7 @@ declare class RRuleTemporal {
77
79
  constructor(params: RRuleOptions);
78
80
  private sanitizeNumericArray;
79
81
  private sanitizeByDay;
82
+ private enforceStrictRfc;
80
83
  private sanitizeOpts;
81
84
  private rawAdvance;
82
85
  /** Expand one base ZonedDateTime into all BYHOUR × BYMINUTE × BYSECOND
@@ -178,6 +181,16 @@ declare class RRuleTemporal {
178
181
  * @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule within the specified time window.
179
182
  */
180
183
  between(after: DateFilter, before: DateFilter, inc?: boolean): Temporal.ZonedDateTime[];
184
+ /**
185
+ * Convenience helper: true if the exact instant is an occurrence of the rule.
186
+ * This checks full date-time equality (including time and time zone).
187
+ */
188
+ matches(date: DateFilter): boolean;
189
+ /**
190
+ * Convenience helper: true if any occurrence falls on the given calendar day
191
+ * in the rule's time zone. This ignores time-of-day granularity.
192
+ */
193
+ occursOn(date: Temporal.PlainDate): boolean;
181
194
  /**
182
195
  * Returns the next occurrence of the rule after a specified date.
183
196
  * @param after - The start date or Temporal.ZonedDateTime object.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-R242V3P5.js";
3
+ } from "./chunk-76UOKZYT.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -238,6 +238,7 @@ var _RRuleTemporal = class _RRuleTemporal {
238
238
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
239
239
  count: (_c = params.count) != null ? _c : parsed.count,
240
240
  until: (_d = params.until) != null ? _d : parsed.until,
241
+ strict: params.strict,
241
242
  maxIterations: params.maxIterations,
242
243
  includeDtstart: params.includeDtstart,
243
244
  tzid: this.tzid
@@ -287,6 +288,33 @@ var _RRuleTemporal = class _RRuleTemporal {
287
288
  }
288
289
  return days.length > 0 ? days : void 0;
289
290
  }
291
+ enforceStrictRfc(opts) {
292
+ var _a;
293
+ if (!opts.strict) return;
294
+ const freq = opts.freq;
295
+ if (opts.byWeekNo && freq !== "YEARLY") {
296
+ throw new Error("BYWEEKNO MUST NOT be used unless FREQ=YEARLY");
297
+ }
298
+ if (opts.byYearDay && ["DAILY", "WEEKLY", "MONTHLY"].includes(freq)) {
299
+ throw new Error("BYYEARDAY MUST NOT be used when FREQ is DAILY, WEEKLY, or MONTHLY");
300
+ }
301
+ if (opts.byMonthDay && freq === "WEEKLY") {
302
+ throw new Error("BYMONTHDAY MUST NOT be used when FREQ is WEEKLY");
303
+ }
304
+ const hasNumericByDay = ((_a = opts.byDay) != null ? _a : []).some((day) => /^[+-]?\d/.test(day));
305
+ if (hasNumericByDay && !["MONTHLY", "YEARLY"].includes(freq)) {
306
+ throw new Error("BYDAY with numeric value MUST NOT be used unless FREQ is MONTHLY or YEARLY");
307
+ }
308
+ if (hasNumericByDay && freq === "YEARLY" && opts.byWeekNo) {
309
+ throw new Error("BYDAY with numeric value MUST NOT be used with FREQ=YEARLY when BYWEEKNO is present");
310
+ }
311
+ const hasOtherBy = Boolean(
312
+ opts.byDay || opts.byMonth || opts.byMonthDay || opts.byYearDay || opts.byWeekNo || opts.byHour || opts.byMinute || opts.bySecond
313
+ );
314
+ if (opts.bySetPos && !hasOtherBy) {
315
+ throw new Error("BYSETPOS MUST be used with another BYxxx rule part");
316
+ }
317
+ }
290
318
  sanitizeOpts(opts) {
291
319
  var _a;
292
320
  opts.byDay = this.sanitizeByDay(opts.byDay);
@@ -312,6 +340,7 @@ var _RRuleTemporal = class _RRuleTemporal {
312
340
  }
313
341
  opts.bySetPos = this.sanitizeNumericArray(opts.bySetPos, -Infinity, Infinity, false, false);
314
342
  }
343
+ this.enforceStrictRfc(opts);
315
344
  return opts;
316
345
  }
317
346
  rawAdvance(zdt) {
@@ -1541,6 +1570,25 @@ var _RRuleTemporal = class _RRuleTemporal {
1541
1570
  return afterStart && beforeEnd;
1542
1571
  });
1543
1572
  }
1573
+ /**
1574
+ * Convenience helper: true if the exact instant is an occurrence of the rule.
1575
+ * This checks full date-time equality (including time and time zone).
1576
+ */
1577
+ matches(date) {
1578
+ return this.between(date, date, true).length > 0;
1579
+ }
1580
+ /**
1581
+ * Convenience helper: true if any occurrence falls on the given calendar day
1582
+ * in the rule's time zone. This ignores time-of-day granularity.
1583
+ */
1584
+ occursOn(date) {
1585
+ const startOfDay = date.toZonedDateTime({
1586
+ timeZone: this.tzid,
1587
+ plainTime: import_polyfill.Temporal.PlainTime.from("00:00")
1588
+ });
1589
+ const endOfDay = startOfDay.add({ days: 1 }).subtract({ nanoseconds: 1 });
1590
+ return this.between(startOfDay, endOfDay, true).length > 0;
1591
+ }
1544
1592
  /**
1545
1593
  * Returns the next occurrence of the rule after a specified date.
1546
1594
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -2966,6 +3014,10 @@ function formatTime(hour, minute = 0, second = 0) {
2966
3014
  }
2967
3015
  return `${hr12} ${ampm}`;
2968
3016
  }
3017
+ function weekdayTokenFromZdt(zdt) {
3018
+ const tokens = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
3019
+ return tokens[zdt.dayOfWeek - 1];
3020
+ }
2969
3021
  function tzAbbreviation(zdt) {
2970
3022
  const parts = new Intl.DateTimeFormat("en-US", {
2971
3023
  timeZone: zdt.timeZoneId,
@@ -2998,6 +3050,14 @@ function toText(input, locale) {
2998
3050
  rDate,
2999
3051
  exDate
3000
3052
  } = opts;
3053
+ const dayOrLarger = freq === "YEARLY" || freq === "MONTHLY" || freq === "WEEKLY" || freq === "DAILY";
3054
+ const hasExplicitTime = Boolean(byHour || byMinute || bySecond);
3055
+ const dtstartHasTime = opts.dtstart.hour !== 0 || opts.dtstart.minute !== 0 || opts.dtstart.second !== 0;
3056
+ const shouldDefaultTime = dayOrLarger && (hasExplicitTime || dtstartHasTime);
3057
+ const textByDay = byDay != null ? byDay : freq === "WEEKLY" ? [weekdayTokenFromZdt(opts.dtstart)] : void 0;
3058
+ const textByHour = byHour != null ? byHour : shouldDefaultTime ? [opts.dtstart.hour] : void 0;
3059
+ const textByMinute = textByHour ? byMinute != null ? byMinute : [opts.dtstart.minute] : byMinute;
3060
+ const textBySecond = textByHour ? bySecond != null ? bySecond : [opts.dtstart.second] : bySecond;
3001
3061
  const parts = [data.words.every];
3002
3062
  const baseKey = {
3003
3063
  YEARLY: "year",
@@ -3009,7 +3069,7 @@ function toText(input, locale) {
3009
3069
  SECONDLY: "second"
3010
3070
  }[freq];
3011
3071
  const base = data.units[baseKey];
3012
- const daysNormalized = byDay == null ? void 0 : byDay.map((d) => d.toUpperCase());
3072
+ const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
3013
3073
  const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
3014
3074
  const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
3015
3075
  if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
@@ -3023,15 +3083,15 @@ function toText(input, locale) {
3023
3083
  parts.push(base.singular);
3024
3084
  }
3025
3085
  }
3026
- if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
3086
+ if (freq === "WEEKLY" && textByDay && !isWeekdays && !isEveryday) {
3027
3087
  parts.push(
3028
3088
  data.words.on,
3029
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
3089
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
3030
3090
  );
3031
- } else if (byDay && freq !== "WEEKLY") {
3091
+ } else if (textByDay && freq !== "WEEKLY") {
3032
3092
  parts.push(
3033
3093
  data.words.on,
3034
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
3094
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
3035
3095
  );
3036
3096
  }
3037
3097
  if (byMonth) {
@@ -3060,18 +3120,18 @@ function toText(input, locale) {
3060
3120
  list(byWeekNo, (n) => n.toString(), data.words.and)
3061
3121
  );
3062
3122
  }
3063
- if (byHour) {
3064
- const minutes = byMinute != null ? byMinute : [0];
3065
- const seconds = bySecond != null ? bySecond : [0];
3066
- const times = byHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
3123
+ if (textByHour) {
3124
+ const minutes = textByMinute != null ? textByMinute : [0];
3125
+ const seconds = textBySecond != null ? textBySecond : [0];
3126
+ const times = textByHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
3067
3127
  parts.push(data.words.at, list(times, void 0, data.words.and));
3068
3128
  parts.push(tzAbbreviation(opts.dtstart));
3069
3129
  }
3070
- if (!byHour && byMinute) {
3071
- parts.push(data.words.at_minute, list(byMinute, void 0, data.words.and));
3130
+ if (!textByHour && textByMinute) {
3131
+ parts.push(data.words.at_minute, list(textByMinute, void 0, data.words.and));
3072
3132
  }
3073
- if (!byHour && !byMinute && bySecond) {
3074
- parts.push(data.words.at_second, list(bySecond, void 0, data.words.and));
3133
+ if (!textByHour && !textByMinute && textBySecond) {
3134
+ parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
3075
3135
  }
3076
3136
  if (until) {
3077
3137
  const monthName = data.monthNames[until.month - 1];
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-R242V3P5.js";
3
+ } from "./chunk-76UOKZYT.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
@@ -566,6 +566,10 @@ function formatTime(hour, minute = 0, second = 0) {
566
566
  }
567
567
  return `${hr12} ${ampm}`;
568
568
  }
569
+ function weekdayTokenFromZdt(zdt) {
570
+ const tokens = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
571
+ return tokens[zdt.dayOfWeek - 1];
572
+ }
569
573
  function tzAbbreviation(zdt) {
570
574
  const parts = new Intl.DateTimeFormat("en-US", {
571
575
  timeZone: zdt.timeZoneId,
@@ -598,6 +602,14 @@ function toText(input, locale) {
598
602
  rDate,
599
603
  exDate
600
604
  } = opts;
605
+ const dayOrLarger = freq === "YEARLY" || freq === "MONTHLY" || freq === "WEEKLY" || freq === "DAILY";
606
+ const hasExplicitTime = Boolean(byHour || byMinute || bySecond);
607
+ const dtstartHasTime = opts.dtstart.hour !== 0 || opts.dtstart.minute !== 0 || opts.dtstart.second !== 0;
608
+ const shouldDefaultTime = dayOrLarger && (hasExplicitTime || dtstartHasTime);
609
+ const textByDay = byDay != null ? byDay : freq === "WEEKLY" ? [weekdayTokenFromZdt(opts.dtstart)] : void 0;
610
+ const textByHour = byHour != null ? byHour : shouldDefaultTime ? [opts.dtstart.hour] : void 0;
611
+ const textByMinute = textByHour ? byMinute != null ? byMinute : [opts.dtstart.minute] : byMinute;
612
+ const textBySecond = textByHour ? bySecond != null ? bySecond : [opts.dtstart.second] : bySecond;
601
613
  const parts = [data.words.every];
602
614
  const baseKey = {
603
615
  YEARLY: "year",
@@ -609,7 +621,7 @@ function toText(input, locale) {
609
621
  SECONDLY: "second"
610
622
  }[freq];
611
623
  const base = data.units[baseKey];
612
- const daysNormalized = byDay == null ? void 0 : byDay.map((d) => d.toUpperCase());
624
+ const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
613
625
  const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
614
626
  const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
615
627
  if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
@@ -623,15 +635,15 @@ function toText(input, locale) {
623
635
  parts.push(base.singular);
624
636
  }
625
637
  }
626
- if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
638
+ if (freq === "WEEKLY" && textByDay && !isWeekdays && !isEveryday) {
627
639
  parts.push(
628
640
  data.words.on,
629
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
641
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
630
642
  );
631
- } else if (byDay && freq !== "WEEKLY") {
643
+ } else if (textByDay && freq !== "WEEKLY") {
632
644
  parts.push(
633
645
  data.words.on,
634
- list(byDay, (t) => formatByDayToken(t, data), data.words.and)
646
+ list(textByDay, (t) => formatByDayToken(t, data), data.words.and)
635
647
  );
636
648
  }
637
649
  if (byMonth) {
@@ -660,18 +672,18 @@ function toText(input, locale) {
660
672
  list(byWeekNo, (n) => n.toString(), data.words.and)
661
673
  );
662
674
  }
663
- if (byHour) {
664
- const minutes = byMinute != null ? byMinute : [0];
665
- const seconds = bySecond != null ? bySecond : [0];
666
- const times = byHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
675
+ if (textByHour) {
676
+ const minutes = textByMinute != null ? textByMinute : [0];
677
+ const seconds = textBySecond != null ? textBySecond : [0];
678
+ const times = textByHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
667
679
  parts.push(data.words.at, list(times, void 0, data.words.and));
668
680
  parts.push(tzAbbreviation(opts.dtstart));
669
681
  }
670
- if (!byHour && byMinute) {
671
- parts.push(data.words.at_minute, list(byMinute, void 0, data.words.and));
682
+ if (!textByHour && textByMinute) {
683
+ parts.push(data.words.at_minute, list(textByMinute, void 0, data.words.and));
672
684
  }
673
- if (!byHour && !byMinute && bySecond) {
674
- parts.push(data.words.at_second, list(bySecond, void 0, data.words.and));
685
+ if (!textByHour && !textByMinute && textBySecond) {
686
+ parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
675
687
  }
676
688
  if (until) {
677
689
  const monthName = data.monthNames[until.month - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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",