rrule-temporal 1.4.1 → 1.4.2
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 +13 -0
- package/dist/{chunk-76UOKZYT.js → chunk-EHMOE4GK.js} +25 -3
- package/dist/index.cjs +25 -3
- package/dist/index.js +1 -1
- package/dist/totext.cjs +25 -3
- package/dist/totext.js +1 -1
- package/package.json +1 -1
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,
|
|
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
|
-
|
|
158
|
-
if (
|
|
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":
|
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,
|
|
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
|
-
|
|
179
|
-
if (
|
|
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":
|
package/dist/index.js
CHANGED
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,
|
|
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
|
-
|
|
181
|
-
if (
|
|
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":
|
package/dist/totext.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-temporal",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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",
|