From b6f4737ecc28eabb4359eab98e6f3b88a204bb04 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Fri, 19 Mar 2021 10:32:04 -0500 Subject: [PATCH 1/2] fix 2488, west of UTC day shift --- CHANGELOG.md | 1 + modules/default/calendar/calendarutils.js | 38 +++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e9d64d1..69ee47b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ _This release is scheduled to be released on 2021-04-01._ - Fix updatenotification creating zombie processes by setting a timeout for the git process - Fix weather module openweathermap not loading if lat and lon set without onecall. - Fix calendar daylight savings offset calculation if recurring start date before 2007 +- Fix calendar time/date adjustment when time with GMT offset is different day (#2488) ## [2.14.0] - 2021-01-01 diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index 9ade144e..debe2cc4 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -296,14 +296,14 @@ 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 + let nowOffset = new Date().getTimezoneOffset(); // for full day events, the time might be off from RRULE/Luxon problem if (CalendarUtils.isFullDayEvent(event)) { Log.debug("fullday"); // if the offset is negative, east of GMT where the problem is if (date.getTimezoneOffset() < 0) { - // get the offset of today where we are processing - // this will be the correction we need to apply - let nowOffset = new Date().getTimezoneOffset(); Log.debug("now offset is " + nowOffset); // reduce the time by the offset Log.debug(" recurring date is " + date + " offset is " + date.getTimezoneOffset()); @@ -314,6 +314,38 @@ const CalendarUtils = { duration = 24 * 60 * 60 * 1000; Log.debug("new recurring date is " + date); } + } else { // not full day, but luxon can still screw up the date on the rule processing + // get time zone offset of the rule calculated event + let dateoffset = date.getTimezoneOffset() + // reduce the time by the 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); + + // we need to correct the date to get back to the right event for + 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 + 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 date hour is less than the offset + if( (24-dh) < Math.abs(dateoffset/60)){ + // apply the correction to the date/time back to right day + date = new Date(date.getTime() + Math.abs(24*60) * 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 date2 is " + date); + } + } } startDate = moment(date); From 2b940c9cfbd19667afb95d0b7e82d8d612fc8e6f Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Fri, 19 Mar 2021 10:42:14 -0500 Subject: [PATCH 2/2] fix formatting --- modules/default/calendar/calendarutils.js | 29 ++++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index debe2cc4..fc45d583 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -314,18 +314,19 @@ const CalendarUtils = { duration = 24 * 60 * 60 * 1000; Log.debug("new recurring date is " + date); } - } else { // not full day, but luxon can still screw up the date on the rule processing + } else { + // not full day, but luxon can still screw up the date on the rule processing // get time zone offset of the rule calculated event - let dateoffset = date.getTimezoneOffset() + let dateoffset = date.getTimezoneOffset(); // reduce the time by the 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); + let dh = moment(date).format("HH"); + Log.debug(" recurring date is " + date + " offset is " + dateoffset / 60 + " Hour is " + dh); // we need to correct the date to get back to the right event for - if(dateoffset <0){ + if (dateoffset < 0) { // if the date hour is less than the offset - if( (dh) < Math.abs(dateoffset/60)){ + 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 @@ -336,14 +337,14 @@ const CalendarUtils = { Log.debug("new recurring date1 is " + date); } } else { - // if the date hour is less than the offset - if( (24-dh) < Math.abs(dateoffset/60)){ - // apply the correction to the date/time back to right day - date = new Date(date.getTime() + Math.abs(24*60) * 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 date2 is " + date); + // if the date hour is less than the offset + if (24 - dh < Math.abs(dateoffset / 60)) { + // apply the correction to the date/time back to right day + date = new Date(date.getTime() + Math.abs(24 * 60) * 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 date2 is " + date); } } }