Skip to content

Commit

Permalink
Correctly handle timezones in ical
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanarora authored and johannesjo committed Mar 26, 2023
1 parent 899ac12 commit 4082d48
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/features/timeline/ical/get-relevant-events-from-ical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ const convertVEventToTimelineEvent = (vevent: any): TimelineFromCalendarEvent =>
const getAllPossibleFutureEventsFromIcal = (icalData: string, now: Date): any[] => {
const c = ICAL.parse(icalData);
const comp = new ICAL.Component(c);
const vevents = comp.getAllSubcomponents('vevent');
const tzAdded = [];
if (comp.getFirstSubcomponent('vtimezone')) {
for (const vtz of comp.getAllSubcomponents('vtimezone')) {
const tz = new ICAL.Timezone({
tzid: vtz.getFirstPropertyValue('tzid'),
component: vtz,
});

if (!ICAL.TimezoneService.has(tz.tzid)) {
ICAL.TimezoneService.register(tz.tzid, tz);
tzAdded.push(tz.tzid);
}
}
}
const vevents = ICAL.helpers.updateTimezones(comp).getAllSubcomponents('vevent');

const allPossibleFutureEvents = vevents.filter(
(ve: any) =>
Expand All @@ -97,5 +111,9 @@ const getAllPossibleFutureEventsFromIcal = (icalData: string, now: Date): any[]
ve.getFirstPropertyValue('rrule')?.until?.toJSDate() > now)),
);

for (const tzid of tzAdded) {
ICAL.TimezoneService.remove(tzid);
}

return allPossibleFutureEvents;
};

0 comments on commit 4082d48

Please sign in to comment.