From ac26afe778384f89bccd49de36496a307938fc8e Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 19 Nov 2024 15:24:16 +0300 Subject: [PATCH] feat(calendars): reorder calendar components --- src/calendarUtil.js | 50 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/calendarUtil.js b/src/calendarUtil.js index b772bcd..4176065 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -30,9 +30,9 @@ export async function fetchCalendarData(calendar) { export function createCalendarComponent(name) { const calendarComponent = new ICAL.Component(['vcalendar', [], []]); calendarComponent.updatePropertyWithValue('name', name); + calendarComponent.updatePropertyWithValue('prodid', '-//CalMerge//Calendar Merger 1.0//EN'); calendarComponent.updatePropertyWithValue('version', '2.0'); calendarComponent.updatePropertyWithValue('calscale', 'GREGORIAN'); - calendarComponent.updatePropertyWithValue('prodid', '-//CalMerge//Calendar Merger 1.0//EN'); return calendarComponent; } @@ -56,7 +56,20 @@ export function addEventsToCalendar(calendarComponent, results, overrideFlag = f const vevent = new ICAL.Event(event); const newEvent = new ICAL.Component('vevent'); - // 1. DTEND with time zone + // 1. 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); + } + + // 2. DTEND with time zone if (vevent.endDate) { const endTime = vevent.endDate.toString(); // Format end date properly const dtendProp = new ICAL.Property('dtend', newEvent); @@ -69,24 +82,14 @@ export function addEventsToCalendar(calendarComponent, results, overrideFlag = f newEvent.addProperty(dtendProp); } - // 2. Copy DTSTAMP + // 3. Copy DTSTAMP const dtstamp = event.getFirstPropertyValue('dtstamp'); if (dtstamp) newEvent.updatePropertyWithValue('dtstamp', dtstamp); - // 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); - } + // 4. Copy UID + newEvent.updatePropertyWithValue('uid', vevent.uid); - // Add LOCATION (conditionally included) + // 5. Add LOCATION (conditionally included) if (!overrideFlag && vevent.location) { newEvent.updatePropertyWithValue('location', vevent.location); } else if (overrideFlag && vevent.location) { @@ -97,23 +100,20 @@ export function addEventsToCalendar(calendarComponent, results, overrideFlag = f newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); } - // 5. Copy Recurrence Rules (RRULE) and Recurrence ID + // 6. 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. Add SEQUENCE (if available or default to 0) - const sequence = event.getFirstPropertyValue('sequence') || 0; - newEvent.updatePropertyWithValue('sequence', sequence); - + // 7. Copy SUMMARY newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); - // 8. Copy UID - newEvent.updatePropertyWithValue('uid', vevent.uid); - + // 8. Add SEQUENCE (if available or default to 0) + const sequence = event.getFirstPropertyValue('sequence') || 0; + newEvent.updatePropertyWithValue('sequence', sequence); + // Add the VEVENT to the calendar calendarComponent.addSubcomponent(newEvent); });