Skip to content

Commit 0405030

Browse files
authored
Merge pull request #137 from cloud-atlas-ai:muness/issue136
[BUG] Regression with previous and next day events showing up
2 parents eedc669 + 1fe24c9 commit 0405030

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/icalUtils.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function extractMeetingInfo(e: any): { callUrl: string, callType: string
2626
return { callUrl: null, callType: null };
2727
}
2828

29-
function adjustDateToOriginalTimezone(originalDate: Date, currentDate: Date, tzid: string): Date {
29+
function applyRecurrenceDateAndTimezone(originalDate: Date, currentDate: Date, tzid: string): Date {
3030
const momentOriginal = tz(originalDate, tzid);
3131
const momentCurrent = tz(currentDate, tzid);
3232

@@ -69,32 +69,27 @@ function processRecurringRules(event: any, dayToMatch: string, excludedDates: mo
6969
const localStartOfYesterday = moment(dayToMatch).subtract(1, 'day').startOf('day').toDate();
7070
const localEndOfTomorrow = moment(dayToMatch).add(1, 'day').endOf('day').toDate();
7171

72-
event.rrule.between(localStartOfYesterday, localEndOfTomorrow).forEach(recurrenceDate => {
73-
const recurrenceMoment = moment(recurrenceDate).startOf('day');
72+
// Get recurrence dates within the range
73+
const recurrenceDates = event.rrule.between(localStartOfYesterday, localEndOfTomorrow, true);
7474

75-
if (isExcluded(recurrenceMoment, excludedDates)) {
76-
console.debug(`Skipping excluded recurrence: ${event.summary} on ${recurrenceMoment.format('YYYY-MM-DD')}`);
77-
return;
78-
}
75+
recurrenceDates.forEach(recurrenceDate => {
76+
const recurrenceMoment = tz(recurrenceDate, event.rrule.origOptions.tzid || 'UTC');
7977

80-
const adjustedRecurrenceDate = tz(recurrenceMoment.toDate(), event.rrule.origOptions.tzid || 'UTC').toDate();
78+
// Clone the event and use the recurrence date directly if start and end times are present
8179
const clonedEvent = { ...event };
80+
clonedEvent.start = applyRecurrenceDateAndTimezone(event.start, recurrenceDate, event.rrule.origOptions.tzid);
81+
clonedEvent.end = applyRecurrenceDateAndTimezone(event.end, recurrenceDate, event.rrule.origOptions.tzid);
8282

83-
if (event.rrule.origOptions.tzid) {
84-
const tzid = event.rrule.origOptions.tzid;
85-
clonedEvent.start = adjustDateToOriginalTimezone(event.start, adjustedRecurrenceDate, tzid);
86-
clonedEvent.end = adjustDateToOriginalTimezone(event.end, adjustedRecurrenceDate, tzid);
87-
} else {
88-
clonedEvent.start = new Date(adjustedRecurrenceDate);
89-
clonedEvent.end = new Date(adjustedRecurrenceDate.getTime() + (event.end.getTime() - event.start.getTime()));
83+
if (isExcluded(recurrenceMoment, excludedDates)) {
84+
console.debug(`Skipping excluded recurrence: ${event.summary} on ${recurrenceMoment.format('YYYY-MM-DD')}`);
85+
return;
9086
}
9187

9288
delete clonedEvent.rrule;
9389
clonedEvent.recurrent = true;
9490

9591
if (moment(clonedEvent.start).isSame(dayToMatch, 'day')) {
96-
console.debug(`Adding recurring event: ${clonedEvent.summary} on ${recurrenceMoment.format('YYYY-MM-DD')} ${clonedEvent}`);
97-
console.debug(clonedEvent);
92+
console.debug(`Adding recurring event: ${clonedEvent.summary} ${clonedEvent.start} - ${clonedEvent.end}`);
9893
matchingEvents.push(clonedEvent);
9994
}
10095
});

0 commit comments

Comments
 (0)