From a1fc38c5fe66043055e2cb4fb23707a47d05af45 Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Sun, 22 Aug 2021 13:57:24 +0200 Subject: [PATCH 1/6] Prettified and added debug messages. --- modules/default/calendar/calendarutils.js | 52 +++++++++++++++-------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 7f0b14b8..041c3882 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -138,13 +138,14 @@ const CalendarUtils = { return CalendarUtils.isFullDayEvent(event) ? moment(event[time], "YYYYMMDD") : moment(new Date(event[time])); }; - Log.debug("there are " + Object.entries(data).length + " calendar entries"); + Log.debug("There are " + Object.entries(data).length + " calendar entries."); Object.entries(data).forEach(([key, event]) => { + Log.debug("Processing entry..."); const now = new Date(); const today = moment().startOf("day").toDate(); const future = moment().startOf("day").add(config.maximumNumberOfDays, "days").subtract(1, "seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat. let past = today; - Log.debug("have entries "); + if (config.includePastEvents) { past = moment().startOf("day").subtract(config.maximumNumberOfDays, "days").toDate(); } @@ -159,10 +160,10 @@ const CalendarUtils = { } if (event.type === "VEVENT") { + Log.debug("\nEvent: " + JSON.stringify(event)); let startDate = eventDate(event, "start"); let endDate; - Log.debug("\nevent=" + JSON.stringify(event)); if (typeof event.end !== "undefined") { endDate = eventDate(event, "end"); } else if (typeof event.duration !== "undefined") { @@ -176,16 +177,21 @@ const CalendarUtils = { } } - Log.debug(" start=" + startDate.toDate() + " end=" + endDate.toDate()); + Log.debug("startDate (local): " + startDate.toDate()); + Log.debug("endDate (local): " + endDate.toDate()); - // calculate the duration of the event for use with recurring events. + // Calculate the duration of the event for use with recurring events. let duration = parseInt(endDate.format("x")) - parseInt(startDate.format("x")); + Log.debug("duration: " + duration); + // FIXME: Since the parsed json object from node-ical comes with time information + // this check could be removed (?) if (event.start.length === 8) { startDate = startDate.startOf("day"); } const title = CalendarUtils.getTitleFromEvent(event); + Log.debug("title: " + title); let excluded = false, dateFilter = null; @@ -260,9 +266,13 @@ const CalendarUtils = { let pastLocal = 0; let futureLocal = 0; if (CalendarUtils.isFullDayEvent(event)) { + Log.debug("fullday"); // if full day event, only use the date part of the ranges pastLocal = pastMoment.toDate(); futureLocal = futureMoment.toDate(); + + Log.debug("pastLocal: " + pastLocal); + Log.debug("futureLocal: " + futureLocal); } else { // if we want past events if (config.includePastEvents) { @@ -274,9 +284,9 @@ const CalendarUtils = { } futureLocal = futureMoment.toDate(); // future } - Log.debug(" between=" + pastLocal + " to " + futureLocal); + Log.debug("Search for recurring events between: " + pastLocal + " and " + futureLocal); const dates = rule.between(pastLocal, futureLocal, true, limitFunction); - Log.debug("title=" + event.summary + " dates=" + JSON.stringify(dates)); + Log.debug("Title: " + event.summary + ", with dates: " + JSON.stringify(dates)); // The "dates" array contains the set of dates within our desired date range range that are valid // for the recurrence rule. *However*, it's possible for us to have a specific recurrence that // had its date changed from outside the range to inside the range. For the time being, @@ -284,6 +294,7 @@ const CalendarUtils = { // because the logic below will filter out any recurrences that don't actually belong within // our display range. // Would be great if there was a better way to handle this. + Log.debug("event.recurrences: " + event.recurrences); if (event.recurrences !== undefined) { for (let r in event.recurrences) { // Only add dates that weren't already in the range we added from the rrule so that @@ -296,6 +307,7 @@ const CalendarUtils = { // Loop through the set of date entries to see which recurrences should be added to our event list. for (let d in dates) { let date = dates[d]; + // FIXME: We now use node-ical instead of ical.js, but method stays the same. // ical.js started returning recurrences and exdates as ISOStrings without time information. // .toISOString().substring(0,10) is the method they use to calculate keys, so we'll do the same // (see https://github.com/peterbraden/ical.js/pull/84 ) @@ -303,21 +315,24 @@ const CalendarUtils = { let curEvent = event; let showRecurrence = true; - // get the offset of today where we are processing - // this will be the correction we need to apply + // Get the offset of today where we are processing + // This will be the correction, we need to apply. let nowOffset = new Date().getTimezoneOffset(); - // for full day events, the time might be off from RRULE/Luxon problem - // get time zone offset of the rule calculated event + // For full day events, the time might be off from RRULE/Luxon problem + // Get time zone offset of the rule calculated event let dateoffset = date.getTimezoneOffset(); - // reduce the time by the offset + + // Reduce the time by the following offset. Log.debug(" recurring date is " + date + " offset is " + dateoffset); + let dh = moment(date).format("HH"); Log.debug(" recurring date is " + date + " offset is " + dateoffset / 60 + " Hour is " + dh); + if (CalendarUtils.isFullDayEvent(event)) { - Log.debug("fullday"); - // if the offset is negative, east of GMT where the problem is + Log.debug("Fullday"); + // If the offset is negative (east of GMT), where the problem is if (dateoffset < 0) { - // if the date hour is less than the offset + // If the date hour is less than the offset if (dh < Math.abs(dateoffset / 60)) { // reduce the time by the offset Log.debug(" recurring date is " + date + " offset is " + dateoffset); @@ -373,6 +388,7 @@ const CalendarUtils = { } } startDate = moment(date); + Log.debug("Corrected startDate (local): " + startDate.toDate()); let adjustDays = CalendarUtils.calculateTimezoneAdjustment(event, date); @@ -388,7 +404,7 @@ const CalendarUtils = { // This date is an exception date, which means we should skip it in the recurrence pattern. showRecurrence = false; } - Log.debug("duration=" + duration); + Log.debug("duration: " + duration); endDate = moment(parseInt(startDate.format("x")) + duration, "x"); if (startDate.format("x") === endDate.format("x")) { @@ -408,7 +424,7 @@ const CalendarUtils = { } if (showRecurrence === true) { - Log.debug("saving event =" + description); + Log.debug("saving event: " + description); addedEvents++; newEvents.push({ title: recurrenceTitle, @@ -424,7 +440,7 @@ const CalendarUtils = { }); } } - // end recurring event parsing + // End recurring event parsing. } else { // Single event. const fullDayEvent = isFacebookBirthday ? true : CalendarUtils.isFullDayEvent(event); From e7f06f5c0c928cf5e646af5bf9ff01f3dac04854 Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Sun, 22 Aug 2021 14:06:24 +0200 Subject: [PATCH 2/6] Removed duplicated and thus superfluous debug messages. --- modules/default/calendar/calendarutils.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 041c3882..ad24182f 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -334,9 +334,8 @@ const CalendarUtils = { if (dateoffset < 0) { // If the date hour is less than the offset if (dh < Math.abs(dateoffset / 60)) { - // reduce the time by the offset - Log.debug(" recurring date is " + date + " offset is " + dateoffset); - // apply the correction to the date/time to get it UTC relative + // Reduce the time by the offset: + // Apply the correction to the date/time to get it UTC relative date = new Date(date.getTime() - Math.abs(nowOffset) * 60000); // the duration was calculated way back at the top before we could correct the start time.. // fix it for this event entry @@ -363,9 +362,8 @@ const CalendarUtils = { if (dateoffset < 0) { // if the date hour is less than the offset if (dh < Math.abs(dateoffset / 60)) { - // reduce the time by the offset - Log.debug(" recurring date is " + date + " offset is " + dateoffset); - // apply the correction to the date/time to get it UTC relative + // Reduce the time by the offset: + // Apply the correction to the date/time to get it UTC relative date = new Date(date.getTime() - Math.abs(nowOffset) * 60000); // the duration was calculated way back at the top before we could correct the start time.. // fix it for this event entry From 878c0be727a39bec10757689e6fd665bb43b3f11 Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Sun, 22 Aug 2021 14:16:02 +0200 Subject: [PATCH 3/6] [Fix] start time of calendar event gets corrected by time zone offset. --- modules/default/calendar/calendarutils.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index ad24182f..32801a05 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -332,16 +332,17 @@ const CalendarUtils = { Log.debug("Fullday"); // If the offset is negative (east of GMT), where the problem is if (dateoffset < 0) { - // If the date hour is less than the offset - if (dh < Math.abs(dateoffset / 60)) { - // Reduce the time by the offset: - // Apply the correction to the date/time to get it UTC relative - date = new Date(date.getTime() - Math.abs(nowOffset) * 60000); - // the duration was calculated way back at the top before we could correct the start time.. - // fix it for this event entry - //duration = 24 * 60 * 60 * 1000; - Log.debug("new recurring date1 is " + date); - } + // Remove the offset, independently of the comparison between the date hour and the offset, + // since in the case that *date houre < offset*, the *new Date* command will handle this by + // representing the day before. + + // Reduce the time by the offset: + // Apply the correction to the date/time to get it UTC relative + date = new Date(date.getTime() - Math.abs(nowOffset) * 60000); + // the duration was calculated way back at the top before we could correct the start time.. + // fix it for this event entry + //duration = 24 * 60 * 60 * 1000; + Log.debug("new recurring date1 is " + date); } else { // if the timezones are the same, correct date if needed if (event.start.tz === moment.tz.guess()) { From 83b8cc6729bd78cf79668d9ebe23fb48265d77ec Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Sun, 22 Aug 2021 14:23:10 +0200 Subject: [PATCH 4/6] Ran npm run lint:prettier.. --- modules/default/calendar/calendarutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 32801a05..9d9876e1 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -327,7 +327,7 @@ const CalendarUtils = { let dh = moment(date).format("HH"); Log.debug(" recurring date is " + date + " offset is " + dateoffset / 60 + " Hour is " + dh); - + if (CalendarUtils.isFullDayEvent(event)) { Log.debug("Fullday"); // If the offset is negative (east of GMT), where the problem is From b34bb87d7a7bf20d0aa6aad9bf387c737e90b099 Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Sun, 22 Aug 2021 14:27:18 +0200 Subject: [PATCH 5/6] Added fix to CHANGELOG. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4205ac3..b9cad781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ _This release is scheduled to be released on 2021-10-01._ ### Fixed - Fix undefined error with ignoreToday option in weather module (#2620). +- Fix time zone correction in calendar module when the date hour is equal to the time zone correction value (#2632). ## [2.16.0] - 2021-07-01 From cfff2ad72b2a66ee57fc148b1999c49e2cf6ef38 Mon Sep 17 00:00:00 2001 From: Julian Dinter Date: Wed, 25 Aug 2021 17:28:37 +0200 Subject: [PATCH 6/6] Changed comment regarding "ical.js" and "node-ical". --- modules/default/calendar/calendarutils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 9d9876e1..91679f13 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -307,10 +307,10 @@ const CalendarUtils = { // Loop through the set of date entries to see which recurrences should be added to our event list. for (let d in dates) { let date = dates[d]; - // FIXME: We now use node-ical instead of ical.js, but method stays the same. - // ical.js started returning recurrences and exdates as ISOStrings without time information. - // .toISOString().substring(0,10) is the method they use to calculate keys, so we'll do the same - // (see https://github.com/peterbraden/ical.js/pull/84 ) + // Remove the time information of each date by using its substring, using the following method: + // .toISOString().substring(0,10). + // since the date is given as ISOString with YYYY-MM-DDTHH:MM:SS.SSSZ + // (see https://momentjs.com/docs/#/displaying/as-iso-string/). const dateKey = date.toISOString().substring(0, 10); let curEvent = event; let showRecurrence = true;