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(Google Calendar node): Correctly set dtstart for recurrence rules in addNextOccurrence function #12266

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,17 @@ export function addNextOccurrence(items: RecurentEvent[]) {
for (const item of items) {
if (item.recurrence) {
let eventRecurrence;
let eventStartDateTime;
try {
eventRecurrence = item.recurrence.find((r) => r.toUpperCase().startsWith('RRULE'));
eventStartDateTime = item.start.dateTime;
if (!eventRecurrence) continue;

const rrule = RRule.fromString(eventRecurrence);
const rruleOptions = {
...RRule.parseString(eventRecurrence),
dtstart: new Date(eventStartDateTime),
};
const rrule = new RRule(rruleOptions);
const until = rrule.options?.until;

const now = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,58 @@ describe('addTimezoneToDate', () => {
expect(result4).toBe('2021-09-01T12:00:00.000+08:00');
});
});

describe('Google Calendar -> addNextOccurrence', () => {
it('should correctly add next occurrence and split time component', () => {
const mockEvent = {
start: {
dateTime: '2023-09-07T09:30:00+02:00',
timeZone: 'Europe/Berlin',
},
end: {
dateTime: '2023-09-07T11:00:00+02:00',
timeZone: 'Europe/Berlin',
},
recurrence: ['RRULE:FREQ=WEEKLY;BYDAY=TH'],
};

const result = addNextOccurrence([mockEvent]);

expect(result[0].nextOccurrence).toBeDefined();
expect(result[0].nextOccurrence.start.dateTime.split('T')[1]).toBe('09:30:00+02:00');
});

it('should handle events without recurrence', () => {
const mockEventNoRecurrence = {
start: {
dateTime: '2023-09-07T09:30:00+02:00',
timeZone: 'Europe/Berlin',
},
end: {
dateTime: '2023-09-07T11:00:00+02:00',
timeZone: 'Europe/Berlin',
},
recurrence: [],
};

const result = addNextOccurrence([mockEventNoRecurrence]);
expect(result[0].nextOccurrence).toBeUndefined();
});

it('should handle events with invalid recurrence rules', () => {
const mockEventInvalidRecurrence = {
start: {
dateTime: '2023-09-07T09:30:00+02:00',
timeZone: 'Europe/Berlin',
},
end: {
dateTime: '2023-09-07T11:00:00+02:00',
timeZone: 'Europe/Berlin',
},
recurrence: ['INVALID_RRULE'],
};

const result = addNextOccurrence([mockEventInvalidRecurrence]);
expect(result[0].nextOccurrence).toBeUndefined();
});
});