Skip to content

Commit

Permalink
carddav: evaluate recurrence in match helper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bitfehler committed Aug 31, 2022
1 parent 58dc8e4 commit dc63df9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
14 changes: 12 additions & 2 deletions caldav/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions caldav/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit dc63df9

Please sign in to comment.