[Kolab-devel] [issue3846] fix recurring events that are counted per week and not per incident

issues at kolab.org issues at kolab.org
Thu Sep 10 10:04:21 CEST 2009


New submission from Sönke Schwardt-Krummrich <schwardt at univention.de>:

horde counts recurring events per week and not per incident. This gets a
problem if a recurring event with more than one incident per week is defined.
A recurring event with incidents on monday and friday with 3 incidents overall
is displayed correctly with 3 incidents over one and a half week in kontact
and Outlook. Without this patch horde displays 6 incidents over 3 weeks.

----------
files: t_kronolith_HK_UV_fixWeeklyRecurringEvents.diff
keyword: web client
messages: 21579
nosy: schwardt
priority: bug
status: unread
title: fix recurring events that are counted per week and not per incident

______________________________________
Kolab issue tracker <issues at kolab.org>
<https://issues.kolab.org/issue3846>
______________________________________
-------------- next part --------------
Patch by schwardt at univention.de (Tue Sep 8 17:35:43 2009 +0200):

kronolith: fix recurring events that are counted per week and not per incident

horde counts recurring events per week and not per incident. This gets a
problem if a recurring event with more than one incident per week is defined.
A recurring event with incidents on monday and friday with 3 incidents overall
is displayed correctly with 3 incidents over one and a half week in kontact
and Outlook. Without this patch horde displays 6 incidents over 3 weeks.

--- a/horde-webmail/kronolith/lib/Recurrence.php
+++ b/horde-webmail/kronolith/lib/Recurrence.php
@@ -379,6 +379,49 @@ class Horde_Date_Recurrence {
                 ceil($recur / 7) / $this->recurInterval >= $this->recurCount) {
                 return false;
             }
+            if (!$this->hasRecurEnd() && $this->recurCount > 0) {
+                $start_week_end = new Horde_Date($start_week);
+                $start_week_end->mday += 7;
+                $start_week_end->correct();
+                $recurrences = 0;
+                $total_recurrences_per_week = 0;
+                $next = new Horde_Date ($start_week);
+                while ($next->compareDateTime($start_week_end) < 0
+                    && $next->compareDateTime($after) < 0) {
+
+                    if ($this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                        $total_recurrences_per_week++;
+                        if ($next->compareDateTime($this->start) >= 0)
+                            $recurrences++;
+                    }
+                    ++$next->mday;
+                    $next->correct();
+                }
+                if ($recurrences >= $this->recurCount)
+                    return false;
+                if ($diff >= $this->recurInterval * 7) {
+                    // calculate the number of weeks between the start and the
+                    // end week
+                    $recurrences += ((int)floor(($diff/($this->recurInterval * 7))) - 1) * $total_recurrences_per_week;
+                    if ($recurrences >= $this->recurCount)
+                        return false;
+                    if ($diff % ($this->recurInterval * 7) == 0) {
+                        // the last week is in the interval - therefore the
+                        // recurrences in the week have to be counted also
+                        $next = new Horde_Date($after_week);
+                        while ($next->compareDateTime($after_week_end) < 0
+                            && $next->compareDateTime($after) < 0) {
+                            if ($this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                                $recurrences++;
+                            }
+                            ++$next->mday;
+                            $next->correct();
+                        }
+                    }
+                }
+                if ($recurrences >= $this->recurCount)
+                    return false;
+            }
             $next = $start_week;
             list($next->mday, $next->month, $next->year) = explode('/', Date_Calc::daysToDate(Date_Calc::dateToDays($next->mday, $next->month, $next->year) + $recur, '%e/%m/%Y'));
             $next = new Horde_Date($next);


More information about the devel mailing list