Skip to content

Commit dc63df9

Browse files
committed
carddav: evaluate recurrence in match helper
The match helper will now properly return recurring events if any of their recurrences fall into the queried time range. A test for this was added as well.
1 parent 58dc8e4 commit dc63df9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

caldav/match.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ func matchPropFilter(filter PropFilter, comp *ical.Component) (bool, error) {
127127
func matchCompTimeRange(start, end time.Time, comp *ical.Component) (bool, error) {
128128
// See https://datatracker.ietf.org/doc/html/rfc4791#section-9.9
129129

130-
// TODO handle "infinity" values in query
131-
// TODO handle recurring events
130+
// evaluate recurring components
131+
rset, err := comp.RecurrenceSet(start.Location())
132+
if err != nil {
133+
return false, err
134+
}
135+
if rset != nil {
136+
// TODO we can only set inclusive to true or false, but really the
137+
// start time is inclusive while the end time is not :/
138+
return len(rset.Between(start, end, true)) > 0, nil
139+
}
132140

141+
// TODO handle "infinity" values in query
142+
// TODO handle more than just events
133143
if comp.Name != ical.CompEvent {
134144
return false, nil
135145
}

caldav/match_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,24 @@ END:VCALENDAR`)
253253
addrs: []CalendarObject{event1, event2, event3, todo1},
254254
want: []CalendarObject{event1},
255255
},
256+
{
257+
// Query a time range that only returns a result if recurrence is properly evaluated.
258+
name: "recurring events in time range",
259+
query: &CalendarQuery{
260+
CompFilter: CompFilter{
261+
Name: "VCALENDAR",
262+
Comps: []CompFilter{
263+
CompFilter{
264+
Name: "VEVENT",
265+
Start: toDate(t, "20060103T000000Z"),
266+
End: toDate(t, "20060104T000000Z"),
267+
},
268+
},
269+
},
270+
},
271+
addrs: []CalendarObject{event1, event2, event3, todo1},
272+
want: []CalendarObject{event2},
273+
},
256274
// TODO add more examples
257275
} {
258276
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)