rrule-temporal 1.4.4 → 1.4.6

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
@@ -61,6 +61,9 @@ Note on `UNTIL` (RFC 5545): if `DTSTART` is a DATE-TIME with a `TZID` or UTC (`Z
61
61
  `UNTIL` must be a DATE-TIME in UTC (trailing `Z`). If `DTSTART` is `VALUE=DATE`,
62
62
  `UNTIL` must be a DATE (no time). Floating DATE-TIME rules (no `TZID`, no `Z`)
63
63
  allow a floating `UNTIL`.
64
+ In default mode (`strict: false`), `UNTIL=YYYYMMDD` with a DATE-TIME `DTSTART`
65
+ is accepted for compatibility and treated as inclusive end-of-day in `DTSTART`'s
66
+ zone (converted to UTC when required). Set `strict: true` to reject it.
64
67
 
65
68
  ## Creating a rule with options
66
69
 
@@ -133,6 +136,7 @@ const prev = rule.previous(new Date("2025-05-01T00:00Z"));
133
136
  ## Converting to human-readable text
134
137
 
135
138
  The `toText` helper converts a rule into a human readable description.
139
+ `UNTIL` (and optional `DTSTART`) dates are locale-aware via `toLocaleString`.
136
140
 
137
141
  ```typescript
138
142
  import { Temporal } from "@js-temporal/polyfill";
@@ -147,6 +151,7 @@ rule.toString();
147
151
  // "DTSTART;TZID=UTC:20250101T090000\nRRULE:FREQ=DAILY;COUNT=3"
148
152
  toText(rule); // uses the runtime locale, defaults to English
149
153
  toText(rule, "es"); // Spanish description
154
+ toText(rule, "en", { includeDtstart: true }); // include "starting from <DTSTART date>"
150
155
  toText(rule);
151
156
  // "every day for 3 times"
152
157
 
@@ -280,7 +285,7 @@ Notes
280
285
  | `next(after?, inclusive?)` | Next occurrence after a given date. |
281
286
  | `previous(before?, inclusive?)` | Previous occurrence before a date. |
282
287
  | `toString()` | Convert the rule back into `DTSTART` and `RRULE` lines. |
283
- | `toText(rule, locale?)` | Human readable description (`en`, `es`, `hi`, `yue`, `ar`, `he`, `zh`, `fr`). |
288
+ | `toText(rule, locale?, options?)` | Human readable description (`en`, `es`, `hi`, `yue`, `ar`, `he`, `zh`, `fr`). Options: `{ includeDtstart?: boolean }`. |
284
289
  | `options()` | Return the normalized options object. |
285
290
 
286
291
  ## Further examples
@@ -81,7 +81,7 @@ function parseByMonthArray(val) {
81
81
  return Number.isFinite(n) ? n : t;
82
82
  });
83
83
  }
