Use object.entries to iterate over data

This commit is contained in:
rejas 2020-06-20 09:01:35 +02:00
parent 1e5bd98f02
commit daa6f5051c

View File

@ -70,9 +70,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
return event[time].length === 8 ? moment(event[time], "YYYYMMDD") : moment(new Date(event[time])); return event[time].length === 8 ? moment(event[time], "YYYYMMDD") : moment(new Date(event[time]));
}; };
for (let k in data) { Object.entries(data).forEach(([key, event]) => {
if (data.hasOwnProperty(k)) {
const event = data[k];
const now = new Date(); const now = new Date();
const today = moment().startOf("day").toDate(); const today = moment().startOf("day").toDate();
const future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1, "seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat. const future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1, "seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.
@ -163,7 +161,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
} }
if (excluded) { if (excluded) {
continue; return;
} }
const location = event.location || false; const location = event.location || false;
@ -281,27 +279,27 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
if (includePastEvents) { if (includePastEvents) {
// Past event is too far in the past, so skip. // Past event is too far in the past, so skip.
if (endDate < past) { if (endDate < past) {
continue; return;
} }
} else { } else {
// It's not a fullday event, and it is in the past, so skip. // It's not a fullday event, and it is in the past, so skip.
if (!fullDayEvent && endDate < new Date()) { if (!fullDayEvent && endDate < new Date()) {
continue; return;
} }
// It's a fullday event, and it is before today, So skip. // It's a fullday event, and it is before today, So skip.
if (fullDayEvent && endDate <= today) { if (fullDayEvent && endDate <= today) {
continue; return;
} }
} }
// It exceeds the maximumNumberOfDays limit, so skip. // It exceeds the maximumNumberOfDays limit, so skip.
if (startDate > future) { if (startDate > future) {
continue; return;
} }
if (timeFilterApplies(now, endDate, dateFilter)) { if (timeFilterApplies(now, endDate, dateFilter)) {
continue; return;
} }
// Adjust start date so multiple day events will be displayed as happening today even though they started some days ago already // Adjust start date so multiple day events will be displayed as happening today even though they started some days ago already
@ -322,8 +320,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
}); });
} }
} }
} });
}
newEvents.sort(function (a, b) { newEvents.sort(function (a, b) {
return a.startDate - b.startDate; return a.startDate - b.startDate;