mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Include all past events (if broadcastPastEvents set) and up to maximumEntries of current or upcoming events
This commit is contained in:
parent
a01f08391b
commit
3c5d50bce9
@ -376,24 +376,20 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
return a.startDate - b.startDate;
|
return a.startDate - b.startDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// include up to maximumEntries current or upcoming events
|
||||||
|
// If past events should be included, include all past events
|
||||||
const now = moment();
|
const now = moment();
|
||||||
var entries = -1;
|
var entries = 0;
|
||||||
var pastEntries = 0;
|
events = [];
|
||||||
for (var ne of newEvents) {
|
for (let ne of newEvents) {
|
||||||
if (!includePastEvents && moment(ne.endDate, "x").isBefore(now)) {
|
if (moment(ne.endDate, "x").isBefore(now)) {
|
||||||
// Events has ended and past events should not be included
|
if (includePastEvents) events.push(ne);
|
||||||
pastEntries++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entries++;
|
entries++;
|
||||||
// If max events has been saved, skip the rest
|
// If max events has been saved, skip the rest
|
||||||
if (entries > maximumEntries) break;
|
if (entries > maximumEntries) break;
|
||||||
}
|
events.push(ne);
|
||||||
entries += pastEntries; // Total number of entries should include pastEntries
|
|
||||||
if (entries > 0) {
|
|
||||||
events = newEvents.slice(0, entries);
|
|
||||||
} else {
|
|
||||||
events = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.broadcastEvents();
|
self.broadcastEvents();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user