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 vevent = new ICAL.Event(event);
const newEvent = new ICAL.Component('vevent'); const newEvent = new ICAL.Component('vevent');
// Copy UID // 1. DTEND with time zone
newEvent.updatePropertyWithValue('uid', vevent.uid); 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'); const dtstamp = event.getFirstPropertyValue('dtstamp');
if (dtstamp) newEvent.updatePropertyWithValue('dtstamp', dtstamp); if (dtstamp) newEvent.updatePropertyWithValue('dtstamp', dtstamp);
// Copy SUMMARY // 3. DTSTART with time zone
newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); 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 // 4. location
newEvent.updatePropertyWithValue('dtstart', vevent.startDate); const location = vevent.location;
newEvent.updatePropertyWithValue('dtend', vevent.endDate); 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'); const rrule = event.getFirstPropertyValue('rrule');
if (rrule) newEvent.updatePropertyWithValue('rrule', rrule); if (rrule) newEvent.updatePropertyWithValue('rrule', rrule);
const recurrenceId = event.getFirstPropertyValue('recurrence-id'); const recurrenceId = event.getFirstPropertyValue('recurrence-id');
if (recurrenceId) newEvent.updatePropertyWithValue('recurrence-id', recurrenceId); 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 // Add the VEVENT to the calendar
calendarComponent.addSubcomponent(newEvent); calendarComponent.addSubcomponent(newEvent);
}); });