From 2d7fdd88c2575915dd95f080d1f211cfa9b2e1af Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 18 Aug 2023 20:40:24 +0200 Subject: [PATCH] sched/calendar: Fix timezone handling on ical --- apps/calendar/interface.html | 9 +++++++-- apps/sched/interface.html | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/calendar/interface.html b/apps/calendar/interface.html index 280a96c0ba..ea64632f86 100644 --- a/apps/calendar/interface.html +++ b/apps/calendar/interface.html @@ -28,11 +28,16 @@ for(let i=0; i { - const jCalData = ICAL.parse(reader.result); + const icalText = reader.result.substring(reader.result.indexOf("BEGIN:VCALENDAR")); // remove html before data + const jCalData = ICAL.parse(icalText); const comp = new ICAL.Component(jCalData); + const vtz = comp.getFirstSubcomponent('vtimezone'); + const tz = new ICAL.Timezone(vtz); + // Fetch the VEVENT part comp.getAllSubcomponents('vevent').forEach(vevent => { - event = new ICAL.Event(vevent); + const event = new ICAL.Event(vevent); + event.startDate.zone = tz; holidays = holidays.filter(holiday => !sameDay(new Date(holiday.date), event.startDate.toJSDate())); // remove if already exists const holiday = eventToHoliday(event); diff --git a/apps/sched/interface.html b/apps/sched/interface.html index cd2c9c5954..53b4433715 100644 --- a/apps/sched/interface.html +++ b/apps/sched/interface.html @@ -16,14 +16,18 @@ for(let i=0; i { - const jCalData = ICAL.parse(reader.result); + const icalText = reader.result.substring(reader.result.indexOf("BEGIN:VCALENDAR")); // remove html before data + const jCalData = ICAL.parse(icalText); const comp = new ICAL.Component(jCalData); + const vtz = comp.getFirstSubcomponent('vtimezone'); + const tz = new ICAL.Timezone(vtz); + // Fetch the VEVENT part comp.getAllSubcomponents('vevent').forEach(vevent => { event = new ICAL.Event(vevent); const exists = alarms.some(alarm => alarm.id === event.uid); - const alarm = eventToAlarm(event, offsetMinutes*60*1000); + const alarm = eventToAlarm(event, tz, offsetMinutes*60*1000); renderAlarm(alarm, exists); if (exists) { @@ -68,7 +72,8 @@ }; } -function eventToAlarm(event, offsetMs) { +function eventToAlarm(event, tz, offsetMs) { + event.startDate.zone = tz; const dateOrig = event.startDate.toJSDate(); const date = offsetMs ? new Date(dateOrig - offsetMs) : dateOrig;