Skip to content

Commit

Permalink
Fix event filter function in example
Browse files Browse the repository at this point in the history
  • Loading branch information
aharter committed Feb 28, 2021
1 parent c7db567 commit 402e91b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions example/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ const bumpSyncToken = function(cal) {
cal.syncToken = parts.slice(0, -1).join('/') + '/' + (parseInt(parts[parts.length - 1]) + 1);
};

const eventFilter = function(start, end, eventStart, eventEnd) {
return (!start || start <= eventEnd) && (!end || end >= eventStart);
};

const recurringEventFilter = function(start, end, event) {
if (!event.recurring) {
return false;
}

const eventStart = event.startDate;
const eventEnd = event.recurring.until ? event.recurring.until : end;
return eventFilter(start, end, eventStart, eventEnd);
};

const singleEventFilter = function(start, end, event) {
return eventFilter(start, end, event.startDate, event.endDate);
};

module.exports.getCalendar = async function({
calendarId,
// principalId,
Expand Down Expand Up @@ -125,10 +143,8 @@ module.exports.getEventsByDate = async function({
return _.filter(data.events, (v) => {
return v.calendarId === calendarId &&
(
v.weekly ||
(start && v.startDate >= start && end && v.endDate <= end) ||
(start && v.startDate >= start && !end) ||
(!start && end && v.endDate <= end)
recurringEventFilter(start, end, v) ||
singleEventFilter(start, end, v)
);
});
};
Expand Down

0 comments on commit 402e91b

Please sign in to comment.