@@ -42,7 +42,7 @@ function isExcluded(recurrenceDate: moment.Moment, exdateArray: moment.Moment[])
4242 return exdateArray . some ( exDate => exDate . isSame ( recurrenceDate , 'day' ) ) ;
4343}
4444
45- function processRecurrenceOverrides ( event : any , dayToMatch : string , excludedDates : moment . Moment [ ] , matchingEvents : any [ ] ) {
45+ function processRecurrenceOverrides ( event : any , sortedDaysToMatch : string [ ] , excludedDates : moment . Moment [ ] , matchingEvents : any [ ] ) {
4646 for ( const date in event . recurrences ) {
4747 const recurrence = event . recurrences [ date ] ;
4848 const recurrenceMoment = moment ( date ) . startOf ( 'day' ) ;
@@ -56,20 +56,20 @@ function processRecurrenceOverrides(event: any, dayToMatch: string, excludedDate
5656 recurrence . recurrent = true ;
5757
5858 // Check if this override matches the dayToMatch
59- if ( moment ( recurrence . start ) . isSame ( dayToMatch , "day" ) ) {
59+ if ( moment ( recurrence . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , "day" , "[] ") ) {
6060 console . debug ( `Adding recurring event with override: ${ recurrence . summary } on ${ recurrenceMoment . format ( 'YYYY-MM-DD' ) } ` ) ;
6161 recurrence . eventType = "recurring override" ;
6262 matchingEvents . push ( recurrence ) ;
6363 }
6464 }
6565}
6666
67- function processRecurringRules ( event : any , dayToMatch : string , excludedDates : moment . Moment [ ] , matchingEvents : any [ ] ) {
68- const localStartOfYesterday = moment ( dayToMatch ) . subtract ( 1 , 'day' ) . startOf ( 'day' ) . toDate ( ) ;
69- const localEndOfTomorrow = moment ( dayToMatch ) . add ( 1 , 'day' ) . endOf ( 'day' ) . toDate ( ) ;
67+ function processRecurringRules ( event : any , sortedDaysToMatch : string [ ] , excludedDates : moment . Moment [ ] , matchingEvents : any [ ] ) {
68+ const localStartOfRange = moment ( sortedDaysToMatch . first ( ) ) . subtract ( 1 , 'day' ) . startOf ( 'day' ) . toDate ( ) ;
69+ const localEndOfRange = moment ( sortedDaysToMatch . last ( ) ) . add ( 1 , 'day' ) . endOf ( 'day' ) . toDate ( ) ;
7070
7171 // Get recurrence dates within the range
72- const recurrenceDates = event . rrule . between ( localStartOfYesterday , localEndOfTomorrow , true ) ;
72+ const recurrenceDates = event . rrule . between ( localStartOfRange , localEndOfRange , true ) ;
7373
7474 recurrenceDates . forEach ( recurrenceDate => {
7575 const recurrenceMoment = tz ( recurrenceDate , event . rrule . origOptions . tzid || 'UTC' ) ;
@@ -87,7 +87,7 @@ function processRecurringRules(event: any, dayToMatch: string, excludedDates: mo
8787 delete clonedEvent . rrule ;
8888 clonedEvent . recurrent = true ;
8989
90- if ( moment ( clonedEvent . start ) . isSame ( dayToMatch , 'day' ) ) {
90+ if ( moment ( clonedEvent . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , 'day' , '[] ') ) {
9191 console . debug ( `Adding recurring event: ${ clonedEvent . summary } ${ clonedEvent . start } - ${ clonedEvent . end } ` ) ;
9292 console . debug ( "Excluded dates:" , excludedDates . map ( date => date . format ( 'YYYY-MM-DD' ) ) ) ;
9393
@@ -102,7 +102,8 @@ function shouldIncludeOngoing(event: any, dayToMatch: string): boolean {
102102 return moment ( dayToMatch ) . isBetween ( moment ( event . start ) , moment ( event . end ) , "day" ) ;
103103}
104104
105- export function filterMatchingEvents ( icsArray : any [ ] , dayToMatch : string , showOngoing : boolean ) {
105+ export function filterMatchingEvents ( icsArray : any [ ] , daysToMatch : string [ ] , showOngoing : boolean ) {
106+ const sortedDaysToMatch = [ ...daysToMatch ] . sort ( ) ;
106107 return icsArray . reduce ( ( matchingEvents , event ) => {
107108 // Skip canceled parent events
108109 if ( event . status && event . status . toUpperCase ( ) === "CANCELLED" ) {
@@ -127,16 +128,16 @@ export function filterMatchingEvents(icsArray: any[], dayToMatch: string, showOn
127128
128129 // Process recurrence overrides to populate matching events and excluded dates
129130 if ( event . recurrences ) {
130- processRecurrenceOverrides ( event , dayToMatch , excludedDates , matchingEvents ) ;
131+ processRecurrenceOverrides ( event , sortedDaysToMatch , excludedDates , matchingEvents ) ;
131132 }
132133
133134 // Process recurring rules, skipping overridden dates
134135 if ( event . rrule ) {
135- processRecurringRules ( event , dayToMatch , excludedDates , matchingEvents ) ;
136+ processRecurringRules ( event , sortedDaysToMatch , excludedDates , matchingEvents )
136137 }
137138
138139 // Process non-recurring events
139- if ( ! event . recurrences && ! event . rrule && moment ( event . start ) . isSame ( dayToMatch , "day" ) ) {
140+ if ( ! event . recurrences && ! event . rrule && moment ( event . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , "day" , "[] ") ) {
140141 console . debug ( "Adding one-off event:" , {
141142 summary : event . summary ,
142143 start : event . start ,
@@ -149,7 +150,7 @@ export function filterMatchingEvents(icsArray: any[], dayToMatch: string, showOn
149150 }
150151
151152 // Include ongoing events
152- if ( showOngoing && shouldIncludeOngoing ( event , dayToMatch ) ) {
153+ if ( showOngoing && daysToMatch . some ( dayToMatch => shouldIncludeOngoing ( event , dayToMatch ) ) ) {
153154 matchingEvents . push ( event ) ;
154155 }
155156
0 commit comments