1
0
Fork 0

fix(calendar): align VEVENT property order and include time zone details

This commit is contained in:
Ryan Mwangi 2024-11-19 01:29:32 +03:00
parent 6cf5b8420e
commit 2b7002303c
1 changed files with 35 additions and 9 deletions

View File

@ -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);
// Copy DTSTAMP
// Add TZID parameter if zone is present
if (vevent.endDate.zone) {
dtendProp.setParameter('TZID', vevent.endDate.zone.tzid);
}
newEvent.addProperty(dtendProp);
}
// 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);
// Copy DTSTART and DTEND
newEvent.updatePropertyWithValue('dtstart', vevent.startDate);
newEvent.updatePropertyWithValue('dtend', vevent.endDate);
// Add TZID parameter if zone is present
if (vevent.startDate.zone) {
dtstartProp.setParameter('TZID', vevent.startDate.zone.tzid);
}
newEvent.addProperty(dtstartProp);
}
// Copy Recurrence Rules (RRULE) and Recurrence ID
// 4. location
const location = vevent.location;
if (location) newEvent.updatePropertyWithValue('location', location);
// 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);
});