[Freeassociation-devel] patch for BYDAY bug

Josh Skillings jskillings at gmail.com
Mon Apr 7 16:18:27 PDT 2008


I encountered a bug when generating recurring events when the rrule
specifies BYDAY but the start of the event pattern is before the first day
in the BYDAY list.

For example:

With rrule FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,WE,FR;WKST=SU, but the start of
the event pattern is on Sunday. The behavior I've noticed is that the call
to "icalrecur_iterator_next" generates an event on Wednesday, with Monday
being skipped.

The attached and inline patch fixes this behavior.

--Josh

Index: libical/src/libical/icalrecur.c
===================================================================
RCS file: /cvsroot/freeassociation/libical/src/libical/icalrecur.c,v
retrieving revision 1.71
diff -u -8 -p -r1.71 icalrecur.c
--- libical/src/libical/icalrecur.c 3 Feb 2008 16:10:46 -0000 1.71
+++ libical/src/libical/icalrecur.c 7 Apr 2008 23:02:12 -0000
@@ -944,19 +944,24 @@ icalrecur_iterator* icalrecur_iterator_n
       days ahead ) will skip over some occurrences in the
       second week. */
    /* This depends on impl->by_ptrs[BY_DAY] being correctly sorted by
     * day. This should probably be abstracted to make such assumption
     * more explicit. */
    short dow =
(short)(impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last));
-   if (dow > impl->rule.week_start-1) dow -= 7;
-   impl->last.day += dow;
-   impl->last = icaltime_normalize(impl->last);
+
+    if((icaltime_day_of_week(impl->last) < impl->by_ptrs[BY_DAY][0] && dow
>= 0) || dow < 0)
+    {
+      /* initial time is after first day of BY_DAY data */
+
+      impl->last.day += dow;
+      impl->last = icaltime_normalize(impl->last);
+    }
       }

     }
     /* For YEARLY rule, begin by setting up the year days array . The
        YEARLY rules work by expanding one year at a time. */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/libical-devel/attachments/20080407/dc315901/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://lists.infradead.org/pipermail/libical-devel/attachments/20080407/dc315901/attachment.txt>


More information about the libical-devel mailing list