Skip to content

Commit

Permalink
Add support for ics.acmcsuf.com
Browse files Browse the repository at this point in the history
This commit adds support for parsing ICS calendars using the ICal
standard format in addition to the existing Google Calendar API.

The new commit also contains a hard-coded array of ICS calendar links,
currently only containing ics.acmcsuf.com. In the future, more links may
be added to this.

A hard-coded array was chosen over an environment variable because
environment variables cannot express arrays as easily. That said, if
there are any private calendars, then they can be used as such:

    const KnownCalendars = [
      "public1.ics",
      "public2.ics",
      SECRET_ICS_X,
      SECRET_ICS_Y,
    ]

In the future, if ics.acmcsuf.com is proven to work well enough, the
Google Calendar API could even be completely phased out.

NOTE: It is worth pointing out that this ICS code currently *does not
support recurring events*. This is because ics.acmcsuf.com doesn't do
recurring events.
  • Loading branch information
diamondburned committed Sep 18, 2023
1 parent 1055182 commit 0b6c8ab
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 16 deletions.
221 changes: 221 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@js-temporal/polyfill": "^0.4.4",
"cropperjs": "^1.5.13",
"html-to-text": "^9.0.5",
"node-ical": "^0.16.1",
"pomo": "github:ethanthatonekid/pomo#npm",
"qrcode": "^1.5.3",
"rrule": "^2.7.2",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/server/events/data/known-ics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const knownICS = ['https://ics.acmcsuf.com/guilds/710225099923521558/events.ics'];
export default knownICS;
2 changes: 1 addition & 1 deletion src/lib/server/events/gcal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CLUB_EVENTS from './data/club-events.json?raw';

test('transforms GCalEvent list to ClubEvent list', async () => {
const input = JSON.parse(GCAL_EVENTS) as GCalEvent[];
const actual = fromGCal(input);
const actual = fromGCal(input, 'America/Los_Angeles');

// To generate 'src/lib/server/events/data/club-events.json', uncomment the
// following lines of code then run 'npm t' (and 'npm run all'):
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/events/gcal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { calendar } from '@googleapis/calendar';
import { makeClubEvent } from './event';
import { GCAL_API_KEY, GCAL_ID } from '$lib/server/env';

export function fromGCal(events: GCalEvent[]): ClubEvent[] {
export function fromGCal(events: GCalEvent[], timezone: string): ClubEvent[] {
const sortedEvents: ClubEvent[] = [];
const refDate = Temporal.Now.zonedDateTimeISO('America/Los_Angeles');
const refDate = Temporal.Now.zonedDateTimeISO(timezone);

for (const event of events) {
const clubEvent = makeClubEvent(event, refDate);
Expand Down
Loading

0 comments on commit 0b6c8ab

Please sign in to comment.