From 12d2647dbbcaff0e2ef1a94775c672d90a88ca6e Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 19 Jan 2023 21:39:14 +0100 Subject: [PATCH 1/2] Refresh the Calendar DOM every minute This keeps relative dates accurate when the calendar's fetch frequency is much larger than a minute. As fetching incurs network traffic and load on servers and most calendars don't update that often, simply refreshing locally is enough. --- CHANGELOG.md | 1 + modules/default/calendar/calendar.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012307d9fc..d619714e7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ _This release is scheduled to be released on 2023-04-01._ - Use develop as target branch for dependabot - Update issue template and contributing doc +- Update dates in Calendar widgets every minute ### Fixed diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 15da1d5d27..dd74e3a077 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -86,6 +86,9 @@ Module.register("calendar", { // Override start method. start: function () { + const ONE_SECOND = 1000; // 1,000 milliseconds + const ONE_MINUTE = ONE_SECOND * 60; + Log.info("Starting module: " + this.name); // Set locale. @@ -131,6 +134,14 @@ Module.register("calendar", { // fetcher till cycle this.addCalendar(calendar.url, calendar.auth, calendarConfig); }); + + // Refresh the DOM every minute if needed: When using relative date format for events that start + // or end in less than an hour, the date shows minute granularity and we want to keep that accurate. + setTimeout(() => { + setInterval(() => { + this.updateDom(1); + }, ONE_MINUTE); + }, ONE_MINUTE - (new Date() % ONE_MINUTE)); }, // Override socket notification handler. From 931996ffbbe172fe859254d46e67008e3d91c5ca Mon Sep 17 00:00:00 2001 From: psieg Date: Thu, 19 Jan 2023 23:42:29 +0100 Subject: [PATCH 2/2] Skip unnecessary constant --- modules/default/calendar/calendar.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index dd74e3a077..762d4b9dfd 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -86,8 +86,7 @@ Module.register("calendar", { // Override start method. start: function () { - const ONE_SECOND = 1000; // 1,000 milliseconds - const ONE_MINUTE = ONE_SECOND * 60; + const ONE_MINUTE = 60 * 1000; Log.info("Starting module: " + this.name);