From f6dcfb5ca351243dc2e47d6562788d98853e7103 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 26 Jan 2023 12:55:34 +0100 Subject: [PATCH] Refresh the Calendar DOM every minute (#3016) 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. When using relative for today's events, dates will show as "in X minutes" or "ends in X minutes" for events within an hour and this goes out of date quickly. It's weird to see that the time is, say, 16:30 and an event that you know ends at 16:45 is shown to "ends in 23 minutes" because that's when the last fetch happened. Please forgive me if there's style issue, I don't have npm set up on my machine to run the formatter. --- CHANGELOG.md | 1 + modules/default/calendar/calendar.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 999048d4..1bb7d4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,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 15da1d5d..762d4b9d 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -86,6 +86,8 @@ Module.register("calendar", { // Override start method. start: function () { + const ONE_MINUTE = 60 * 1000; + Log.info("Starting module: " + this.name); // Set locale. @@ -131,6 +133,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.