rrule-temporal 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # RRule Temporal
2
2
 
3
+ > This library is sponsored by [PostalForm 💌](https://postalform.com/?utm_source=github&utm_medium=readme&utm_campaign=rrule-temporal) — upload a PDF and we print + mail it via USPS (no printer or stamps needed). The only mailing platform for AI Agents via MCP, and the easiest one for humans!
4
+
3
5
  The first and only fully compliant Recurrence rule ([RFC-5545](https://www.rfc-editor.org/rfc/rfc5545.html)) processing JS/TS library built on the Temporal API, now with support for [RFC-7529](https://www.rfc-editor.org/rfc/rfc7529.html) (RSCALE / SKIP) for non-Gregorian calendars.
4
6
  The library accepts the familiar `RRULE` format and returns
5
7
  `Temporal.ZonedDateTime` instances for easy time‑zone aware scheduling.
@@ -55,6 +57,11 @@ This is useful when:
55
57
  - Storing recurrence patterns separately from start dates in databases
56
58
  - Building rules programmatically from user input
57
59
 
60
+ Note on `UNTIL` (RFC 5545): if `DTSTART` is a DATE-TIME with a `TZID` or UTC (`Z`),
61
+ `UNTIL` must be a DATE-TIME in UTC (trailing `Z`). If `DTSTART` is `VALUE=DATE`,
62
+ `UNTIL` must be a DATE (no time). Floating DATE-TIME rules (no `TZID`, no `Z`)
63
+ allow a floating `UNTIL`.
64
+
58
65
  ## Creating a rule with options
59
66
 
60
67
  Instead of a full ICS string you can supply the recurrence parameters directly:
@@ -377,3 +384,9 @@ const appOccurrences = rawOccurrences.map((zdt) =>
377
384
  ```
378
385
 
379
386
  Both approaches preserve the original calendar, time-zone and nanosecond accuracy.
387
+
388
+ ## Sponsor
389
+
390
+ If this library saves you time, sponsorship helps keep it maintained.
391
+
392
+ Primary sponsor: [PostalForm](https://postalform.com/?utm_source=github&utm_medium=readme&utm_campaign=rrule-temporal)
@@ -86,6 +86,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
86
86
  const unfoldedInput = unfoldLine(input).trim();
87
87
  let parsedDtstart;
88
88
  let tzid = targetTimezone;
89
+ let dtstartValueType = "DATE-TIME";
90
+ let dtstartHasTzid = false;
91
+ let dtstartIsUtc = false;
89
92
  let rruleLine;
90
93
  let exDate = [];
91
94
  let rDate = [];
@@ -98,8 +101,12 @@ function parseRRuleString(input, targetTimezone, dtstart) {
98
101
  const dtMatch = dtLine.match(/DTSTART(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
99
102
  if (!dtMatch) throw new Error("Invalid DTSTART in ICS snippet");
100
103
  const [, valueType, dtTzid, dtValue] = dtMatch;
104
+ const normalizedValueType = (valueType || ((dtValue == null ? void 0 : dtValue.includes("T")) ? "DATE-TIME" : "DATE")).toUpperCase();
105
+ dtstartValueType = normalizedValueType === "DATE" ? "DATE" : "DATE-TIME";
106
+ dtstartHasTzid = Boolean(dtTzid);
107
+ dtstartIsUtc = Boolean(dtValue == null ? void 0 : dtValue.endsWith("Z"));
101
108
  const effectiveTzid = (_b = (_a = dtTzid != null ? dtTzid : targetTimezone) != null ? _a : tzid) != null ? _b : "UTC";
102
- parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, valueType);
109
+ parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, dtstartValueType);
103
110
  tzid = (_e = (_d = (_c = dtTzid != null ? dtTzid : parsedDtstart.timeZoneId) != null ? _c : targetTimezone) != null ? _d : tzid) != null ? _e : "UTC";
104
111
  rruleLine = rrLine;
105
112
  exDate = parseDateLines(exLines, "EXDATE", tzid != null ? tzid : "UTC");
@@ -109,6 +116,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
109
116
  rruleLine = unfoldedInput;
110
117
  if (parsedDtstart) {
111
118
  tzid = parsedDtstart.timeZoneId;
119
+ dtstartValueType = "DATE-TIME";
120
+ dtstartHasTzid = true;
121
+ dtstartIsUtc = parsedDtstart.timeZoneId === "UTC";
112
122
  }
113
123
  }
114
124
  const parts = rruleLine ? rruleLine.replace(/^RRULE:/i, "").split(";") : [];
@@ -154,10 +164,22 @@ function parseRRuleString(input, targetTimezone, dtstart) {
154
164
  opts.count = parseInt(val, 10);
155
165
  break;
156
166
  case "UNTIL": {
157
- opts.until = parseIcsDateTime(val, tzid || "UTC");
158
- if (!val.endsWith("Z") && tzid !== "UTC") {
167
+ const untilHasTime = val.includes("T");
168
+ if (dtstartValueType === "DATE") {
169
+ if (untilHasTime) {
170
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
171
+ }
172
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE");
173
+ break;
174
+ }
175
+ if (!untilHasTime) {
176
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
177
+ }
178
+ const requiresUtc = dtstartHasTzid || dtstartIsUtc;
179
+ if (requiresUtc && !val.endsWith("Z")) {
159
180
  throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
160
181
  }
182
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE-TIME");
161
183
  break;
162
184
  }
163
185
  case "BYHOUR":
@@ -1505,7 +1527,11 @@ var _RRuleTemporal = class _RRuleTemporal {
1505
1527
  default:
1506
1528
  unit = "seconds";
1507
1529
  }
1508
- const diffDur = this.opts.dtstart.until(aligned, { largestUnit: unit });
1530
+ const dtstartNormalized = Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1531
+ const alignedNormalized = Temporal.ZonedDateTime.from(
1532
+ aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1533
+ ).withTimeZone(dtstartNormalized.timeZoneId);
1534
+ const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1509
1535
  const unitsBetween = diffDur[unit];
1510
1536
  const steps = Math.floor(unitsBetween / interval);
1511
1537
  let toAdd;
@@ -1532,9 +1558,10 @@ var _RRuleTemporal = class _RRuleTemporal {
1532
1558
  default:
1533
1559
  toAdd = { seconds: jump };
1534
1560
  }
1535
- let candidate = this.opts.dtstart.add(toAdd);
1536
- if (Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) < 0) {
1537
- candidate = this.opts.dtstart;
1561
+ let candidate = Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1562
+ const dtstartForCompare = Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1563
+ if (Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1564
+ candidate = dtstartForCompare;
1538
1565
  }
1539
1566
  tempOpts.dtstart = candidate;
1540
1567
  }
package/dist/index.cjs CHANGED
@@ -107,6 +107,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
107
107
  const unfoldedInput = unfoldLine(input).trim();
108
108
  let parsedDtstart;
109
109
  let tzid = targetTimezone;
110
+ let dtstartValueType = "DATE-TIME";
111
+ let dtstartHasTzid = false;
112
+ let dtstartIsUtc = false;
110
113
  let rruleLine;
111
114
  let exDate = [];
112
115
  let rDate = [];
@@ -119,8 +122,12 @@ function parseRRuleString(input, targetTimezone, dtstart) {
119
122
  const dtMatch = dtLine.match(/DTSTART(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
120
123
  if (!dtMatch) throw new Error("Invalid DTSTART in ICS snippet");
121
124
  const [, valueType, dtTzid, dtValue] = dtMatch;
125
+ const normalizedValueType = (valueType || ((dtValue == null ? void 0 : dtValue.includes("T")) ? "DATE-TIME" : "DATE")).toUpperCase();
126
+ dtstartValueType = normalizedValueType === "DATE" ? "DATE" : "DATE-TIME";
127
+ dtstartHasTzid = Boolean(dtTzid);
128
+ dtstartIsUtc = Boolean(dtValue == null ? void 0 : dtValue.endsWith("Z"));
122
129
  const effectiveTzid = (_b = (_a = dtTzid != null ? dtTzid : targetTimezone) != null ? _a : tzid) != null ? _b : "UTC";
123
- parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, valueType);
130
+ parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, dtstartValueType);
124
131
  tzid = (_e = (_d = (_c = dtTzid != null ? dtTzid : parsedDtstart.timeZoneId) != null ? _c : targetTimezone) != null ? _d : tzid) != null ? _e : "UTC";
125
132
  rruleLine = rrLine;
126
133
  exDate = parseDateLines(exLines, "EXDATE", tzid != null ? tzid : "UTC");
@@ -130,6 +137,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
130
137
  rruleLine = unfoldedInput;
131
138
  if (parsedDtstart) {
132
139
  tzid = parsedDtstart.timeZoneId;
140
+ dtstartValueType = "DATE-TIME";
141
+ dtstartHasTzid = true;
142
+ dtstartIsUtc = parsedDtstart.timeZoneId === "UTC";
133
143
  }
134
144
  }
135
145
  const parts = rruleLine ? rruleLine.replace(/^RRULE:/i, "").split(";") : [];
@@ -175,10 +185,22 @@ function parseRRuleString(input, targetTimezone, dtstart) {
175
185
  opts.count = parseInt(val, 10);
176
186
  break;
177
187
  case "UNTIL": {
178
- opts.until = parseIcsDateTime(val, tzid || "UTC");
179
- if (!val.endsWith("Z") && tzid !== "UTC") {
188
+ const untilHasTime = val.includes("T");
189
+ if (dtstartValueType === "DATE") {
190
+ if (untilHasTime) {
191
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
192
+ }
193
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE");
194
+ break;
195
+ }
196
+ if (!untilHasTime) {
197
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
198
+ }
199
+ const requiresUtc = dtstartHasTzid || dtstartIsUtc;
200
+ if (requiresUtc && !val.endsWith("Z")) {
180
201
  throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
181
202
  }
203
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE-TIME");
182
204
  break;
183
205
  }
184
206
  case "BYHOUR":
@@ -1526,7 +1548,11 @@ var _RRuleTemporal = class _RRuleTemporal {
1526
1548
  default:
1527
1549
  unit = "seconds";
1528
1550
  }
1529
- const diffDur = this.opts.dtstart.until(aligned, { largestUnit: unit });
1551
+ const dtstartNormalized = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1552
+ const alignedNormalized = import_polyfill.Temporal.ZonedDateTime.from(
1553
+ aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1554
+ ).withTimeZone(dtstartNormalized.timeZoneId);
1555
+ const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1530
1556
  const unitsBetween = diffDur[unit];
1531
1557
  const steps = Math.floor(unitsBetween / interval);
1532
1558
  let toAdd;
@@ -1553,9 +1579,10 @@ var _RRuleTemporal = class _RRuleTemporal {
1553
1579
  default:
1554
1580
  toAdd = { seconds: jump };
1555
1581
  }
1556
- let candidate = this.opts.dtstart.add(toAdd);
1557
- if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) < 0) {
1558
- candidate = this.opts.dtstart;
1582
+ let candidate = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1583
+ const dtstartForCompare = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1584
+ if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1585
+ candidate = dtstartForCompare;
1559
1586
  }
1560
1587
  tempOpts.dtstart = candidate;
1561
1588
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-76UOKZYT.js";
3
+ } from "./chunk-BN57WTKY.js";
4
4
  export {
5
5
  RRuleTemporal
6
6
  };
package/dist/totext.cjs CHANGED
@@ -109,6 +109,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
109
109
  const unfoldedInput = unfoldLine(input).trim();
110
110
  let parsedDtstart;
111
111
  let tzid = targetTimezone;
112
+ let dtstartValueType = "DATE-TIME";
113
+ let dtstartHasTzid = false;
114
+ let dtstartIsUtc = false;
112
115
  let rruleLine;
113
116
  let exDate = [];
114
117
  let rDate = [];
@@ -121,8 +124,12 @@ function parseRRuleString(input, targetTimezone, dtstart) {
121
124
  const dtMatch = dtLine.match(/DTSTART(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
122
125
  if (!dtMatch) throw new Error("Invalid DTSTART in ICS snippet");
123
126
  const [, valueType, dtTzid, dtValue] = dtMatch;
127
+ const normalizedValueType = (valueType || ((dtValue == null ? void 0 : dtValue.includes("T")) ? "DATE-TIME" : "DATE")).toUpperCase();
128
+ dtstartValueType = normalizedValueType === "DATE" ? "DATE" : "DATE-TIME";
129
+ dtstartHasTzid = Boolean(dtTzid);
130
+ dtstartIsUtc = Boolean(dtValue == null ? void 0 : dtValue.endsWith("Z"));
124
131
  const effectiveTzid = (_b = (_a = dtTzid != null ? dtTzid : targetTimezone) != null ? _a : tzid) != null ? _b : "UTC";
125
- parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, valueType);
132
+ parsedDtstart = parseIcsDateTime(dtValue, effectiveTzid, dtstartValueType);
126
133
  tzid = (_e = (_d = (_c = dtTzid != null ? dtTzid : parsedDtstart.timeZoneId) != null ? _c : targetTimezone) != null ? _d : tzid) != null ? _e : "UTC";
127
134
  rruleLine = rrLine;
128
135
  exDate = parseDateLines(exLines, "EXDATE", tzid != null ? tzid : "UTC");
@@ -132,6 +139,9 @@ function parseRRuleString(input, targetTimezone, dtstart) {
132
139
  rruleLine = unfoldedInput;
133
140
  if (parsedDtstart) {
134
141
  tzid = parsedDtstart.timeZoneId;
142
+ dtstartValueType = "DATE-TIME";
143
+ dtstartHasTzid = true;
144
+ dtstartIsUtc = parsedDtstart.timeZoneId === "UTC";
135
145
  }
136
146
  }
137
147
  const parts = rruleLine ? rruleLine.replace(/^RRULE:/i, "").split(";") : [];
@@ -177,10 +187,22 @@ function parseRRuleString(input, targetTimezone, dtstart) {
177
187
  opts.count = parseInt(val, 10);
178
188
  break;
179
189
  case "UNTIL": {
180
- opts.until = parseIcsDateTime(val, tzid || "UTC");
181
- if (!val.endsWith("Z") && tzid !== "UTC") {
190
+ const untilHasTime = val.includes("T");
191
+ if (dtstartValueType === "DATE") {
192
+ if (untilHasTime) {
193
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
194
+ }
195
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE");
196
+ break;
197
+ }
198
+ if (!untilHasTime) {
199
+ throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
200
+ }
201
+ const requiresUtc = dtstartHasTzid || dtstartIsUtc;
202
+ if (requiresUtc && !val.endsWith("Z")) {
182
203
  throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
183
204
  }
205
+ opts.until = parseIcsDateTime(val, tzid || "UTC", "DATE-TIME");
184
206
  break;
185
207
  }
186
208
  case "BYHOUR":
@@ -1528,7 +1550,11 @@ var _RRuleTemporal = class _RRuleTemporal {
1528
1550
  default:
1529
1551
  unit = "seconds";
1530
1552
  }
1531
- const diffDur = this.opts.dtstart.until(aligned, { largestUnit: unit });
1553
+ const dtstartNormalized = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1554
+ const alignedNormalized = import_polyfill.Temporal.ZonedDateTime.from(
1555
+ aligned.withPlainTime(this.originalDtstart.toPlainTime()).toString()
1556
+ ).withTimeZone(dtstartNormalized.timeZoneId);
1557
+ const diffDur = dtstartNormalized.until(alignedNormalized, { largestUnit: unit });
1532
1558
  const unitsBetween = diffDur[unit];
1533
1559
  const steps = Math.floor(unitsBetween / interval);
1534
1560
  let toAdd;
@@ -1555,9 +1581,10 @@ var _RRuleTemporal = class _RRuleTemporal {
1555
1581
  default:
1556
1582
  toAdd = { seconds: jump };
1557
1583
  }
1558
- let candidate = this.opts.dtstart.add(toAdd);
1559
- if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.dtstart) < 0) {
1560
- candidate = this.opts.dtstart;
1584
+ let candidate = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.add(toAdd).toString());
1585
+ const dtstartForCompare = import_polyfill.Temporal.ZonedDateTime.from(this.opts.dtstart.toString());
1586
+ if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, dtstartForCompare) < 0) {
1587
+ candidate = dtstartForCompare;
1561
1588
  }
1562
1589
  tempOpts.dtstart = candidate;
1563
1590
  }
package/dist/totext.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RRuleTemporal
3
- } from "./chunk-76UOKZYT.js";
3
+ } from "./chunk-BN57WTKY.js";
4
4
 
5
5
  // src/totext.ts
6
6
  var en = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Recurrence rule (rrule) processing using Temporal PlainDate/PlainDateTime, with cross-timezone and cross-calendar rrule support",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",