From: Gunnar Wrobel Date: Mon, 9 Nov 2009 16:27:36 +0000 (+0100) Subject: Fix skipping weeks for recurring events that do not occur every other week. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=88e3374d5955ddf0b4b2a69a2a8dd80c9aaaacd8;p=horde.git Fix skipping weeks for recurring events that do not occur every other week. Bug: #8546 --- diff --git a/framework/Date/lib/Horde/Date/Recurrence.php b/framework/Date/lib/Horde/Date/Recurrence.php index b6e83eaf7..3d9ffd9b0 100644 --- a/framework/Date/lib/Horde/Date/Recurrence.php +++ b/framework/Date/lib/Horde/Date/Recurrence.php @@ -400,11 +400,25 @@ class Horde_Date_Recurrence $after_week_end->mday += 7; $diff = $start_week->diff($after_week); - $recur = $diff + ($diff % ($this->recurInterval * 7)); + $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; - if ($recur > 0) { + if ($repeats > 0) { $weekdays = $this->recurData; $total_recurrences_per_week = 0; while ($weekdays > 0) { @@ -413,7 +427,7 @@ class Horde_Date_Recurrence } $weekdays = ($weekdays - ($weekdays % 2)) / 2; } - $recurrences += $total_recurrences_per_week * ($recur / ($this->recurInterval * 7)); + $recurrences += $total_recurrences_per_week * $repeats; } } diff --git a/framework/Date/test/Horde/Date/RecurrenceTest.php b/framework/Date/test/Horde/Date/RecurrenceTest.php index 3cc11fbbe..267a3e1bf 100644 --- a/framework/Date/test/Horde/Date/RecurrenceTest.php +++ b/framework/Date/test/Horde/Date/RecurrenceTest.php @@ -32,7 +32,7 @@ class Horde_Date_RecurrenceTest extends PHPUnit_Framework_TestCase // This is a Thursday $next = new Horde_Date('2007-03-01 00:00:00'); while ($next = $r->nextRecurrence($next)) { - if (++$protect > 10) { + if (++$protect > 20) { return 'Infinite loop'; } $recurrences[] = (string)$next; @@ -109,7 +109,7 @@ class Horde_Date_RecurrenceTest extends PHPUnit_Framework_TestCase '2010-01-06 08:00:00', '2010-01-07 08:00:00', '2010-01-08 08:00:00', -), + ), $this->_getRecurrences($r), 'Test for bug #8546'); }