Skip to content

Commit

Permalink
✨ Recurring events
Browse files Browse the repository at this point in the history
  • Loading branch information
davidruisinger authored Oct 19, 2022
1 parent 3f201d5 commit 2ce44b7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ ics(event); // standard ICS file based on https://icalendar.org

### Options

| Property | Description | Allowed values |
| ------------------ | --------------------------- | ------------------------------------------- |
| `title` (required) | Event title | String |
| `start` (required) | Start time | JS Date / ISO 8601 string / Unix Timestamp |
| `end` | End time | JS Date / ISO 8601 string / Unix Timestamp |
| `duration` | Event duration | Array with value (Number) and unit (String) |
| `allDay` | All day event | Boolean |
| `description` | Information about the event | String |
| `location` | Event location in words | String |
| `busy` | Mark on calendar as busy? | Boolean |
| `guests` | Emails of other guests | Array of emails (String) |
| `url` | Calendar document URL | String |
| Property | Description | Allowed values |
| ------------------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `title` (required) | Event title | String |
| `start` (required) | Start time | JS Date / ISO 8601 string / Unix Timestamp |
| `end` | End time | JS Date / ISO 8601 string / Unix Timestamp |
| `duration` | Event duration | Array with value (Number) and unit (String) |
| `allDay` | All day event | Boolean |
| `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` |
| `description` | Information about the event | String |
| `location` | Event location in words | String |
| `busy` | Mark on calendar as busy? | Boolean |
| `guests` | Emails of other guests | Array of emails (String) |
| `url` | Calendar document URL | String |

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

Expand Down
16 changes: 16 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ describe("Calendar Links", () => {
);
});

test("generate a recurring google link", () => {
const event: CalendarEvent = {
title: "Birthday party",
start: "2019-12-29",
duration: [2, "hour"],
rRule: "FREQ=YEARLY;INTERVAL=1"
};
const link = google(event);
const sTime = dayjs(event.start).utc().format(TimeFormats.dateTimeUTC);
const eTime = dayjs(event.start).add(2, "hour").utc().format(TimeFormats.dateTimeUTC);
const expectedDates = encodeURIComponent(`${sTime}/${eTime}`);
expect(link).toBe(
`https://calendar.google.com/calendar/render?action=TEMPLATE&dates=${expectedDates}&recur=FREQ%3DYEARLY%3BINTERVAL%3D1&text=Birthday%20party`
);
});

test("generate a google link with guests", () => {
const event: CalendarEvent = {
title: "Birthday party",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const google = (calendarEvent: CalendarEvent): string => {
location: event.location,
trp: event.busy,
dates: start + "/" + end,
recur: event.rRule,
};
if (event.guests && event.guests.length) {
details.add = event.guests.join();
Expand Down Expand Up @@ -144,6 +145,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
key: "DTEND",
value: end,
},
{
key: "RRULE",
value: event.rRule,
},
{
key: "SUMMARY",
value: event.title,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface CalendarEvent {
end?: any;
duration?: [number, dayjs.UnitType];
allDay?: boolean;
rRule?: string;
description?: string;
location?: string;
organizer?: CalendarEventOrganizer;
Expand Down

0 comments on commit 2ce44b7

Please sign in to comment.