From 3437d9bfa9a2778e5b013cca98b2c3af4f800151 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 12 Nov 2024 15:15:40 +0300 Subject: [PATCH] fix(in-progress): maintain original timezone and not convert time to local timezone --- src/calendarUtil.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/calendarUtil.js b/src/calendarUtil.js index 677f4b2..16a52c4 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -34,6 +34,12 @@ export function createCalendarComponent(name) { calendarComponent.updatePropertyWithValue('name', name); return calendarComponent; } +// Add timezone information +export function addTimezoneComponent(calendarComponent, timezoneId) { + const timezoneComponent = new ICAL.Component('vtimezone'); + timezoneComponent.updatePropertyWithValue('tzid', timezoneId); + calendarComponent.addSubcomponent(timezoneComponent); +} // Add events to the calendar component export function addEventsToCalendar(calendarComponent, results) { @@ -45,13 +51,25 @@ export function addEventsToCalendar(calendarComponent, results) { const vevent = new ICAL.Event(event); const newEvent = new ICAL.Component('vevent'); - const startDate = vevent.startDate && ICAL.Time.fromJSDate(vevent.startDate.toJSDate()); - const endDate = vevent.endDate && ICAL.Time.fromJSDate(vevent.endDate.toJSDate()); + // Define start and end times using original timezone info + const startDate = vevent.startDate; // Keep the original startDate with timezone + const endDate = vevent.endDate; // Keep the original endDate with timezone + // Specify time zone ID for DTSTART and DTEND + const startProp = new ICAL.Property('dtstart'); + startProp.setValue(startDate); // Use the original startDate directly + startProp.setParameter('tzid', startDate.zone.tzid); // Set the timezone ID + + const endProp = new ICAL.Property('dtend'); + endProp.setValue(endDate); // Use the original endDate directly + endProp.setParameter('tzid', endDate.zone.tzid); // Set the timezone ID + + // Set properties for newEvent + newEvent.addProperty(startProp); + newEvent.addProperty(endProp); newEvent.updatePropertyWithValue('uid', vevent.uid); newEvent.updatePropertyWithValue('summary', `${result.prefix} ${vevent.summary}`); - newEvent.updatePropertyWithValue('dtstart', startDate); - newEvent.updatePropertyWithValue('dtend', endDate); + calendarComponent.addSubcomponent(newEvent); });