-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathexample-rrule-basic.js
More file actions
35 lines (29 loc) · 1.18 KB
/
example-rrule-basic.js
File metadata and controls
35 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Example: Expanding a simple recurring event (native Date only)
*
* This minimal script shows how to read an .ics file, expand a single
* RRULE within a fixed window, and print the resulting instances.
*/
const path = require('node:path');
const ical = require('../node-ical.js');
// Load the basic example calendar that contains one recurring event.
const data = ical.parseFile(path.join(__dirname, 'example-rrule-basic.ics'));
// Pull out the first VEVENT.
const event = Object.values(data).find(item => item.type === 'VEVENT');
if (!event) {
throw new Error('No VEVENT found in example-rrule-basic.ics');
}
// Choose a window that definitely includes all generated instances.
const rangeStart = new Date('2024-01-01T00:00:00.000Z');
const rangeEnd = new Date('2024-01-31T23:59:59.999Z');
// Use expandRecurringEvent to handle RRULE expansion, EXDATE filtering, and RECURRENCE-ID overrides
const instances = ical.expandRecurringEvent(event, {
from: rangeStart,
to: rangeEnd,
});
for (const instance of instances) {
console.log(`summary:${instance.summary}`);
console.log(`start:${instance.start.toISOString()}`);
console.log(`end:${instance.end.toISOString()}`);
console.log();
}