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.
This commit is contained in:
Conrad Hoffmann 2022-08-31 12:09:00 +02:00 committed by Conrad Hoffmann
parent 58dc8e4982
commit dc63df9058
2 changed files with 30 additions and 2 deletions

View File

@ -127,9 +127,19 @@ func matchPropFilter(filter PropFilter, comp *ical.Component) (bool, error) {
func matchCompTimeRange(start, end time.Time, comp *ical.Component) (bool, error) {
// See https://datatracker.ietf.org/doc/html/rfc4791#section-9.9
// TODO handle "infinity" values in query
// TODO handle recurring events
// evaluate recurring components
rset, err := comp.RecurrenceSet(start.Location())
if err != nil {
return false, err
}
if rset != nil {
// TODO we can only set inclusive to true or false, but really the
// start time is inclusive while the end time is not :/
return len(rset.Between(start, end, true)) > 0, nil
}
// TODO handle "infinity" values in query
// TODO handle more than just events
if comp.Name != ical.CompEvent {
return false, nil
}

View File

@ -253,6 +253,24 @@ END:VCALENDAR`)
addrs: []CalendarObject{event1, event2, event3, todo1},
want: []CalendarObject{event1},
},
{
// Query a time range that only returns a result if recurrence is properly evaluated.
name: "recurring events in time range",
query: &CalendarQuery{
CompFilter: CompFilter{
Name: "VCALENDAR",
Comps: []CompFilter{
CompFilter{
Name: "VEVENT",
Start: toDate(t, "20060103T000000Z"),
End: toDate(t, "20060104T000000Z"),
},
},
},
},
addrs: []CalendarObject{event1, event2, event3, todo1},
want: []CalendarObject{event2},
},
// TODO add more examples
} {
t.Run(tc.name, func(t *testing.T) {