sched/calendar: Fix timezone handling on ical

pull/2979/head
Erik Andresen 2023-08-18 20:40:24 +02:00
parent 918be9e7bb
commit 2d7fdd88c2
2 changed files with 15 additions and 5 deletions

View File

@ -28,11 +28,16 @@ function readFile(input) {
for(let i=0; i<input.files.length; i++) { for(let i=0; i<input.files.length; i++) {
const reader = new FileReader(); const reader = new FileReader();
reader.addEventListener("load", () => { reader.addEventListener("load", () => {
const jCalData = ICAL.parse(reader.result); const icalText = reader.result.substring(reader.result.indexOf("BEGIN:VCALENDAR")); // remove html before data
const jCalData = ICAL.parse(icalText);
const comp = new ICAL.Component(jCalData); const comp = new ICAL.Component(jCalData);
const vtz = comp.getFirstSubcomponent('vtimezone');
const tz = new ICAL.Timezone(vtz);
// Fetch the VEVENT part // Fetch the VEVENT part
comp.getAllSubcomponents('vevent').forEach(vevent => { comp.getAllSubcomponents('vevent').forEach(vevent => {
event = new ICAL.Event(vevent); const event = new ICAL.Event(vevent);
event.startDate.zone = tz;
holidays = holidays.filter(holiday => !sameDay(new Date(holiday.date), event.startDate.toJSDate())); // remove if already exists holidays = holidays.filter(holiday => !sameDay(new Date(holiday.date), event.startDate.toJSDate())); // remove if already exists
const holiday = eventToHoliday(event); const holiday = eventToHoliday(event);

View File

@ -16,14 +16,18 @@ function readFile(input) {
for(let i=0; i<input.files.length; i++) { for(let i=0; i<input.files.length; i++) {
const reader = new FileReader(); const reader = new FileReader();
reader.addEventListener("load", () => { reader.addEventListener("load", () => {
const jCalData = ICAL.parse(reader.result); const icalText = reader.result.substring(reader.result.indexOf("BEGIN:VCALENDAR")); // remove html before data
const jCalData = ICAL.parse(icalText);
const comp = new ICAL.Component(jCalData); const comp = new ICAL.Component(jCalData);
const vtz = comp.getFirstSubcomponent('vtimezone');
const tz = new ICAL.Timezone(vtz);
// Fetch the VEVENT part // Fetch the VEVENT part
comp.getAllSubcomponents('vevent').forEach(vevent => { comp.getAllSubcomponents('vevent').forEach(vevent => {
event = new ICAL.Event(vevent); event = new ICAL.Event(vevent);
const exists = alarms.some(alarm => alarm.id === event.uid); const exists = alarms.some(alarm => alarm.id === event.uid);
const alarm = eventToAlarm(event, offsetMinutes*60*1000); const alarm = eventToAlarm(event, tz, offsetMinutes*60*1000);
renderAlarm(alarm, exists); renderAlarm(alarm, exists);
if (exists) { if (exists) {
@ -68,7 +72,8 @@ function getAlarmDefaults() {
}; };
} }
function eventToAlarm(event, offsetMs) { function eventToAlarm(event, tz, offsetMs) {
event.startDate.zone = tz;
const dateOrig = event.startDate.toJSDate(); const dateOrig = event.startDate.toJSDate();
const date = offsetMs ? new Date(dateOrig - offsetMs) : dateOrig; const date = offsetMs ? new Date(dateOrig - offsetMs) : dateOrig;