fix: get DTSTAMP to get parsed correctly and remain the same as the original
This commit is contained in:
parent
e8582cd411
commit
0114c94caa
|
@ -43,8 +43,6 @@ export function addEventsToCalendar(calendarComponent, results) {
|
||||||
|
|
||||||
component.getAllSubcomponents('vevent').forEach((event) => {
|
component.getAllSubcomponents('vevent').forEach((event) => {
|
||||||
const vevent = new ICAL.Event(event);
|
const vevent = new ICAL.Event(event);
|
||||||
console.log('Original event properties:', event.getAllProperties());
|
|
||||||
console.log('Original vevent properties:', vevent);
|
|
||||||
const newEvent = new ICAL.Component('vevent');
|
const newEvent = new ICAL.Component('vevent');
|
||||||
|
|
||||||
// Use ICAL.Time to handle dates correctly
|
// Use ICAL.Time to handle dates correctly
|
||||||
|
@ -65,22 +63,25 @@ export function addEventsToCalendar(calendarComponent, results) {
|
||||||
endTime.isDate = true; // Set as all-day event
|
endTime.isDate = true; // Set as all-day event
|
||||||
|
|
||||||
// Retain the existing DTSTAMP from vevent
|
// Retain the existing DTSTAMP from vevent
|
||||||
const dtstampProperty = event.getFirstProperty('dtstamp'); // Get DTSTAMP from the original event
|
const dtstampProperty = event.getFirstProperty('dtstamp');
|
||||||
const dtstamp = dtstampProperty ? dtstampProperty.value : null; // Safely get the value
|
const dtstamp = dtstampProperty ? dtstampProperty.getFirstValue() : null;
|
||||||
|
|
||||||
|
// Add properties to the new event
|
||||||
newEvent.updatePropertyWithValue('uid', vevent.uid);
|
newEvent.updatePropertyWithValue('uid', vevent.uid);
|
||||||
newEvent.updatePropertyWithValue('summary', vevent.summary.trim());
|
|
||||||
if (dtstamp) {
|
if (dtstamp) {
|
||||||
newEvent.updatePropertyWithValue('dtstamp', dtstamp); // Retain the existing DTSTAMP
|
newEvent.updatePropertyWithValue('dtstamp', dtstamp); // Retain the existing DTSTAMP
|
||||||
|
} else {
|
||||||
|
console.warn('DTSTAMP not found in the original event.'); // Warn if DTSTAMP is missing
|
||||||
}
|
}
|
||||||
|
newEvent.updatePropertyWithValue('summary', vevent.summary.trim()); // Set SUMMARY without leading spaces
|
||||||
|
|
||||||
// Set the dtstart and dtend properties using ICAL.Time
|
// Set the dtstart and dtend properties using ICAL.Time
|
||||||
newEvent.updatePropertyWithValue('dtstart', startTime);
|
newEvent.updatePropertyWithValue('dtstart', startTime);
|
||||||
newEvent.updatePropertyWithValue('dtend', endTime);
|
newEvent.updatePropertyWithValue('dtend', endTime);
|
||||||
|
|
||||||
|
|
||||||
// Add the new event to the calendar component
|
// Add the new event to the calendar component
|
||||||
calendarComponent.addSubcomponent(newEvent);
|
calendarComponent.addSubcomponent(newEvent);
|
||||||
console.log('New event properties:', newEvent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log the added events for debugging
|
// Log the added events for debugging
|
||||||
|
|
Loading…
Reference in New Issue