From 895f515838ace277521b31717684a5a1faf0857b Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 26 Oct 2008 22:15:39 +1300 Subject: [PATCH] Better handling for daily + byday rules. --- dba/caldav_functions.sql | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dba/caldav_functions.sql b/dba/caldav_functions.sql index 723ed3f6..a930a814 100644 --- a/dba/caldav_functions.sql +++ b/dba/caldav_functions.sql @@ -182,9 +182,18 @@ BEGIN loopcount := 100; -- Desirable to stop an infinite loop if there is something we cannot handle LOOP -- RAISE NOTICE ''Testing date: %'', our_answer; - IF frequency = ''WEEKLY'' THEN + IF frequency = 'DAILY' THEN + IF byday IS NOT NULL THEN + LOOP + dow = substring( to_char( our_answer, 'DY' ) for 2); + EXIT WHEN byday ~* dow; + -- Increment for our next time through the loop... + our_answer := our_answer + (length::text || units)::interval; + END LOOP; + END IF; + ELSIF frequency = ''WEEKLY'' THEN -- Weekly repeats are only on specific days - -- I think this is not really right, since a WEEKLY on MO,WE,FR should + -- This is really not right, since a WEEKLY on MO,WE,FR should -- occur three times each week and this will only be once a week. dow = substring( to_char( our_answer, ''DY'' ) for 2); ELSIF frequency = ''MONTHLY'' THEN