84
- function parseRRuleString(input, targetTimezone, dtstart) {
84
+ function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
85
85
  var _a, _b, _c, _d, _e;
86
86
  const unfoldedInput = unfoldLine(input).trim();
87
87
  let parsedDtstart;
@@ -173,7 +173,20 @@ function parseRRuleString(input, targetTimezone, dtstart) {
173
173
  break;
174
174
  }
175
175
  if (!untilHasTime) {
176
- throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
176
+ if (strict) {
177
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
178
+ }
179
+ const localEndOfDay = parseIcsDateTime(val, tzid || "UTC", "DATE").with({
180
+ hour: 23,
181
+ minute: 59,
182
+ second: 59,
183
+ millisecond: 0,
184
+ microsecond: 0,
185
+ nanosecond: 0
186
+ });
187
+ const requiresUtc2 = dtstartHasTzid || dtstartIsUtc;
188
+ opts.until = requiresUtc2 ? localEndOfDay.withTimeZone("UTC") : localEndOfDay;
189
+ break;
177
190
  }
178
191
  const requiresUtc = dtstartHasTzid || dtstartIsUtc;
179
192
  if (requiresUtc && !val.endsWith("Z")) {
@@ -231,19 +244,19 @@ var _RRuleTemporal = class _RRuleTemporal {
231
244
  return Temporal.ZonedDateTime.from(zdt.toString());
232
245
  }
233
246
  constructor(params) {
234
- var _a, _b, _c, _d, _e, _f, _g;
247
+ var _a, _b, _c, _d, _e, _f, _g, _h;
235
248
  let manual;
236
249
  if (isIcsOpts(params)) {
237
- const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart);
250
+ const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
238
251
  if (!parsed.dtstart) {
239
252
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
240
253
  }
241
- this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
254
+ this.tzid = (_c = (_b = parsed.tzid) != null ? _b : params.tzid) != null ? _c : "UTC";
242
255
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
243
256
  manual = __spreadProps(__spreadValues({}, parsed), {
244
257
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
245
- count: (_c = params.count) != null ? _c : parsed.count,
246
- until: (_d = params.until) != null ? _d : parsed.until,
258
+ count: (_d = params.count) != null ? _d : parsed.count,
259
+ until: (_e = params.until) != null ? _e : parsed.until,
247
260
  strict: params.strict,
248
261
  maxIterations: params.maxIterations,
249
262
  includeDtstart: params.includeDtstart,
@@ -259,7 +272,7 @@ var _RRuleTemporal = class _RRuleTemporal {
259
272
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
260
273
  }
261
274
  if (!manual.freq) throw new Error("RRULE must include FREQ");
262
- manual.interval = (_e = manual.interval) != null ? _e : 1;
275
+ manual.interval = (_f = manual.interval) != null ? _f : 1;
263
276
  if (manual.interval <= 0) {
264
277
  throw new Error("Cannot create RRule: interval must be greater than 0");
265
278
  }
@@ -270,8 +283,8 @@ var _RRuleTemporal = class _RRuleTemporal {
270
283
  manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
271
284
  }
272
285
  this.opts = this.sanitizeOpts(manual);
273
- this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
274
- this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
286
+ this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
287
+ this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
275
288
  }
276
289
  sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
277
290
  if (!arr) return void 0;
@@ -1494,6 +1507,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1494
1507
  const safetyMargin = Math.min(targetRuleCount, 10);
1495
1508
  return matchCount >= targetRuleCount + safetyMargin;
1496
1509
  }
1510
+ hasTimeOfDayBetween(startTime, endTime) {
1511
+ var _a, _b, _c;
1512
+ if (Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1513
+ const base = this.originalDtstart;
1514
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1515
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1516
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1517
+ for (const hour of hours) {
1518
+ for (const minute of minutes) {
1519
+ for (const second of seconds) {
1520
+ const candidate = Temporal.PlainTime.from({
1521
+ hour,
1522
+ minute,
1523
+ second,
1524
+ millisecond: base.millisecond,
1525
+ microsecond: base.microsecond,
1526
+ nanosecond: base.nanosecond
1527
+ });
1528
+ if (Temporal.PlainTime.compare(candidate, startTime) >= 0 && Temporal.PlainTime.compare(candidate, endTime) < 0) {
1529
+ return true;
1530
+ }
1531
+ }
1532
+ }
1533
+ }
1534
+ return false;
1535
+ }
1497
1536
  /**
1498
1537
  * Returns all occurrences of the rule within a specified time window.
1499
1538
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1538,37 +1577,42 @@ var _RRuleTemporal = class _RRuleTemporal {
1538
1577
  unit = "seconds";
1539
1578
  }
1540
1579
  const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1580
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1541
1581
  const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1542
1582
  aligned.withPlainTime(this.originalDtstart.toPlainTime())
1543
1583
  ).withTimeZone(dtstartNormalized.timeZoneId);
1544
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1584
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1585
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1545
1586
  const unitsBetween = diffDur[unit];
1546
- const steps = Math.floor(unitsBetween / interval);
1547
- let toAdd;
1548
- const jump = steps * interval;
1549
- switch (unit) {
1550
- case "years":
1551
- toAdd = { years: jump };
1552
- break;
1553
- case "months":
1554
- toAdd = { months: jump };
1555
- break;
1556
- case "weeks":
1557
- toAdd = { weeks: jump };
1558
- break;
1559
- case "days":
1560
- toAdd = { days: jump };
1561
- break;
1562
- case "hours":
1563
- toAdd = { hours: jump };
1564
- break;
1565
- case "minutes":
1566
- toAdd = { minutes: jump };
1567
- break;
1568
- default:
1569
- toAdd = { seconds: jump };
1587
+ let steps = Math.floor(unitsBetween / interval);
1588
+ const durationForJump = (jump) => {
1589
+ switch (unit) {
1590
+ case "years":
1591
+ return { years: jump };
1592
+ case "months":
1593
+ return { months: jump };
1594
+ case "weeks":
1595
+ return { weeks: jump };
1596
+ case "days":
1597
+ return { days: jump };
1598
+ case "hours":
1599
+ return { hours: jump };
1600
+ case "minutes":
1601
+ return { minutes: jump };
1602
+ default:
1603
+ return { seconds: jump };
1604
+ }
1605
+ };
1606
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1607
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1608
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1609
+ if (sameDate && Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1610
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1611
+ steps -= 1;
1612
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1613
+ }
1614
+ }
1570
1615
  }
1571
- let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(toAdd));
1572
1616
  const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1573
1617
  if (Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1574
1618
  candidate = dtstartForCompare;
package/dist/index.cjs CHANGED
@@ -102,7 +102,7 @@ function parseByMonthArray(val) {
102
102
  return Number.isFinite(n) ? n : t;
103
103
  });
104
104
  }
105
- function parseRRuleString(input, targetTimezone, dtstart) {
105
+ function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
106
106
  var _a, _b, _c, _d, _e;
107
107
  const unfoldedInput = unfoldLine(input).trim();
108
108
  let parsedDtstart;
@@ -194,7 +194,20 @@ function parseRRuleString(input, targetTimezone, dtstart) {
194
194
  break;
195
195
  }
196
196
  if (!untilHasTime) {
197
- throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
197
+ if (strict) {
198
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
199
+ }
200
+ const localEndOfDay = parseIcsDateTime(val, tzid || "UTC", "DATE").with({
201
+ hour: 23,
202
+ minute: 59,
203
+ second: 59,
204
+ millisecond: 0,
205
+ microsecond: 0,
206
+ nanosecond: 0
207
+ });
208
+ const requiresUtc2 = dtstartHasTzid || dtstartIsUtc;
209
+ opts.until = requiresUtc2 ? localEndOfDay.withTimeZone("UTC") : localEndOfDay;
210
+ break;
198
211
  }
199
212
  const requiresUtc = dtstartHasTzid || dtstartIsUtc;
200
213
  if (requiresUtc && !val.endsWith("Z")) {
@@ -252,19 +265,19 @@ var _RRuleTemporal = class _RRuleTemporal {
252
265
  return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
253
266
  }
254
267
  constructor(params) {
255
- var _a, _b, _c, _d, _e, _f, _g;
268
+ var _a, _b, _c, _d, _e, _f, _g, _h;
256
269
  let manual;
257
270
  if (isIcsOpts(params)) {
258
- const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart);
271
+ const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
259
272
  if (!parsed.dtstart) {
260
273
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
261
274
  }
262
- this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
275
+ this.tzid = (_c = (_b = parsed.tzid) != null ? _b : params.tzid) != null ? _c : "UTC";
263
276
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
264
277
  manual = __spreadProps(__spreadValues({}, parsed), {
265
278
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
266
- count: (_c = params.count) != null ? _c : parsed.count,
267
- until: (_d = params.until) != null ? _d : parsed.until,
279
+ count: (_d = params.count) != null ? _d : parsed.count,
280
+ until: (_e = params.until) != null ? _e : parsed.until,
268
281
  strict: params.strict,
269
282
  maxIterations: params.maxIterations,
270
283
  includeDtstart: params.includeDtstart,
@@ -280,7 +293,7 @@ var _RRuleTemporal = class _RRuleTemporal {
280
293
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
281
294
  }
282
295
  if (!manual.freq) throw new Error("RRULE must include FREQ");
283
- manual.interval = (_e = manual.interval) != null ? _e : 1;
296
+ manual.interval = (_f = manual.interval) != null ? _f : 1;
284
297
  if (manual.interval <= 0) {
285
298
  throw new Error("Cannot create RRule: interval must be greater than 0");
286
299
  }
@@ -291,8 +304,8 @@ var _RRuleTemporal = class _RRuleTemporal {
291
304
  manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
292
305
  }
293
306
  this.opts = this.sanitizeOpts(manual);
294
- this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
295
- this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
307
+ this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
308
+ this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
296
309
  }
297
310
  sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
298
311
  if (!arr) return void 0;
@@ -1515,6 +1528,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1515
1528
  const safetyMargin = Math.min(targetRuleCount, 10);
1516
1529
  return matchCount >= targetRuleCount + safetyMargin;
1517
1530
  }
1531
+ hasTimeOfDayBetween(startTime, endTime) {
1532
+ var _a, _b, _c;
1533
+ if (import_polyfill.Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1534
+ const base = this.originalDtstart;
1535
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1536
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1537
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1538
+ for (const hour of hours) {
1539
+ for (const minute of minutes) {
1540
+ for (const second of seconds) {
1541
+ const candidate = import_polyfill.Temporal.PlainTime.from({
1542
+ hour,
1543
+ minute,
1544
+ second,
1545
+ millisecond: base.millisecond,
1546
+ microsecond: base.microsecond,
1547
+ nanosecond: base.nanosecond
1548
+ });
1549
+ if (import_polyfill.Temporal.PlainTime.compare(candidate, startTime) >= 0 && import_polyfill.Temporal.PlainTime.compare(candidate, endTime) < 0) {
1550
+ return true;
1551
+ }
1552
+ }
1553
+ }
1554
+ }
1555
+ return false;
1556
+ }
1518
1557
  /**
1519
1558
  * Returns all occurrences of the rule within a specified time window.
1520
1559
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1559,37 +1598,42 @@ var _RRuleTemporal = class _RRuleTemporal {
1559
1598
  unit = "seconds";
1560
1599
  }
1561
1600
  const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1601
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1562
1602
  const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1563
1603
  aligned.withPlainTime(this.originalDtstart.toPlainTime())
1564
1604
  ).withTimeZone(dtstartNormalized.timeZoneId);
1565
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1605
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1606
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1566
1607
  const unitsBetween = diffDur[unit];
1567
- const steps = Math.floor(unitsBetween / interval);
1568
- let toAdd;
1569
- const jump = steps * interval;
1570
- switch (unit) {
1571
- case "years":
1572
- toAdd = { years: jump };
1573
- break;
1574
- case "months":
1575
- toAdd = { months: jump };
1576
- break;
1577
- case "weeks":
1578
- toAdd = { weeks: jump };
1579
- break;
1580
- case "days":
1581
- toAdd = { days: jump };
1582
- break;
1583
- case "hours":
1584
- toAdd = { hours: jump };
1585
- break;
1586
- case "minutes":
1587
- toAdd = { minutes: jump };
1588
- break;
1589
- default:
1590
- toAdd = { seconds: jump };
1608
+ let steps = Math.floor(unitsBetween / interval);
1609
+ const durationForJump = (jump) => {
1610
+ switch (unit) {
1611
+ case "years":
1612
+ return { years: jump };
1613
+ case "months":
1614
+ return { months: jump };
1615
+ case "weeks":
1616
+ return { weeks: jump };
1617
+ case "days":
1618
+ return { days: jump };
1619
+ case "hours":
1620
+ return { hours: jump };
1621
+ case "minutes":
1622
+ return { minutes: jump };
1623
+ default:
1624
+ return { seconds: jump };
1625
+ }
1626
+ };
1627
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1628
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1629
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1630
+ if (sameDate && import_polyfill.Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1631
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1632
+ steps -= 1;
1633
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1634
+ }
1635
+ }
1591
1636
  }
1592
- let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(toAdd));
1593
1637
  const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1594
1638
  if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1595
1639
  candidate = dtstartForCompare;
package/dist/index.d.cts CHANGED
@@ -178,6 +178,7 @@ declare class RRuleTemporal {
178
178
  * @returns true if the loop should break
179
179
  */
180
180
  private shouldBreakForCountLimit;
181
+ private hasTimeOfDayBetween;
181
182
  /**
182
183
  * Returns all occurrences of the rule within a specified time window.
183
184
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -262,4 +263,4 @@ declare class RRuleTemporal {
262
263
  private _allRscaleNonGregorian;
263
264
  }
264
265
 
265
- export { type RRuleOptions, RRuleTemporal };
266
+ export { type Freq, type RRuleOptions, RRuleTemporal };
package/dist/index.d.ts CHANGED
@@ -178,6 +178,7 @@ declare class RRuleTemporal {
178
178
  * @returns true if the loop should break
179
179
  */
180
180
  private shouldBreakForCountLimit;
181
+ private hasTimeOfDayBetween;
181
182
  /**
182
183
  * Returns all occurrences of the rule within a specified time window.
183
184
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -262,4 +263,4 @@ declare class RRuleTemporal {
262
263
  private _allRscaleNonGregorian;
263
264
  }
264
265
 
265
- export { type RRuleOptions, RRuleTemporal };
266
+ export { type Freq, type RRuleOptions, RRuleTemporal };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-GZKXW77S.js";
3
+ } from "./chunk-6K5NTVS6.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -104,7 +104,7 @@ function parseByMonthArray(val) {
104
104
  return Number.isFinite(n) ? n : t;
105
105
  });
106
106
  }
107
- function parseRRuleString(input, targetTimezone, dtstart) {
107
+ function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
108
108
  var _a, _b, _c, _d, _e;
109
109
  const unfoldedInput = unfoldLine(input).trim();
110
110
  let parsedDtstart;
@@ -196,7 +196,20 @@ function parseRRuleString(input, targetTimezone, dtstart) {
196
196
  break;
197
197
  }
198
198
  if (!untilHasTime) {
199
- throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
199
+ if (strict) {
200
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
201
+ }
202
+ const localEndOfDay = parseIcsDateTime(val, tzid || "UTC", "DATE").with({
203
+ hour: 23,
204
+ minute: 59,
205
+ second: 59,
206
+ millisecond: 0,
207
+ microsecond: 0,
208
+ nanosecond: 0
209
+ });
210
+ const requiresUtc2 = dtstartHasTzid || dtstartIsUtc;
211
+ opts.until = requiresUtc2 ? localEndOfDay.withTimeZone("UTC") : localEndOfDay;
212
+ break;
200
213
  }
201
214
  const requiresUtc = dtstartHasTzid || dtstartIsUtc;
202
215
  if (requiresUtc && !val.endsWith("Z")) {
@@ -254,19 +267,19 @@ var _RRuleTemporal = class _RRuleTemporal {
254
267
  return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
255
268
  }
256
269
  constructor(params) {
257
- var _a, _b, _c, _d, _e, _f, _g;
270
+ var _a, _b, _c, _d, _e, _f, _g, _h;
258
271
  let manual;
259
272
  if (isIcsOpts(params)) {
260
- const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart);
273
+ const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
261
274
  if (!parsed.dtstart) {
262
275
  throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
263
276
  }
264
- this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
277
+ this.tzid = (_c = (_b = parsed.tzid) != null ? _b : params.tzid) != null ? _c : "UTC";
265
278
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
266
279
  manual = __spreadProps(__spreadValues({}, parsed), {
267
280
  // Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
268
- count: (_c = params.count) != null ? _c : parsed.count,
269
- until: (_d = params.until) != null ? _d : parsed.until,
281
+ count: (_d = params.count) != null ? _d : parsed.count,
282
+ until: (_e = params.until) != null ? _e : parsed.until,
270
283
  strict: params.strict,
271
284
  maxIterations: params.maxIterations,
272
285
  includeDtstart: params.includeDtstart,
@@ -282,7 +295,7 @@ var _RRuleTemporal = class _RRuleTemporal {
282
295
  this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
283
296
  }
284
297
  if (!manual.freq) throw new Error("RRULE must include FREQ");
285
- manual.interval = (_e = manual.interval) != null ? _e : 1;
298
+ manual.interval = (_f = manual.interval) != null ? _f : 1;
286
299
  if (manual.interval <= 0) {
287
300
  throw new Error("Cannot create RRule: interval must be greater than 0");
288
301
  }
@@ -293,8 +306,8 @@ var _RRuleTemporal = class _RRuleTemporal {
293
306
  manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
294
307
  }
295
308
  this.opts = this.sanitizeOpts(manual);
296
- this.maxIterations = (_f = manual.maxIterations) != null ? _f : 1e4;
297
- this.includeDtstart = (_g = manual.includeDtstart) != null ? _g : false;
309
+ this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
310
+ this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
298
311
  }
299
312
  sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
300
313
  if (!arr) return void 0;
@@ -1517,6 +1530,32 @@ var _RRuleTemporal = class _RRuleTemporal {
1517
1530
  const safetyMargin = Math.min(targetRuleCount, 10);
1518
1531
  return matchCount >= targetRuleCount + safetyMargin;
1519
1532
  }
1533
+ hasTimeOfDayBetween(startTime, endTime) {
1534
+ var _a, _b, _c;
1535
+ if (import_polyfill.Temporal.PlainTime.compare(startTime, endTime) >= 0) return false;
1536
+ const base = this.originalDtstart;
1537
+ const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
1538
+ const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
1539
+ const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
1540
+ for (const hour of hours) {
1541
+ for (const minute of minutes) {
1542
+ for (const second of seconds) {
1543
+ const candidate = import_polyfill.Temporal.PlainTime.from({
1544
+ hour,
1545
+ minute,
1546
+ second,
1547
+ millisecond: base.millisecond,
1548
+ microsecond: base.microsecond,
1549
+ nanosecond: base.nanosecond
1550
+ });
1551
+ if (import_polyfill.Temporal.PlainTime.compare(candidate, startTime) >= 0 && import_polyfill.Temporal.PlainTime.compare(candidate, endTime) < 0) {
1552
+ return true;
1553
+ }
1554
+ }
1555
+ }
1556
+ }
1557
+ return false;
1558
+ }
1520
1559
  /**
1521
1560
  * Returns all occurrences of the rule within a specified time window.
1522
1561
  * @param after - The start date or Temporal.ZonedDateTime object.
@@ -1561,37 +1600,42 @@ var _RRuleTemporal = class _RRuleTemporal {
1561
1600
  unit = "seconds";
1562
1601
  }
1563
1602
  const dtstartNormalized = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1603
+ const startZdtNormalized = _RRuleTemporal.normalizeToPolyfill(startZdt).withTimeZone(dtstartNormalized.timeZoneId);
1564
1604
  const alignedNormalized = _RRuleTemporal.normalizeToPolyfill(
1565
1605
  aligned.withPlainTime(this.originalDtstart.toPlainTime())
1566
1606
  ).withTimeZone(dtstartNormalized.timeZoneId);
1567
- const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1607
+ const diffAnchor = ["hours", "minutes", "seconds"].includes(unit) ? startZdtNormalized : alignedNormalized;
1608
+ const diffDur = dtstartNormalized.until(diffAnchor, { largestUnit: unit });
1568
1609
  const unitsBetween = diffDur[unit];
1569
- const steps = Math.floor(unitsBetween / interval);
1570
- let toAdd;
1571
- const jump = steps * interval;
1572
- switch (unit) {
1573
- case "years":
1574
- toAdd = { years: jump };
1575
- break;
1576
- case "months":
1577
- toAdd = { months: jump };
1578
- break;
1579
- case "weeks":
1580
- toAdd = { weeks: jump };
1581
- break;
1582
- case "days":
1583
- toAdd = { days: jump };
1584
- break;
1585
- case "hours":
1586
- toAdd = { hours: jump };
1587
- break;
1588
- case "minutes":
1589
- toAdd = { minutes: jump };
1590
- break;
1591
- default:
1592
- toAdd = { seconds: jump };
1610
+ let steps = Math.floor(unitsBetween / interval);
1611
+ const durationForJump = (jump) => {
1612
+ switch (unit) {
1613
+ case "years":
1614
+ return { years: jump };
1615
+ case "months":
1616
+ return { months: jump };
1617
+ case "weeks":
1618
+ return { weeks: jump };
1619
+ case "days":
1620
+ return { days: jump };
1621
+ case "hours":
1622
+ return { hours: jump };
1623
+ case "minutes":
1624
+ return { minutes: jump };
1625
+ default:
1626
+ return { seconds: jump };
1627
+ }
1628
+ };
1629
+ let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1630
+ if (steps > 0 && ["years", "months", "weeks", "days"].includes(unit)) {
1631
+ const sameDate = candidate.toPlainDate().equals(startZdtNormalized.toPlainDate());
1632
+ if (sameDate && import_polyfill.Temporal.ZonedDateTime.compare(candidate, startZdtNormalized) > 0) {
1633
+ if (this.hasTimeOfDayBetween(startZdtNormalized.toPlainTime(), candidate.toPlainTime())) {
1634
+ steps -= 1;
1635
+ candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(durationForJump(steps * interval)));
1636
+ }
1637
+ }
1593
1638
  }
1594
- let candidate = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart.add(toAdd));
1595
1639
  const dtstartForCompare = _RRuleTemporal.normalizeToPolyfill(this.opts.dtstart);
1596
1640
  if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1597
1641
  candidate = dtstartForCompare;
@@ -2538,7 +2582,8 @@ var en = {
2538
2582
  date: "date",
2539
2583
  dates: "dates",
2540
2584
  and: "and",
2541
- last: "last"
2585
+ last: "last",
2586
+ starting_from: "starting from"
2542
2587
  },
2543
2588
  ordinal: (n) => {
2544
2589
  const abs = Math.abs(n);
@@ -2596,7 +2641,8 @@ var de = {
2596
2641
  date: "Datum",
2597
2642
  dates: "Daten",
2598
2643
  and: "und",
2599
- last: "letzter"
2644
+ last: "letzter",
2645
+ starting_from: "beginnend am"
2600
2646
  },
2601
2647
  ordinal: (n) => {
2602
2648
  if (n < 0) return "letzten";
@@ -2653,7 +2699,8 @@ var es = {
2653
2699
  date: "fecha",
2654
2700
  dates: "fechas",
2655
2701
  and: "y",
2656
- last: "\xFAltimo"
2702
+ last: "\xFAltimo",
2703
+ starting_from: "a partir de"
2657
2704
  },
2658
2705
  ordinal: (n) => n < 0 ? "\xFAltimo" : `${Math.abs(n)}\xBA`
2659
2706
  };
@@ -2707,7 +2754,8 @@ var hi = {
2707
2754
  date: "\u0924\u093E\u0930\u0940\u0916",
2708
2755
  dates: "\u0924\u093E\u0930\u0940\u0916\u0947\u0902",
2709
2756
  and: "\u0914\u0930",
2710
- last: "\u0906\u0916\u093F\u0930\u0940"
2757
+ last: "\u0906\u0916\u093F\u0930\u0940",
2758
+ starting_from: "\u0938\u0947 \u0936\u0941\u0930\u0942"
2711
2759
  },
2712
2760
  ordinal: (n) => n < 0 ? "\u0906\u0916\u093F\u0930\u0940" : `${Math.abs(n)}\u0935\u093E\u0902`
2713
2761
  };
@@ -2748,7 +2796,8 @@ var yue = {
2748
2796
  date: "\u65E5\u671F",
2749
2797
  dates: "\u65E5\u671F",
2750
2798
  and: "\u548C",
2751
- last: "\u6700\u5F8C"
2799
+ last: "\u6700\u5F8C",
2800
+ starting_from: "\u7531"
2752
2801
  },
2753
2802
  ordinal: (n) => n < 0 ? "\u6700\u5F8C" : `\u7B2C${Math.abs(n)}`
2754
2803
  };
@@ -2802,7 +2851,8 @@ var ar = {
2802
2851
  date: "\u062A\u0627\u0631\u064A\u062E",
2803
2852
  dates: "\u062A\u0648\u0627\u0631\u064A\u062E",
2804
2853
  and: "\u0648",
2805
- last: "\u0627\u0644\u0623\u062E\u064A\u0631"
2854
+ last: "\u0627\u0644\u0623\u062E\u064A\u0631",
2855
+ starting_from: "\u0627\u0628\u062A\u062F\u0627\u0621\u064B \u0645\u0646"
2806
2856
  },
2807
2857
  ordinal: (n) => {
2808
2858
  if (n < 0) return "\u0627\u0644\u0623\u062E\u064A\u0631";
@@ -2875,7 +2925,8 @@ var he = {
2875
2925
  date: "\u05EA\u05D0\u05E8\u05D9\u05DA",
2876
2926
  dates: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD",
2877
2927
  and: "\u05D5",
2878
- last: "\u05D0\u05D7\u05E8\u05D5\u05DF"
2928
+ last: "\u05D0\u05D7\u05E8\u05D5\u05DF",
2929
+ starting_from: "\u05D4\u05D7\u05DC \u05DE"
2879
2930
  },
2880
2931
  ordinal: (n) => {
2881
2932
  if (n < 0) return "\u05D0\u05D7\u05E8\u05D5\u05DF";
@@ -2935,25 +2986,26 @@ var zh = {
2935
2986
  date: "\u65E5\u671F",
2936
2987
  dates: "\u65E5\u671F",
2937
2988
  and: "\u548C",
2938
- last: "\u6700\u540E"
2989
+ last: "\u6700\u540E",
2990
+ starting_from: "\u4ECE"
2939
2991
  },
2940
2992
  ordinal: (n) => n < 0 ? "\u6700\u540E" : `\u7B2C${Math.abs(n)}`
2941
2993
  };
2942
2994
  var fr = {
2943
- weekdayNames: ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
2995
+ weekdayNames: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
2944
2996
  monthNames: [
2945
- "Janvier",
2946
- "F\xE9vrier",
2947
- "Mars",
2948
- "Avril",
2949
- "Mai",
2950
- "Juin",
2951
- "Juillet",
2952
- "Ao\xFBt",
2953
- "Septembre",
2954
- "Octobre",
2955
- "Novembre",
2956
- "D\xE9cembre"
2997
+ "janvier",
2998
+ "f\xE9vrier",
2999
+ "mars",
3000
+ "avril",
3001
+ "mai",
3002
+ "juin",
3003
+ "juillet",
3004
+ "ao\xFBt",
3005
+ "septembre",
3006
+ "octobre",
3007
+ "novembre",
3008
+ "d\xE9cembre"
2957
3009
  ],
2958
3010
  units: {
2959
3011
  year: { singular: "ann\xE9e", plural: "ans" },
@@ -2976,7 +3028,7 @@ var fr = {
2976
3028
  at: "\xE0",
2977
3029
  at_minute: "\xE0 la minute",
2978
3030
  at_second: "\xE0 la seconde",
2979
- until: "jusqu'\xE0",
3031
+ until: "jusqu'au",
2980
3032
  for: "pendant",
2981
3033
  time: "fois",
2982
3034
  times: "fois",
@@ -2989,7 +3041,8 @@ var fr = {
2989
3041
  date: "date",
2990
3042
  dates: "dates",
2991
3043
  and: "et",
2992
- last: "dernier"
3044
+ last: "dernier",
3045
+ starting_from: "\xE0 partir du"
2993
3046
  },
2994
3047
  ordinal: (n) => {
2995
3048
  const abs = Math.abs(n);
@@ -3064,11 +3117,20 @@ function tzAbbreviation(zdt) {
3064
3117
  const tzPart = parts.find((p) => p.type === "timeZoneName");
3065
3118
  return (tzPart == null ? void 0 : tzPart.value) || zdt.timeZoneId;
3066
3119
  }
3067
- function toText(input, locale) {
3120
+ function formatLocalizedDate(zdt, locale) {
3121
+ try {
3122
+ return zdt.toLocaleString(locale, { dateStyle: "long" });
3123
+ } catch (e) {
3124
+ return zdt.toLocaleString("en", { dateStyle: "long" });
3125
+ }
3126
+ }
3127
+ function toText(input, locale, options = {}) {
3068
3128
  const rule = typeof input === "string" ? new RRuleTemporal({ rruleString: input }) : input;
3069
3129
  const opts = rule.options();
3070
- const lang = (locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale).split("-")[0];
3130
+ const resolvedLocale = locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale;
3131
+ const lang = resolvedLocale.split("-")[0];
3071
3132
  const data = LOCALES[lang] || en;
3133
+ const dateLocale = LOCALES[lang] ? resolvedLocale : "en";
3072
3134
  const {
3073
3135
  freq,
3074
3136
  interval = 1,
@@ -3170,9 +3232,11 @@ function toText(input, locale) {
3170
3232
  if (!textByHour && !textByMinute && textBySecond) {
3171
3233
  parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
3172
3234
  }
3235
+ if (options.includeDtstart) {
3236
+ parts.push(data.words.starting_from, formatLocalizedDate(opts.dtstart, dateLocale));
3237
+ }
3173
3238
  if (until) {
3174
- const monthName = data.monthNames[until.month - 1];
3175
- parts.push(data.words.until, `${monthName} ${until.day}, ${until.year}`);
3239
+ parts.push(data.words.until, formatLocalizedDate(until, dateLocale));
3176
3240
  } else if (count !== void 0) {
3177
3241
  parts.push(data.words.for, count.toString(), count === 1 ? data.words.time : data.words.times);
3178
3242
  }
package/dist/totext.d.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { RRuleTemporal } from './index.cjs';
2
2
  import '@js-temporal/polyfill';
3
3
 
4
- declare function toText(input: RRuleTemporal | string, locale?: string): string;
4
+ interface ToTextOptions {
5
+ includeDtstart?: boolean;
6
+ }
7
+ declare function toText(input: RRuleTemporal | string, locale?: string, options?: ToTextOptions): string;
5
8
 
6
- export { toText };
9
+ export { type ToTextOptions, toText };
package/dist/totext.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { RRuleTemporal } from './index.js';
2
2
  import '@js-temporal/polyfill';
3
3
 
4
- declare function toText(input: RRuleTemporal | string, locale?: string): string;
4
+ interface ToTextOptions {
5
+ includeDtstart?: boolean;
6
+ }
7
+ declare function toText(input: RRuleTemporal | string, locale?: string, options?: ToTextOptions): string;
5
8
 
6
- export { toText };
9
+ export { type ToTextOptions, toText };
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-GZKXW77S.js";
3
+ } from "./chunk-6K5NTVS6.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
@@ -53,7 +53,8 @@ var en = {
53
53
  date: "date",
54
54
  dates: "dates",
55
55
  and: "and",
56
- last: "last"
56
+ last: "last",
57
+ starting_from: "starting from"
57
58
  },
58
59
  ordinal: (n) => {
59
60
  const abs = Math.abs(n);
@@ -111,7 +112,8 @@ var de = {
111
112
  date: "Datum",
112
113
  dates: "Daten",
113
114
  and: "und",
114
- last: "letzter"
115
+ last: "letzter",
116
+ starting_from: "beginnend am"
115
117
  },
116
118
  ordinal: (n) => {
117
119
  if (n < 0) return "letzten";
@@ -168,7 +170,8 @@ var es = {
168
170
  date: "fecha",
169
171
  dates: "fechas",
170
172
  and: "y",
171
- last: "\xFAltimo"
173
+ last: "\xFAltimo",
174
+ starting_from: "a partir de"
172
175
  },
173
176
  ordinal: (n) => n < 0 ? "\xFAltimo" : `${Math.abs(n)}\xBA`
174
177
  };
@@ -222,7 +225,8 @@ var hi = {
222
225
  date: "\u0924\u093E\u0930\u0940\u0916",
223
226
  dates: "\u0924\u093E\u0930\u0940\u0916\u0947\u0902",
224
227
  and: "\u0914\u0930",
225
- last: "\u0906\u0916\u093F\u0930\u0940"
228
+ last: "\u0906\u0916\u093F\u0930\u0940",
229
+ starting_from: "\u0938\u0947 \u0936\u0941\u0930\u0942"
226
230
  },
227
231
  ordinal: (n) => n < 0 ? "\u0906\u0916\u093F\u0930\u0940" : `${Math.abs(n)}\u0935\u093E\u0902`
228
232
  };
@@ -263,7 +267,8 @@ var yue = {
263
267
  date: "\u65E5\u671F",
264
268
  dates: "\u65E5\u671F",
265
269
  and: "\u548C",
266
- last: "\u6700\u5F8C"
270
+ last: "\u6700\u5F8C",
271
+ starting_from: "\u7531"
267
272
  },
268
273
  ordinal: (n) => n < 0 ? "\u6700\u5F8C" : `\u7B2C${Math.abs(n)}`
269
274
  };
@@ -317,7 +322,8 @@ var ar = {
317
322
  date: "\u062A\u0627\u0631\u064A\u062E",
318
323
  dates: "\u062A\u0648\u0627\u0631\u064A\u062E",
319
324
  and: "\u0648",
320
- last: "\u0627\u0644\u0623\u062E\u064A\u0631"
325
+ last: "\u0627\u0644\u0623\u062E\u064A\u0631",
326
+ starting_from: "\u0627\u0628\u062A\u062F\u0627\u0621\u064B \u0645\u0646"
321
327
  },
322
328
  ordinal: (n) => {
323
329
  if (n < 0) return "\u0627\u0644\u0623\u062E\u064A\u0631";
@@ -390,7 +396,8 @@ var he = {
390
396
  date: "\u05EA\u05D0\u05E8\u05D9\u05DA",
391
397
  dates: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD",
392
398
  and: "\u05D5",
393
- last: "\u05D0\u05D7\u05E8\u05D5\u05DF"
399
+ last: "\u05D0\u05D7\u05E8\u05D5\u05DF",
400
+ starting_from: "\u05D4\u05D7\u05DC \u05DE"
394
401
  },
395
402
  ordinal: (n) => {
396
403
  if (n < 0) return "\u05D0\u05D7\u05E8\u05D5\u05DF";
@@ -450,25 +457,26 @@ var zh = {
450
457
  date: "\u65E5\u671F",
451
458
  dates: "\u65E5\u671F",
452
459
  and: "\u548C",
453
- last: "\u6700\u540E"
460
+ last: "\u6700\u540E",
461
+ starting_from: "\u4ECE"
454
462
  },
455
463
  ordinal: (n) => n < 0 ? "\u6700\u540E" : `\u7B2C${Math.abs(n)}`
456
464
  };
457
465
  var fr = {
458
- weekdayNames: ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
466
+ weekdayNames: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
459
467
  monthNames: [
460
- "Janvier",
461
- "F\xE9vrier",
462
- "Mars",
463
- "Avril",
464
- "Mai",
465
- "Juin",
466
- "Juillet",
467
- "Ao\xFBt",
468
- "Septembre",
469
- "Octobre",
470
- "Novembre",
471
- "D\xE9cembre"
468
+ "janvier",
469
+ "f\xE9vrier",
470
+ "mars",
471
+ "avril",
472
+ "mai",
473
+ "juin",
474
+ "juillet",
475
+ "ao\xFBt",
476
+ "septembre",
477
+ "octobre",
478
+ "novembre",
479
+ "d\xE9cembre"
472
480
  ],
473
481
  units: {
474
482
  year: { singular: "ann\xE9e", plural: "ans" },
@@ -491,7 +499,7 @@ var fr = {
491
499
  at: "\xE0",
492
500
  at_minute: "\xE0 la minute",
493
501
  at_second: "\xE0 la seconde",
494
- until: "jusqu'\xE0",
502
+ until: "jusqu'au",
495
503
  for: "pendant",
496
504
  time: "fois",
497
505
  times: "fois",
@@ -504,7 +512,8 @@ var fr = {
504
512
  date: "date",
505
513
  dates: "dates",
506
514
  and: "et",
507
- last: "dernier"
515
+ last: "dernier",
516
+ starting_from: "\xE0 partir du"
508
517
  },
509
518
  ordinal: (n) => {
510
519
  const abs = Math.abs(n);
@@ -579,11 +588,20 @@ function tzAbbreviation(zdt) {
579
588
  const tzPart = parts.find((p) => p.type === "timeZoneName");
580
589
  return (tzPart == null ? void 0 : tzPart.value) || zdt.timeZoneId;
581
590
  }
582
- function toText(input, locale) {
591
+ function formatLocalizedDate(zdt, locale) {
592
+ try {
593
+ return zdt.toLocaleString(locale, { dateStyle: "long" });
594
+ } catch (e) {
595
+ return zdt.toLocaleString("en", { dateStyle: "long" });
596
+ }
597
+ }
598
+ function toText(input, locale, options = {}) {
583
599
  const rule = typeof input === "string" ? new RRuleTemporal({ rruleString: input }) : input;
584
600
  const opts = rule.options();
585
- const lang = (locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale).split("-")[0];
601
+ const resolvedLocale = locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale;
602
+ const lang = resolvedLocale.split("-")[0];
586
603
  const data = LOCALES[lang] || en;
604
+ const dateLocale = LOCALES[lang] ? resolvedLocale : "en";
587
605
  const {
588
606
  freq,
589
607
  interval = 1,
@@ -685,9 +703,11 @@ function toText(input, locale) {
685
703
  if (!textByHour && !textByMinute && textBySecond) {
686
704
  parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
687
705
  }
706
+ if (options.includeDtstart) {
707
+ parts.push(data.words.starting_from, formatLocalizedDate(opts.dtstart, dateLocale));
708
+ }
688
709
  if (until) {
689
- const monthName = data.monthNames[until.month - 1];
690
- parts.push(data.words.until, `${monthName} ${until.day}, ${until.year}`);
710
+ parts.push(data.words.until, formatLocalizedDate(until, dateLocale));
691
711
  } else if (count !== void 0) {
692
712
  parts.push(data.words.for, count.toString(), count === 1 ? data.words.time : data.words.times);
693
713
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
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",