gunnar: server/patches/horde-webmail/1.2.0/tg t_kronolith_HK_GW_FixWeeklyRecurringEvents.diff, NONE, 1.1.2.1 series, 1.5.2.9, 1.5.2.10

cvs at kolab.org cvs at kolab.org
Tue Nov 10 10:59:09 CET 2009


Author: gunnar

Update of /kolabrepository/server/patches/horde-webmail/1.2.0/tg
In directory doto:/tmp/cvs-serv4824/patches/horde-webmail/1.2.0/tg

Modified Files:
      Tag: kolab_2_2_branch
	series 
Added Files:
      Tag: kolab_2_2_branch
	t_kronolith_HK_GW_FixWeeklyRecurringEvents.diff 
Log Message:
 kolab/issue3846 (fix recurring events that are counted per week and not per incident) and upstream http://bugs.horde.org/ticket/8546

--- NEW FILE: t_kronolith_HK_GW_FixWeeklyRecurringEvents.diff ---
From: Gunnar Wrobel <p at rdus.de>
Subject: [PATCH] t/kronolith/HK/GW/FixWeeklyRecurringEvents

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.

Signed-off-by: Gunnar Wrobel <p at rdus.de>

---
 horde-webmail/kronolith/lib/Recurrence.php  |   57 ++++++++++++++++++++++++--
 horde-webmail/lib/Horde/Date/Recurrence.php |   57 ++++++++++++++++++++++++--
 2 files changed, 104 insertions(+), 10 deletions(-)

