mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Fetch maximumEntries of current events (and all past events if broadcastPastEvents is true)
This commit is contained in:
parent
8a5e87b116
commit
d00c25e107
@ -376,17 +376,24 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
||||
return a.startDate - b.startDate;
|
||||
});
|
||||
|
||||
if (includePastEvents) {
|
||||
// Include all events
|
||||
events = newEvents;
|
||||
} else {
|
||||
// All events from startOfToday are fetched but we only want the ones that haven't ended yet
|
||||
const now = moment();
|
||||
var entries = -1;
|
||||
var pastEntries = 0;
|
||||
for (var ne of newEvents) {
|
||||
if (moment(ne.endDate, "x").isAfter(now)) events.push(ne);
|
||||
if (!includePastEvents && moment(ne.endDate, "x").isBefore(now)) {
|
||||
// Events has ended and past events should not be included
|
||||
pastEntries++;
|
||||
continue;
|
||||
}
|
||||
entries++;
|
||||
// If max events has been saved, skip the rest
|
||||
if (entries > maximumEntries) break;
|
||||
}
|
||||
entries += pastEntries; // Total number of entries should include pastEntries
|
||||
if (entries > 0) {
|
||||
events = newEvents.slice(0, entries);
|
||||
} else {
|
||||
events = [];
|
||||
}
|
||||
events = events.slice(0, maximumEntries);
|
||||
|
||||
self.broadcastEvents();
|
||||
scheduleTimer();
|
||||
|
Loading…
x
Reference in New Issue
Block a user