Compare commits

...

1 Commits

1 changed files with 22 additions and 4 deletions

View File

@ -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);
});