@@ -26,7 +26,7 @@ export function extractMeetingInfo(e: any): { callUrl: string, callType: string
26
26
return { callUrl : null , callType : null } ;
27
27
}
28
28
29
- function adjustDateToOriginalTimezone ( originalDate : Date , currentDate : Date , tzid : string ) : Date {
29
+ function applyRecurrenceDateAndTimezone ( originalDate : Date , currentDate : Date , tzid : string ) : Date {
30
30
const momentOriginal = tz ( originalDate , tzid ) ;
31
31
const momentCurrent = tz ( currentDate , tzid ) ;
32
32
@@ -69,32 +69,27 @@ function processRecurringRules(event: any, dayToMatch: string, excludedDates: mo
69
69
const localStartOfYesterday = moment ( dayToMatch ) . subtract ( 1 , 'day' ) . startOf ( 'day' ) . toDate ( ) ;
70
70
const localEndOfTomorrow = moment ( dayToMatch ) . add ( 1 , 'day' ) . endOf ( 'day' ) . toDate ( ) ;
71
71
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 ) ;
74
74
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' ) ;
79
77
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
81
79
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 ) ;
82
82
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 ;
90
86
}
91
87
92
88
delete clonedEvent . rrule ;
93
89
clonedEvent . recurrent = true ;
94
90
95
91
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 } ` ) ;
98
93
matchingEvents . push ( clonedEvent ) ;
99
94
}
100
95
} ) ;
0 commit comments