From 2b7002303c5ae4835a2489f387a93503ae08333e Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 19 Nov 2024 01:29:32 +0300 Subject: [PATCH] fix(calendar): align VEVENT property order and include time zone details --- src/calendarUtil.js | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/calendarUtil.js b/src/calendarUtil.js index fad6f5a..b684917 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -54,27 +54,53 @@ export function addEventsToCalendar(calendarComponent, results) { const vevent = new ICAL.Event(event); const newEvent = new ICAL.Component('vevent'); - // Copy UID - newEvent.updatePropertyWithValue('uid', vevent.uid); + // 1. DTEND with time zone + if (vevent.endDate) { + const endTime = vevent.endDate.toString(); // Format end date properly + const dtendProp = new ICAL.Property('dtend', newEvent); + dtendProp.setValue(endTime); + + // Add TZID parameter if zone is present + if (vevent.endDate.zone) { + dtendProp.setParameter('TZID', vevent.endDate.zone.tzid); + } + newEvent.addProperty(dtendProp); + } - // Copy DTSTAMP + // 2. Copy DTSTAMP const dtstamp = event.getFirstPropertyValue('dtstamp'); if (dtstamp) newEvent.updatePropertyWithValue('dtstamp', dtstamp); - // Copy SUMMARY - newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); + // 3. DTSTART with time zone + if (vevent.startDate) { + const startTime = vevent.startDate.toString(); // Format start date properly + const dtstartProp = new ICAL.Property('dtstart', newEvent); + dtstartProp.setValue(startTime); + + // Add TZID parameter if zone is present + if (vevent.startDate.zone) { + dtstartProp.setParameter('TZID', vevent.startDate.zone.tzid); + } + newEvent.addProperty(dtstartProp); + } - // Copy DTSTART and DTEND - newEvent.updatePropertyWithValue('dtstart', vevent.startDate); - newEvent.updatePropertyWithValue('dtend', vevent.endDate); + // 4. location + const location = vevent.location; + if (location) newEvent.updatePropertyWithValue('location', location); - // Copy Recurrence Rules (RRULE) and Recurrence ID + // 5. Copy Recurrence Rules (RRULE) and Recurrence ID const rrule = event.getFirstPropertyValue('rrule'); if (rrule) newEvent.updatePropertyWithValue('rrule', rrule); const recurrenceId = event.getFirstPropertyValue('recurrence-id'); if (recurrenceId) newEvent.updatePropertyWithValue('recurrence-id', recurrenceId); + // 6. Copy SUMMARY + newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); + + // 7. Copy UID + newEvent.updatePropertyWithValue('uid', vevent.uid); + // Add the VEVENT to the calendar calendarComponent.addSubcomponent(newEvent); });