Skip to content

Commit

Permalink
Merge pull request #2979 from nxdefiant/master
Browse files Browse the repository at this point in the history
sched/calendar: Interface ical fixes
  • Loading branch information
gfwilliams authored Aug 29, 2023
2 parents 6607973 + 2d7fdd8 commit 4adb594
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions apps/calendar/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
for(let i=0; i<input.files.length; i++) {
const reader = new FileReader();
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 vtz = comp.getFirstSubcomponent('vtimezone');
const tz = new ICAL.Timezone(vtz);

// Fetch the VEVENT part
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

const holiday = eventToHoliday(event);
Expand Down
11 changes: 8 additions & 3 deletions apps/sched/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
for(let i=0; i<input.files.length; i++) {
const reader = new FileReader();
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 vtz = comp.getFirstSubcomponent('vtimezone');
const tz = new ICAL.Timezone(vtz);

// Fetch the VEVENT part
comp.getAllSubcomponents('vevent').forEach(vevent => {
event = new ICAL.Event(vevent);
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);

if (exists) {
Expand Down Expand Up @@ -68,7 +72,8 @@
};
}

function eventToAlarm(event, offsetMs) {
function eventToAlarm(event, tz, offsetMs) {
event.startDate.zone = tz;
const dateOrig = event.startDate.toJSDate();
const date = offsetMs ? new Date(dateOrig - offsetMs) : dateOrig;

Expand Down

0 comments on commit 4adb594

Please sign in to comment.