rrule-temporal 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Recurrence rule processing using Temporal PlainDate/PlainDateTime",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
10
+ "import": "./dist/index.js",
11
11
  "require": "./dist/index.cjs"
12
12
  }
13
13
  },
@@ -33,7 +33,7 @@
33
33
  "bugs": {
34
34
  "url": "https://github.com/ggaabe/rrule-temporal/issues"
35
35
  },
36
- "homepage": "https://github.com/ggaabe/rrule-temporal#readme",
36
+ "homepage": "https://github.io/ggaabe/rrule-temporal",
37
37
  "files": [
38
38
  "dist"
39
39
  ],
@@ -1 +0,0 @@
1
- export {};
@@ -1,240 +0,0 @@
1
- import { RRuleTemporal } from "../index";
2
- import { Temporal } from "@js-temporal/polyfill";
3
- describe("RRuleTemporal - ICS snippet parsing", () => {
4
- const ics = `DTSTART;TZID=America/Chicago:20250320T170000
5
- RRULE:FREQ=DAILY;BYHOUR=17;BYMINUTE=0;COUNT=5`.trim();
6
- const rule = new RRuleTemporal({ rruleString: ics });
7
- test("toString reproduces original ICS (excluding COUNT position)", () => {
8
- const out = rule.toString();
9
- expect(out).toContain("DTSTART;TZID=America/Chicago:20250320T170000");
10
- expect(out).toContain("FREQ=DAILY");
11
- expect(out).toContain("BYHOUR=17");
12
- expect(out).toContain("BYMINUTE=0");
13
- expect(out).toContain("COUNT=5");
14
- });
15
- test("all() returns exactly count occurrences at 5pm CT each day", () => {
16
- const dates = rule.all();
17
- expect(dates).toHaveLength(5);
18
- for (let i = 0; i < dates.length; i++) {
19
- const dt = dates[i];
20
- if (!dt) {
21
- throw new Error("dt is undefined");
22
- }
23
- // 17:00 CT should be 22:00 UTC during CDT
24
- expect(dt.hour).toBe(17);
25
- expect(dt.minute).toBe(0);
26
- // consecutive days
27
- const next = dates[i + 1];
28
- if (next) {
29
- const diff = Temporal.Duration.compare(next.since(dt), Temporal.Duration.from({ days: 1 }));
30
- expect(diff).toBe(0);
31
- }
32
- }
33
- });
34
- });
35
- describe("RRuleTemporal - Manual options", () => {
36
- const dtstart = Temporal.ZonedDateTime.from({
37
- year: 2025,
38
- month: 4,
39
- day: 20,
40
- hour: 8,
41
- minute: 30,
42
- timeZone: "America/Chicago",
43
- });
44
- const rule = new RRuleTemporal({
45
- freq: "DAILY",
46
- interval: 2,
47
- count: 3,
48
- byHour: [9],
49
- byMinute: [15],
50
- dtstart,
51
- tzid: "America/Chicago",
52
- });
53
- test("all() respects manual interval and overrides time", () => {
54
- const dates = rule.all();
55
- expect(dates).toHaveLength(3);
56
- dates.forEach((d, idx) => {
57
- expect(d.hour).toBe(9);
58
- expect(d.minute).toBe(15);
59
- if (idx > 0) {
60
- const prev = dates[idx - 1];
61
- if (!prev) {
62
- throw new Error("prev is undefined");
63
- }
64
- const diffDays = Math.round(d.since(prev).total({ unit: "days" }));
65
- expect(diffDays).toBe(2);
66
- }
67
- });
68
- });
69
- });
70
- describe("RRuleTemporal - between()", () => {
71
- const ics = `DTSTART;TZID=America/Chicago:20250401T000000
72
- RRULE:FREQ=DAILY;BYHOUR=0;BYMINUTE=0;UNTIL=20250405T000000Z`.trim();
73
- const rule = new RRuleTemporal({ rruleString: ics });
74
- const start = new Date(Date.UTC(2025, 3, 2, 0, 0)); // Apr 2 00:00 UTC
75
- // after:
76
- const end = new Date(
77
- // 2025-04-04 00:00 America/Chicago → 05:00 UTC
78
- Date.UTC(2025, 3, 4, 5, 0, 0));
79
- test("between returns occurrences in window inclusive/exclusive", () => {
80
- const arrExc = rule.between(start, end, false);
81
- expect(arrExc.map((d) => d.day)).toEqual([2, 3]);
82
- const arrInc = rule.between(start, end, true);
83
- expect(arrInc.map((d) => d.day)).toEqual([2, 3, 4]);
84
- });
85
- });
86
- describe("RRuleTemporal - next() and previous()", () => {
87
- const ics = `DTSTART;TZID=UTC:20250101T120000
88
- RRULE:FREQ=MONTHLY;BYHOUR=12;BYMINUTE=0;COUNT=12`.trim();
89
- const rule = new RRuleTemporal({ rruleString: ics });
90
- test("next gives first upcoming after a date", () => {
91
- const after = new Date(Temporal.ZonedDateTime.from({
92
- year: 2025,
93
- month: 3,
94
- day: 15,
95
- hour: 0,
96
- minute: 0,
97
- timeZone: "UTC",
98
- }).toInstant().epochMilliseconds);
99
- const nxt = rule.next(after);
100
- expect(nxt).not.toBeNull();
101
- if (!nxt) {
102
- throw new Error("nxt is undefined");
103
- }
104
- expect(nxt.month).toBe(4); // April’s occurrence
105
- expect(nxt.hour).toBe(12);
106
- });
107
- test("previous gives last before a date", () => {
108
- const before = new Date(Temporal.ZonedDateTime.from({
109
- year: 2025,
110
- month: 6,
111
- day: 5,
112
- hour: 0,
113
- minute: 0,
114
- timeZone: "UTC",
115
- }).toInstant().epochMilliseconds);
116
- const prev = rule.previous(before);
117
- expect(prev).not.toBeNull();
118
- if (!prev) {
119
- throw new Error("prev is undefined");
120
- }
121
- expect(prev.month).toBe(6); // June’s occurrence (on or before)
122
- });
123
- });
124
- describe("RRuleTemporal - unbounded all() error", () => {
125
- const ics = `DTSTART;TZID=UTC:20250101T000000
126
- RRULE:FREQ=DAILY`.trim();
127
- const rule = new RRuleTemporal({ rruleString: ics });
128
- test("all() throws without iterator on unbounded", () => {
129
- expect(() => rule.all()).toThrow(/requires iterator/);
130
- });
131
- test("all() works with iterator limit", () => {
132
- const dates = rule.all((dt, i) => i < 3);
133
- expect(dates).toHaveLength(3);
134
- });
135
- });
136
- describe("RRuleTemporal - BYDAY frequencies", () => {
137
- const ics = `DTSTART;TZID=America/Chicago:20250325T000000
138
- RRULE:FREQ=MONTHLY;BYDAY=2FR,4FR;BYHOUR=0;BYMINUTE=0`.trim();
139
- const rule = new RRuleTemporal({ rruleString: ics });
140
- // 2025 Apr 22 00:00 UTC
141
- const start = new Date(Date.UTC(2025, 3, 20, 0, 0));
142
- // 2026 Apr 22 00:00 UTC
143
- const end = new Date(Date.UTC(2026, 3, 22, 0, 0, 0));
144
- test("between returns occurrences in window", () => {
145
- const arrInc = rule.between(start, end, true);
146
- console.log("arrInc: ", arrInc.map((d) => d.toString()));
147
- expect(arrInc.map((d) => d.day)).toEqual([
148
- 25, 9, 23, 13, 27, 11, 25, 8, 22, 12, 26, 10, 24, 14, 28, 12, 26, 9, 23,
149
- 13, 27, 13, 27, 10,
150
- ]);
151
- });
152
- });
153
- describe("RRuleTemporal - BYMONTH with MONTHLY freq (ICS snippet)", () => {
154
- const ics = `DTSTART;TZID=UTC:20250115T000000
155
- RRULE:FREQ=MONTHLY;BYMONTH=1,4,7;BYHOUR=0;BYMINUTE=0;COUNT=3`.trim();
156
- const rule = new RRuleTemporal({ rruleString: ics });
157
- test("all() returns exactly the 15th of Jan, Apr & Jul", () => {
158
- const dates = rule.all();
159
- expect(dates).toHaveLength(3);
160
- expect(dates.map((d) => d.month)).toEqual([1, 4, 7]);
161
- expect(dates.map((d) => d.day)).toEqual([15, 15, 15]);
162
- });
163
- });
164
- describe("RRuleTemporal - BYMONTH with YEARLY freq (manual opts)", () => {
165
- const dtstart = Temporal.ZonedDateTime.from({
166
- year: 2025,
167
- month: 1,
168
- day: 10,
169
- hour: 9,
170
- minute: 0,
171
- timeZone: "UTC",
172
- });
173
- const rule = new RRuleTemporal({
174
- freq: "YEARLY",
175
- interval: 1,
176
- count: 4,
177
- byMonth: [1, 6, 12],
178
- byHour: [9],
179
- byMinute: [0],
180
- dtstart,
181
- });
182
- test("all() emits Jan ’25, Jun ’26, Dec ’27, Jan ’28", () => {
183
- const dates = rule.all();
184
- expect(dates).toHaveLength(4);
185
- expect(dates.map((d) => ({ year: d.year, month: d.month }))).toEqual([
186
- { year: 2025, month: 1 },
187
- { year: 2026, month: 6 },
188
- { year: 2027, month: 12 },
189
- { year: 2028, month: 1 },
190
- ]);
191
- for (const d of dates) {
192
- expect(d.hour).toBe(9);
193
- expect(d.minute).toBe(0);
194
- }
195
- });
196
- });
197
- describe("RRuleTemporal - Weekly BYDAY simple all()", () => {
198
- const ics = `DTSTART;TZID=America/Chicago:20250406T000000
199
- RRULE:FREQ=WEEKLY;BYDAY=MO;BYHOUR=0;BYMINUTE=0;COUNT=4`.trim();
200
- const rule = new RRuleTemporal({ rruleString: ics });
201
- test("all() returns 4 consecutive Mondays", () => {
202
- const dates = rule.all();
203
- // dayOfWeek 1 == Monday
204
- expect(dates).toHaveLength(4);
205
- expect(dates.map((d) => d.day)).toEqual([7, 14, 21, 28]);
206
- dates.forEach((d) => expect(d.dayOfWeek).toBe(1));
207
- });
208
- });
209
- describe("RRuleTemporal - Weekly BYDAY simple between()", () => {
210
- const ics = `DTSTART;TZID=America/Chicago:20250325T000000
211
- RRULE:FREQ=WEEKLY;BYDAY=MO;BYHOUR=0;BYMINUTE=0`.trim();
212
- const rule = new RRuleTemporal({ rruleString: ics });
213
- // Window: April 22 2025 UTC → May 20 2025 UTC
214
- const start = new Date(Date.UTC(2025, 3, 22, 0, 0)); // April is month=3
215
- const end = new Date(Date.UTC(2025, 4, 20, 0, 0)); // May is month=4
216
- test("between() returns the Mondays falling in that window", () => {
217
- const arrInc = rule.between(start, end, true);
218
- // Expect 2025-04-28, 05-05, 05-12, 05-19
219
- expect(arrInc.map((d) => d.day)).toEqual([28, 5, 12, 19]);
220
- arrInc.forEach((d) => expect(d.dayOfWeek).toBe(1));
221
- });
222
- });
223
- describe("RRuleTemporal - Weekly BYDAY frequencies without positional prefix", () => {
224
- const ics = `DTSTART;TZID=America/Chicago:20250325T000000
225
- RRULE:FREQ=WEEKLY;BYDAY=MO;BYHOUR=0;BYMINUTE=0`.trim();
226
- const rule = new RRuleTemporal({ rruleString: ics });
227
- // 2025 Apr 22 00:00 UTC
228
- const start = new Date(Date.UTC(2025, 3, 22, 0, 0));
229
- // 2026 Apr 22 00:00 UTC
230
- const end = new Date(Date.UTC(2026, 3, 22, 0, 0, 0));
231
- test("between returns occurrences in window", () => {
232
- const arrInc = rule.between(start, end, true);
233
- console.log("arrInc: ", arrInc.map((d) => d.toString()));
234
- expect(arrInc.map((d) => d.day)).toEqual([
235
- 28, 5, 12, 19, 26, 2, 9, 16, 23, 30, 7, 14, 21, 28, 4, 11, 18, 25, 1, 8,
236
- 15, 22, 29, 6, 13, 20, 27, 3, 10, 17, 24, 1, 8, 15, 22, 29, 5, 12, 19, 26,
237
- 2, 9, 16, 23, 2, 9, 16, 23, 30, 6, 13, 20,
238
- ]);
239
- });
240
- });