Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle possible date field lookup exceptions #66

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions src/icalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,34 @@ function findRecurringEvents(icsArray: any[], dayToMatch: string) {
let skip = false;

// Use just the date of the recurrence to look up overrides and exceptions (i.e. chop off time information)
const dateLookupKey = date.toISOString().slice(0, 10);

if (origEvent.exdate !== undefined && curEvent.exdate[dateLookupKey] !== undefined) {
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
// This date is an exception date, which means we should skip it in the recurrence pattern.
skip = true;
}

// For each date that we're checking, it's possible that there is a recurrence override for that one day.
if (curEvent.recurrences !== undefined && curEvent.recurrences[dateLookupKey] !== undefined) {
// override event
curEvent = curEvent.recurrences[dateLookupKey];
//override duration
curDuration = extractDuration(curEvent);
try {
const dateLookupKey = date.toISOString().slice(0, 10);

if (origEvent.exdate !== undefined && curEvent.exdate[dateLookupKey] !== undefined) {
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
// This date is an exception date, which means we should skip it in the recurrence pattern.
skip = true;
}

// For each date that we're checking, it's possible that there is a recurrence override for that one day.
if (curEvent.recurrences !== undefined && curEvent.recurrences[dateLookupKey] !== undefined) {
// override event
curEvent = curEvent.recurrences[dateLookupKey];
//override duration
curDuration = extractDuration(curEvent);
}

//if this is the first instance of the event, we don't want it picked up here
if (moment(date).isSame(curEvent.start)) {
skip = true;
}

if (!skip)
matchingRecurringEvents.push(cloneRecurringEvent(origEvent, curEvent, date, curDuration));
} catch (e) {
console.error('Unable to parse date: ', date, e);
return
}

//if this is the first instance of the event, we don't want it picked up here
if (moment(date).isSame(curEvent.start)) {
skip = true;
}

if (!skip)
matchingRecurringEvents.push(cloneRecurringEvent(origEvent, curEvent, date, curDuration));
});
}
});
Expand Down