Skip to content

Commit 2ce44b7

Browse files
✨ Recurring events
1 parent 3f201d5 commit 2ce44b7

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ ics(event); // standard ICS file based on https://icalendar.org
4040

4141
### Options
4242

43-
| Property | Description | Allowed values |
44-
| ------------------ | --------------------------- | ------------------------------------------- |
45-
| `title` (required) | Event title | String |
46-
| `start` (required) | Start time | JS Date / ISO 8601 string / Unix Timestamp |
47-
| `end` | End time | JS Date / ISO 8601 string / Unix Timestamp |
48-
| `duration` | Event duration | Array with value (Number) and unit (String) |
49-
| `allDay` | All day event | Boolean |
50-
| `description` | Information about the event | String |
51-
| `location` | Event location in words | String |
52-
| `busy` | Mark on calendar as busy? | Boolean |
53-
| `guests` | Emails of other guests | Array of emails (String) |
54-
| `url` | Calendar document URL | String |
43+
| Property | Description | Allowed values |
44+
| ------------------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
45+
| `title` (required) | Event title | String |
46+
| `start` (required) | Start time | JS Date / ISO 8601 string / Unix Timestamp |
47+
| `end` | End time | JS Date / ISO 8601 string / Unix Timestamp |
48+
| `duration` | Event duration | Array with value (Number) and unit (String) |
49+
| `allDay` | All day event | Boolean |
50+
| `rRule` | Recurring event | iCal [recurrence rule](https://www.rfc-editor.org/rfc/rfc5545#section-3.3.10) string <br />**NOTE:** Only supported by `google` and `ics` |
51+
| `description` | Information about the event | String |
52+
| `location` | Event location in words | String |
53+
| `busy` | Mark on calendar as busy? | Boolean |
54+
| `guests` | Emails of other guests | Array of emails (String) |
55+
| `url` | Calendar document URL | String |
5556

5657
Any one of the fields `end`, `duration`, or `allDay` is required.
5758

src/index.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ describe("Calendar Links", () => {
6767
);
6868
});
6969

70+
test("generate a recurring google link", () => {
71+
const event: CalendarEvent = {
72+
title: "Birthday party",
73+
start: "2019-12-29",
74+
duration: [2, "hour"],
75+
rRule: "FREQ=YEARLY;INTERVAL=1"
76+
};
77+
const link = google(event);
78+
const sTime = dayjs(event.start).utc().format(TimeFormats.dateTimeUTC);
79+
const eTime = dayjs(event.start).add(2, "hour").utc().format(TimeFormats.dateTimeUTC);
80+
const expectedDates = encodeURIComponent(`${sTime}/${eTime}`);
81+
expect(link).toBe(
82+
`https://calendar.google.com/calendar/render?action=TEMPLATE&dates=${expectedDates}&recur=FREQ%3DYEARLY%3BINTERVAL%3D1&text=Birthday%20party`
83+
);
84+
});
85+
7086
test("generate a google link with guests", () => {
7187
const event: CalendarEvent = {
7288
title: "Birthday party",

src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const google = (calendarEvent: CalendarEvent): string => {
4848
location: event.location,
4949
trp: event.busy,
5050
dates: start + "/" + end,
51+
recur: event.rRule,
5152
};
5253
if (event.guests && event.guests.length) {
5354
details.add = event.guests.join();
@@ -144,6 +145,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
144145
key: "DTEND",
145146
value: end,
146147
},
148+
{
149+
key: "RRULE",
150+
value: event.rRule,
151+
},
147152
{
148153
key: "SUMMARY",
149154
value: event.title,

src/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface CalendarEvent {
66
end?: any;
77
duration?: [number, dayjs.UnitType];
88
allDay?: boolean;
9+
rRule?: string;
910
description?: string;
1011
location?: string;
1112
organizer?: CalendarEventOrganizer;

0 commit comments

Comments
 (0)