diff --git a/horde-webmail/kronolith/lib/Recurrence.php b/horde-webmail/kronolith/lib/Recurrence.php
index f22351d..5aa5960 100644
--- a/horde-webmail/kronolith/lib/Recurrence.php
+++ b/horde-webmail/kronolith/lib/Recurrence.php
@@ -374,18 +374,65 @@ class Horde_Date_Recurrence {
 
             $diff = Date_Calc::dateDiff($start_week->mday, $start_week->month, $start_week->year,
                                         $after_week->mday, $after_week->month, $after_week->year);
-            $recur = $diff + ($diff % ($this->recurInterval * 7));
-            if ($this->recurCount &&
-                ceil($recur / 7) / $this->recurInterval >= $this->recurCount) {
-                return false;
+            $interval = $this->recurInterval * 7;
+            $repeats = floor($diff / $interval);
+            if ($diff % $interval < 7) {
+                $recur = $diff;
+            } else {
+                /**
+                 * If the after_week is not in the first week interval the
+                 * search needs to skip ahead a complete interval. The way it is
+                 * calculated here means that an event that occurs every second
+                 * week on Monday and Wednesday with the event actually starting
+                 * on Tuesday or Wednesday will only have one incidence in the
+                 * first week.
+                 */
+                $recur = $interval * ($repeats + 1);
             }
+
+            if ($this->hasRecurCount()) {
+                $recurrences = 0;
+                /**
+                 * Correct the number of recurrences by the number of events
+                 * that lay between the start of the start week and the
+                 * recurrence start.
+                 */
+                $next = new Horde_Date($start_week);
+                while ($next->compareDateTime($this->start) < 0) {
+                    if ($this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                        $recurrences--;
+                    }
+                    ++$next->mday;
+                }
+                if ($repeats > 0) {
+                    $weekdays = $this->recurData;
+                    $total_recurrences_per_week = 0;
+                    while ($weekdays > 0) {
+                        if ($weekdays % 2) {
+                            $total_recurrences_per_week++;
+                        }
+                        $weekdays = ($weekdays - ($weekdays % 2)) / 2;
+                    }
+                    $recurrences += $total_recurrences_per_week * $repeats;
+                }
+            }
+
             $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'));
+            list($next->mday, $next->month, $next->year) = explode('/', Date_Calc::daysToDate(Date_Calc::dateToDays($next->mday, $next->month, $next->year) + $recur - 1, '%e/%m/%Y'));
             $next = new Horde_Date($next);
             while ($next->compareDateTime($after) < 0 &&
                    $next->compareDateTime($after_week_end) < 0) {
                 ++$next->mday;
                 $next->correct();
+                if ($this->hasRecurCount()
+                    && $next->compareDateTime($after) < 0
+                    && $this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                    $recurrences++;
+                }
+            }
+            if ($this->hasRecurCount() &&
+                $recurrences >= $this->recurCount) {
+                return false;
             }
             if (!$this->hasRecurEnd() ||
                 $next->compareDateTime($this->recurEnd) <= 0) {
diff --git a/horde-webmail/lib/Horde/Date/Recurrence.php b/horde-webmail/lib/Horde/Date/Recurrence.php
index 9dbf057..e21193f 100644
--- a/horde-webmail/lib/Horde/Date/Recurrence.php
+++ b/horde-webmail/lib/Horde/Date/Recurrence.php
@@ -374,18 +374,65 @@ class Horde_Date_Recurrence {
 
             $diff = Date_Calc::dateDiff($start_week->mday, $start_week->month, $start_week->year,
                                         $after_week->mday, $after_week->month, $after_week->year);
-            $recur = $diff + ($diff % ($this->recurInterval * 7));
-            if ($this->recurCount &&
-                ceil($recur / 7) / $this->recurInterval >= $this->recurCount) {
-                return false;
+            $interval = $this->recurInterval * 7;
+            $repeats = floor($diff / $interval);
+            if ($diff % $interval < 7) {
+                $recur = $diff;
+            } else {
+                /**
+                 * If the after_week is not in the first week interval the
+                 * search needs to skip ahead a complete interval. The way it is
+                 * calculated here means that an event that occurs every second
+                 * week on Monday and Wednesday with the event actually starting
+                 * on Tuesday or Wednesday will only have one incidence in the
+                 * first week.
+                 */
+                $recur = $interval * ($repeats + 1);
             }
+
+            if ($this->hasRecurCount()) {
+                $recurrences = 0;
+                /**
+                 * Correct the number of recurrences by the number of events
+                 * that lay between the start of the start week and the
+                 * recurrence start.
+                 */
+                $next = new Horde_Date($start_week);
+                while ($next->compareDateTime($this->start) < 0) {
+                    if ($this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                        $recurrences--;
+                    }
+                    ++$next->mday;
+                }
+                if ($repeats > 0) {
+                    $weekdays = $this->recurData;
+                    $total_recurrences_per_week = 0;
+                    while ($weekdays > 0) {
+                        if ($weekdays % 2) {
+                            $total_recurrences_per_week++;
+                        }
+                        $weekdays = ($weekdays - ($weekdays % 2)) / 2;
+                    }
+                    $recurrences += $total_recurrences_per_week * $repeats;
+                }
+            }
+
             $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'));
+            list($next->mday, $next->month, $next->year) = explode('/', Date_Calc::daysToDate(Date_Calc::dateToDays($next->mday, $next->month, $next->year) + $recur - 1, '%e/%m/%Y'));
             $next = new Horde_Date($next);
             while ($next->compareDateTime($after) < 0 &&
                    $next->compareDateTime($after_week_end) < 0) {
                 ++$next->mday;
                 $next->correct();
+                if ($this->hasRecurCount()
+                    && $next->compareDateTime($after) < 0
+                    && $this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
+                    $recurrences++;
+                }
+            }
+            if ($this->hasRecurCount() &&
+                $recurrences >= $this->recurCount) {
+                return false;
             }
             if (!$this->hasRecurEnd() ||
                 $next->compareDateTime($this->recurEnd) <= 0) {
-- 
tg: (01f4e60..) t/kronolith/HK/GW/FixWeeklyRecurringEvents (depends on: t/kronolith/HK/UV/dateInputFieldOrder)
-- 
TOPGIT patch commit log
=======================

commit ecde0d9b33f53d7ed3a3d5bdd358118213d4abe1
Author: Gunnar Wrobel <p at rdus.de>
Date:   Tue Nov 10 10:38:20 2009 +0100

    Another fix for another corner case.

commit 3b0550f0c84354d9210fa097397af9cd424d8c35
Author: Gunnar Wrobel <p at rdus.de>
Date:   Tue Nov 10 09:46:38 2009 +0100

    Fix another problem found when testing recurrences with multiple incidences per week.

commit c5b9c97a29db689afadf411fa2eacce06b3e9022
Author: Gunnar Wrobel <p at rdus.de>
Date:   Tue Nov 10 08:09:47 2009 +0100

    Remove stray patch file.

commit 1d1005e3b0e81a0b74edaca7b242919e8f79336f
Author: Gunnar Wrobel <p at rdus.de>
Date:   Tue Nov 10 07:25:22 2009 +0100

     kolab/issue3846 (fix recurring events that are counted per week and not per incident)

Index: series
===================================================================
RCS file: /kolabrepository/server/patches/horde-webmail/1.2.0/tg/Attic/series,v
retrieving revision 1.5.2.9
retrieving revision 1.5.2.10
diff -u -d -r1.5.2.9 -r1.5.2.10
--- series	5 Nov 2009 11:14:09 -0000	1.5.2.9
+++ series	10 Nov 2009 09:59:07 -0000	1.5.2.10
@@ -74,3 +74,4 @@
 t_kronolith_HK_GW_AnonymousiCalDownload.diff -p1
 t_kronolith_HK_GW_ExportEventList.diff -p1
 t_kronolith_HK_UV_dateInputFieldOrder.diff -p1
+t_kronolith_HK_GW_FixWeeklyRecurringEvents.diff -p1





More information about the commits mailing list