diff --git a/inc/freebusy-functions.php b/inc/freebusy-functions.php index d0ab2fe9..35225973 100644 --- a/inc/freebusy-functions.php +++ b/inc/freebusy-functions.php @@ -20,7 +20,10 @@ function get_freebusy( $path_match, $range_start, $range_end, $bin_privs = null } $params = array( ':path_match' => $path_match, ':start' => $range_start->UTC(), ':end' => $range_end->UTC() ); $where = ' WHERE caldav_data.dav_name ~ :path_match '; - $where .= 'AND rrule_event_overlaps( dtstart, dtend, rrule, :start, :end) '; + $where .= "AND ("; + $where .= " (calendar_item.first_instance_start <= :end AND (:start <= calendar_item.last_instance_end OR calendar_item.last_instance_end IS NULL)) "; + $where .= " OR (calendar_item.first_instance_start IS NULL AND rrule_event_overlaps( dtstart, dtend, rrule, :start, :end)) "; + $where .= ") "; $where .= "AND caldav_data.caldav_type IN ( 'VEVENT', 'VTODO' ) "; $where .= "AND (calendar_item.transp != 'TRANSPARENT' OR calendar_item.transp IS NULL) "; $where .= "AND (calendar_item.status != 'CANCELLED' OR calendar_item.status IS NULL) ";