rrule-temporal 1.0.0 → 1.1.0
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 +108 -6
- package/dist/chunk-6VZV7PDA.js +1252 -0
- package/dist/index.cjs +88 -51
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/totext.cjs +544 -84
- package/dist/totext.js +456 -33
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# rrule-temporal
|
|
2
2
|
|
|
3
|
-
Recurrence rule (RFC 5545) processing built on the Temporal API.
|
|
3
|
+
The first and only fully compliant Recurrence rule (RFC 5545) processing JS/TS library built on the Temporal API.
|
|
4
4
|
The library accepts the familiar `RRULE` format and returns
|
|
5
5
|
`Temporal.ZonedDateTime` instances for easy time‑zone aware scheduling.
|
|
6
6
|
|
|
7
7
|
See the [demo site](https://ggaabe.github.io/rrule-temporal/) for an interactive playground.
|
|
8
8
|
|
|
9
|
-
> This was created to advance the rrule library to use Temporal, and to provide a more modern API, as the original rrule library is [not maintained anymore](https://github.com/jkbrzt/rrule/issues/615). Maintainers suggested to use Temporal instead of Date:
|
|
9
|
+
> This library was created to advance the rrule library to use Temporal, and to provide a more modern API, as the original rrule library is [not maintained anymore](https://github.com/jkbrzt/rrule/issues/615). Maintainers suggested to use Temporal instead of Date:
|
|
10
10
|
>https://github.com/jkbrzt/rrule/issues/450#issuecomment-1055853095
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -30,6 +30,9 @@ rule.all().forEach(dt => console.log(dt.toString()));
|
|
|
30
30
|
// 2025-01-01T09:00:00[UTC]
|
|
31
31
|
// 2025-01-02T09:00:00[UTC]
|
|
32
32
|
// 2025-01-03T09:00:00[UTC]
|
|
33
|
+
|
|
34
|
+
// Only the first 10 events
|
|
35
|
+
const firstTen = rule.all((_, i) => i < 10);
|
|
33
36
|
```
|
|
34
37
|
|
|
35
38
|
## Creating a rule with options
|
|
@@ -56,6 +59,34 @@ const rule = new RRuleTemporal({
|
|
|
56
59
|
rule.all().forEach(dt => console.log(dt.toString()));
|
|
57
60
|
```
|
|
58
61
|
|
|
62
|
+
### Manual options
|
|
63
|
+
|
|
64
|
+
When creating a rule with individual fields you can specify any of the options
|
|
65
|
+
below. These correspond to the recurrence rule parts defined in RFC 5545:
|
|
66
|
+
|
|
67
|
+
| Option | Description |
|
|
68
|
+
| ------ | ----------- |
|
|
69
|
+
| `freq` | Recurrence frequency (`"YEARLY"`, `"MONTHLY"`, `"WEEKLY"`, `"DAILY"`, `"HOURLY"`, `"MINUTELY"`, `"SECONDLY"`). |
|
|
70
|
+
| `interval` | Interval between each occurrence of `freq`. |
|
|
71
|
+
| `count` | Total number of occurrences. |
|
|
72
|
+
| `until` | Last possible occurrence as `Temporal.ZonedDateTime`. |
|
|
73
|
+
| `byHour` | Hours to include (0–23). |
|
|
74
|
+
| `byMinute` | Minutes to include (0–59). |
|
|
75
|
+
| `bySecond` | Seconds to include (0–59). |
|
|
76
|
+
| `byDay` | List of weekday codes, e.g. `["MO", "WE", "FR"]`. |
|
|
77
|
+
| `byMonth` | Months of the year (1–12). |
|
|
78
|
+
| `byMonthDay` | Days of the month (1–31 or negative from end). |
|
|
79
|
+
| `byYearDay` | Days of the year (1–366 or negative from end). |
|
|
80
|
+
| `byWeekNo` | ISO week numbers (1–53 or negative from end). |
|
|
81
|
+
| `bySetPos` | Select n-th occurrence(s) after other filters. |
|
|
82
|
+
| `wkst` | Weekday on which the week starts (`"MO"`..`"SU"`). |
|
|
83
|
+
| `rDate` | Additional dates to include. |
|
|
84
|
+
| `exDate` | Exception dates to exclude. |
|
|
85
|
+
| `tzid` | Time zone identifier for interpreting dates. |
|
|
86
|
+
| `maxIterations` | Safety cap when generating occurrences. |
|
|
87
|
+
| `includeDtstart` | Include `DTSTART` even if it does not match the pattern. |
|
|
88
|
+
| `dtstart` | First occurrence as `Temporal.ZonedDateTime`. |
|
|
89
|
+
|
|
59
90
|
## Querying occurrences
|
|
60
91
|
|
|
61
92
|
Use the provided methods to enumerate or search for occurrences:
|
|
@@ -73,10 +104,54 @@ const prev = rule.previous(new Date("2025-05-01T00:00Z"));
|
|
|
73
104
|
|
|
74
105
|
## Converting back to text
|
|
75
106
|
|
|
107
|
+
The `toText` helper converts a rule into a human readable description.
|
|
108
|
+
|
|
76
109
|
```typescript
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
110
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
111
|
+
import { RRuleTemporal } from "rrule-temporal";
|
|
112
|
+
import { toText } from "rrule-temporal/totext";
|
|
113
|
+
|
|
114
|
+
const rule = new RRuleTemporal({
|
|
115
|
+
rruleString: `DTSTART;TZID=UTC:20250101T090000\nRRULE:FREQ=DAILY;COUNT=3`
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
rule.toString();
|
|
119
|
+
// "DTSTART;TZID=UTC:20250101T090000\nRRULE:FREQ=DAILY;COUNT=3"
|
|
120
|
+
toText(rule); // uses the runtime locale, defaults to English
|
|
121
|
+
toText(rule, "es"); // Spanish description
|
|
122
|
+
toText(rule);
|
|
123
|
+
// "every day for 3 times"
|
|
124
|
+
|
|
125
|
+
const weekly = new RRuleTemporal({
|
|
126
|
+
freq: "WEEKLY",
|
|
127
|
+
byDay: ["SU"],
|
|
128
|
+
byHour: [10],
|
|
129
|
+
dtstart: Temporal.ZonedDateTime.from({
|
|
130
|
+
year: 2025, month: 1, day: 1, hour: 10, timeZone: "UTC"
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
toText(weekly);
|
|
135
|
+
// "every week on Sunday at 10 AM UTC"
|
|
136
|
+
toText(weekly, "es");
|
|
137
|
+
// "cada semana en domingo a las 10 AM UTC"
|
|
138
|
+
|
|
139
|
+
`toText()` currently ships translations for **English (`en`)**,
|
|
140
|
+
**Spanish (`es`)**, **Hindi (`hi`)**, **Cantonese (`yue`)**, **Arabic (`ar`)**,
|
|
141
|
+
**Hebrew (`he`)** and **Mandarin (`zh`)**. At build time you can reduce bundle size by
|
|
142
|
+
defining the `TOTEXT_LANGS` environment variable, e.g. `TOTEXT_LANGS=en,es,ar`.
|
|
143
|
+
|
|
144
|
+
### `toText` supported languages
|
|
145
|
+
|
|
146
|
+
| Code | Language |
|
|
147
|
+
| ---- | -------- |
|
|
148
|
+
| en | English |
|
|
149
|
+
| es | Spanish |
|
|
150
|
+
| hi | Hindi |
|
|
151
|
+
| yue | Cantonese |
|
|
152
|
+
| ar | Arabic |
|
|
153
|
+
| he | Hebrew |
|
|
154
|
+
| zh | Mandarin |
|
|
80
155
|
|
|
81
156
|
## API
|
|
82
157
|
|
|
@@ -88,7 +163,7 @@ toText(rule); // human readable description
|
|
|
88
163
|
| `next(after?, inclusive?)` | Next occurrence after a given date. |
|
|
89
164
|
| `previous(before?, inclusive?)` | Previous occurrence before a date. |
|
|
90
165
|
| `toString()` | Convert the rule back into `DTSTART` and `RRULE` lines. |
|
|
91
|
-
| `toText(rule, locale?)` |
|
|
166
|
+
| `toText(rule, locale?)` | Human readable description (`en`, `es`, `hi`, `yue`, `ar`, `he`, `zh`). |
|
|
92
167
|
| `options()` | Return the normalized options object. |
|
|
93
168
|
|
|
94
169
|
## Further examples
|
|
@@ -118,3 +193,30 @@ const ruleB = new RRuleTemporal({
|
|
|
118
193
|
});
|
|
119
194
|
ruleB.all().forEach(dt => console.log(dt.toString()));
|
|
120
195
|
```
|
|
196
|
+
|
|
197
|
+
### Working with extra and excluded dates
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
201
|
+
|
|
202
|
+
const start = Temporal.ZonedDateTime.from({
|
|
203
|
+
year: 2025, month: 1, day: 1, hour: 12, timeZone: "UTC"
|
|
204
|
+
});
|
|
205
|
+
const ruleC = new RRuleTemporal({
|
|
206
|
+
freq: "WEEKLY",
|
|
207
|
+
count: 5,
|
|
208
|
+
rDate: [start.add({ days: 1 })], // add one extra day
|
|
209
|
+
exDate: [start.add({ weeks: 2 })], // skip the third week
|
|
210
|
+
dtstart: start
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// First five occurrences (with rDate/exDate accounted for)
|
|
214
|
+
ruleC.all((_, i) => i < 5).forEach(dt => console.log(dt.toString()));
|
|
215
|
+
|
|
216
|
+
// Occurrences within a window
|
|
217
|
+
const hits = ruleC.between(
|
|
218
|
+
new Date("2025-01-01T00:00Z"),
|
|
219
|
+
new Date("2025-02-01T00:00Z"),
|
|
220
|
+
true
|
|
221
|
+
);
|
|
222
|
+
```
|