mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
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.
This commit is contained in:
parent
157e74ce7c
commit
f6dcfb5ca3
@ -26,6 +26,7 @@ _This release is scheduled to be released on 2023-04-01._
|
|||||||
|
|
||||||
- Use develop as target branch for dependabot
|
- Use develop as target branch for dependabot
|
||||||
- Update issue template and contributing doc
|
- Update issue template and contributing doc
|
||||||
|
- Update dates in Calendar widgets every minute
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -86,6 +86,8 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
// Override start method.
|
// Override start method.
|
||||||
start: function () {
|
start: function () {
|
||||||
|
const ONE_MINUTE = 60 * 1000;
|
||||||
|
|
||||||
Log.info("Starting module: " + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
@ -131,6 +133,14 @@ Module.register("calendar", {
|
|||||||
// fetcher till cycle
|
// fetcher till cycle
|
||||||
this.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
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.
|
// Override socket notification handler.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user