diff --git a/dba/caldav_functions.sql b/dba/caldav_functions.sql
index 15998465..fbd96ad8 100644
--- a/dba/caldav_functions.sql
+++ b/dba/caldav_functions.sql
@@ -95,6 +95,10 @@ DECLARE
our_answer TIMESTAMP WITH TIME ZONE;
loopcount INT;
BEGIN
+ IF basedate > earliest THEN
+ RETURN basedate;
+ END IF;
+
temp_txt := substring(repeatrule from ''UNTIL=([0-9TZ]+)(;|$)'');
IF temp_txt IS NOT NULL AND temp_txt::timestamp with time zone < earliest THEN
RETURN NULL;
@@ -179,7 +183,7 @@ BEGIN
END IF;
- loopcount := 100; -- Desirable to stop an infinite loop if there is something we cannot handle
+ loopcount := 500; -- Desirable to stop an infinite loop if there is something we cannot handle
LOOP
-- RAISE NOTICE ''Testing date: %'', our_answer;
IF frequency = ''DAILY'' THEN
@@ -212,9 +216,13 @@ BEGIN
EXIT WHEN our_answer >= earliest;
+ -- Give up if we have exceeded the count
+ EXIT WHEN past_repeats > count;
+ past_repeats := past_repeats + 1;
+
loopcount := loopcount - 1;
IF loopcount < 0 THEN
- RAISE EXCEPTION ''Giving up on repeat rule "%" - after 100 increments from % we are still not after %'', repeatrule, basedate, earliest;
+ RAISE NOTICE ''Giving up on repeat rule "%" - after 100 increments from % we are still not after %'', repeatrule, basedate, earliest;
RETURN NULL;
END IF;
diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php
index f5f50440..645ba2e1 100644
--- a/inc/caldav-REPORT-calquery.php
+++ b/inc/caldav-REPORT-calquery.php
@@ -121,19 +121,18 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter =
$finish = $v->GetAttribute("end");
if ( isset($start) && isset($finish) ) {
$sql .= sprintf( "AND ( (%s >= %s::timestamp with time zone AND %s <= %s::timestamp with time zone) ",
- $start_column, qpg($start), $finish_column, qpg($finish));
- $sql .= sprintf( "OR (calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone ", qpg($start), $finish_column, qpg($start) );
- $sql .= sprintf( "AND calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= %s::timestamp with time zone ", qpg($start), $start_column, qpg($finish) );
- $sql .= sprintf( "AND calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= ", qpg($start), $finish_column );
- $sql .= sprintf( " calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) ) ", qpg($start), $start_column );
- $sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) ) " );
+ $finish_column, qpg($start), $start_column, qpg($finish));
+ $sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= %s::timestamp with time zone ", qpg($start), $finish_column, qpg($finish) );
+ $sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= %s::timestamp with time zone ", qpg($start), $start_column, qpg($finish) );
+ $sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) )" );
}
else if ( isset($start) ) {
- $sql .= sprintf( "AND (%s >= %s::timestamp with time zone ", $start_column, qpg($start));
- $sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone) ", qpg($start), $start_column, qpg($start) );
+ $sql .= sprintf( "AND (%s >= %s::timestamp with time zone ", $finish_column, qpg($start));
+ $sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone ", qpg($start), $finish_column, qpg($start) );
+ $sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) )" );
}
else if ( isset( $finish ) ) {
- $sql .= sprintf( "AND %s <= %s::timestamp with time zone ", $finish_column, qpg($finish) );
+ $sql .= sprintf( "AND %s <= %s::timestamp with time zone ", $start_column, qpg($finish) );
}
break;
diff --git a/testing/tests/regression-suite/900-Moz-REPORT.result b/testing/tests/regression-suite/900-Moz-REPORT.result
index d41c9ed9..bb3a8dcd 100644
--- a/testing/tests/regression-suite/900-Moz-REPORT.result
+++ b/testing/tests/regression-suite/900-Moz-REPORT.result
@@ -1,8 +1,8 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
-ETag: "45378fedb0c0afcdb486961f46833f39"
-Content-Length: 7736
+ETag: "064d0dec288b53bef0f91734d355a42a"
+Content-Length: 6389
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/xml; charset="utf-8"
@@ -184,56 +184,6 @@ RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=10
END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
-
-
- HTTP/1.1 200 OK
-
-
-
- /caldav.php/user1/home/e70576e9-c1e0-431e-a507-0386fd82f223.ics
-
-
- BEGIN:VCALENDAR
-PRODID:-//Mozilla Calendar//NONSGML Sunbird//EN
-VERSION:2.0
-BEGIN:VTIMEZONE
-TZID:/mozilla.org/20070129_1/Antarctica/McMurdo
-X-LIC-LOCATION:Antarctica/McMurdo
-BEGIN:STANDARD
-TZOFFSETFROM:+1300
-TZOFFSETTO:+1200
-TZNAME:NZST
-DTSTART:19700315T030000
-RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=3SU;BYMONTH=3
-END:STANDARD
-BEGIN:DAYLIGHT
-TZOFFSETFROM:+1200
-TZOFFSETTO:+1300
-TZNAME:NZDT
-DTSTART:19701004T020000
-RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=10
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VEVENT
-CREATED:20071203T202630Z
-LAST-MODIFIED:20071203T202834Z
-DTSTAMP:20071203T202630Z
-UID:e70576e9-c1e0-431e-a507-0386fd82f223
-SUMMARY:Morning Meeting
-RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH
-DTSTART;TZID=/mozilla.org/20070129_1/Antarctica/McMurdo:20071211T074500
-DTEND;TZID=/mozilla.org/20070129_1/Antarctica/McMurdo:20071211T083000
-X-MOZ-LOCATIONPATH:e70576e9-c1e0-431e-a507-0386fd82f223.ics
-LOCATION:Suzies Coffee Lounge
-DESCRIPTION:Twice-weekly breakfast meeting
-CATEGORIES:Business
-BEGIN:VALARM
-TRIGGER;VALUE=DURATION:-PT10M
-DESCRIPTION:Mozilla Alarm: Morning Meeting
-ACTION:DISPLAY
-END:VALARM
-END:VEVENT
-END:VCALENDAR
HTTP/1.1 200 OK