@@ -42,12 +42,11 @@ function isExcluded(recurrenceDate: moment.Moment, exdateArray: moment.Moment[])
4242 return exdateArray . some ( exDate => exDate . isSame ( recurrenceDate , 'day' ) ) ;
4343}
4444
45- function processRecurrenceOverrides ( event : any , range : Date [ ] , 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' ) ;
4949
50-
5150 // Skip canceled overrides
5251 if ( recurrence . status && recurrence . status . toUpperCase ( ) === "CANCELLED" ) {
5352 console . debug ( `Skipping canceled recurrence override: ${ recurrence . summary } on ${ date } ` ) ;
@@ -57,18 +56,20 @@ function processRecurrenceOverrides(event: any, range: Date[], excludedDates: mo
5756 recurrence . recurrent = true ;
5857
5958 // Check if this override matches the dayToMatch
60- if ( moment ( recurrence . start ) . isBetween ( range . first ( ) , range . last ( ) , "day" ) ) {
59+ if ( moment ( recurrence . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , "day" , "[] ") ) {
6160 console . debug ( `Adding recurring event with override: ${ recurrence . summary } on ${ recurrenceMoment . format ( 'YYYY-MM-DD' ) } ` ) ;
6261 recurrence . eventType = "recurring override" ;
6362 matchingEvents . push ( recurrence ) ;
6463 }
6564 }
6665}
6766
68- function processRecurringRules ( event : any , range : Date [ ] , excludedDates : moment . Moment [ ] , matchingEvents : any [ ] ) {
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 ( ) ;
6970
7071 // Get recurrence dates within the range
71- const recurrenceDates = event . rrule . between ( range . first ( ) , range . last ( ) , true ) ;
72+ const recurrenceDates = event . rrule . between ( localStartOfRange , localEndOfRange , true ) ;
7273
7374 recurrenceDates . forEach ( recurrenceDate => {
7475 const recurrenceMoment = tz ( recurrenceDate , event . rrule . origOptions . tzid || 'UTC' ) ;
@@ -86,8 +87,11 @@ function processRecurringRules(event: any, range: Date[], excludedDates: moment.
8687 delete clonedEvent . rrule ;
8788 clonedEvent . recurrent = true ;
8889
89- if ( moment ( clonedEvent . start ) . isBetween ( range . first ( ) , range . last ( ) , 'day' ) ) {
90+ if ( moment ( clonedEvent . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , 'day' , '[] ') ) {
9091 console . debug ( `Adding recurring event: ${ clonedEvent . summary } ${ clonedEvent . start } - ${ clonedEvent . end } ` ) ;
92+ console . debug ( "Excluded dates:" , excludedDates . map ( date => date . format ( 'YYYY-MM-DD' ) ) ) ;
93+
94+ console . debug ( clonedEvent ) ;
9195 clonedEvent . eventType = "recurring" ;
9296 matchingEvents . push ( clonedEvent ) ;
9397 }
@@ -100,13 +104,7 @@ function shouldIncludeOngoing(event: any, dayToMatch: string): boolean {
100104
101105export function filterMatchingEvents ( icsArray : any [ ] , daysToMatch : string [ ] , showOngoing : boolean ) {
102106 const sortedDaysToMatch = [ ...daysToMatch ] . sort ( ) ;
103-
104- const localStartOfRange = moment ( sortedDaysToMatch . first ( ) ) . startOf ( 'day' ) . toDate ( ) ;
105- const localEndOfRange = moment ( sortedDaysToMatch . last ( ) ) . endOf ( 'day' ) . toDate ( ) ;
106- const range = [ localStartOfRange , localEndOfRange ] ;
107-
108107 return icsArray . reduce ( ( matchingEvents , event ) => {
109-
110108 // Skip canceled parent events
111109 if ( event . status && event . status . toUpperCase ( ) === "CANCELLED" ) {
112110 console . debug ( `Skipping canceled event: ${ event . summary } ` ) ;
@@ -130,17 +128,16 @@ export function filterMatchingEvents(icsArray: any[], daysToMatch: string[], sho
130128
131129 // Process recurrence overrides to populate matching events and excluded dates
132130 if ( event . recurrences ) {
133- processRecurrenceOverrides ( event , range , excludedDates , matchingEvents ) ;
131+ processRecurrenceOverrides ( event , sortedDaysToMatch , excludedDates , matchingEvents ) ;
134132 }
135133
136134 // Process recurring rules, skipping overridden dates
137135 if ( event . rrule ) {
138- processRecurringRules ( event , range , excludedDates , matchingEvents )
136+ processRecurringRules ( event , sortedDaysToMatch , excludedDates , matchingEvents )
139137 }
140138
141-
142139 // Process non-recurring events
143- if ( ! event . recurrences && ! event . rrule && moment ( event . start ) . isBetween ( range . first ( ) , range . last ( ) ) ) {
140+ if ( ! event . recurrences && ! event . rrule && moment ( event . start ) . isBetween ( sortedDaysToMatch . first ( ) , sortedDaysToMatch . last ( ) , "day" , "[]" ) ) {
144141 console . debug ( "Adding one-off event:" , {
145142 summary : event . summary ,
146143 start : event . start ,
@@ -162,8 +159,8 @@ export function filterMatchingEvents(icsArray: any[], daysToMatch: string[], sho
162159}
163160
164161export function parseIcs ( ics : string ) {
165- let data = ical . parseICS ( ics ) ;
166- let vevents = [ ] ;
162+ var data = ical . parseICS ( ics ) ;
163+ var vevents = [ ] ;
167164
168165 for ( let i in data ) {
169166 if ( data [ i ] . type != "VEVENT" )
0 commit comments