diff --git a/plugins/libkolab/lib/kolab_date_recurrence.php b/plugins/libkolab/lib/kolab_date_recurrence.php index a9a04cbc..2ec06c8a 100644 --- a/plugins/libkolab/lib/kolab_date_recurrence.php +++ b/plugins/libkolab/lib/kolab_date_recurrence.php @@ -140,7 +140,7 @@ class kolab_date_recurrence } /** - * Find date/time of the first occurrence (excluding start date) + * Find date/time of the first occurrence */ public function first_occurrence() { @@ -196,11 +196,17 @@ class kolab_date_recurrence $object->set($event); $recurrence = new self($object); + $orig_date = $orig_start->format('Y-m-d'); + $found = false; + // find the first occurrence - $found = false; while ($next = $recurrence->next_start()) { $start = $next; - if ($next >= $orig_start) { + if ($next->format('Y-m-d') >= $orig_date) { + if ($event['allday']) { + $next->setTime($orig_start->format('G'), $orig_start->format('i'), $orig_start->format('s')); + } + $found = true; break; } @@ -217,7 +223,7 @@ class kolab_date_recurrence return null; } - if ($orig_start->_dateonly) { + if ($event['allday']) { $start->_dateonly = true; } diff --git a/plugins/libkolab/tests/kolab_date_recurrence.php b/plugins/libkolab/tests/kolab_date_recurrence.php index 8fd57b2c..9ea3db7b 100644 --- a/plugins/libkolab/tests/kolab_date_recurrence.php +++ b/plugins/libkolab/tests/kolab_date_recurrence.php @@ -157,13 +157,13 @@ class kolab_date_recurrence_test extends PHPUnit_Framework_TestCase // yearly array( array('FREQ' => 'YEARLY', 'INTERVAL' => '1'), - '2017-08-16 11:00:00', - '2017-08-16 11:00:00', + '2017-08-16 12:00:00', + '2017-08-16 12:00:00', ), array( array('FREQ' => 'YEARLY', 'INTERVAL' => '1', 'BYMONTH' => '8'), - '2017-08-16 11:00:00', - '2017-08-16 11:00:00', + '2017-08-16 12:00:00', + '2017-08-16 12:00:00', ), array( array('FREQ' => 'YEARLY', 'INTERVAL' => '1', 'BYDAY' => '-1MO'), @@ -209,5 +209,26 @@ class kolab_date_recurrence_test extends PHPUnit_Framework_TestCase ); } + /** + * kolab_date_recurrence::first_occurrence() for all-day events + * + * @dataProvider data_first_occurrence + */ + function test_first_occurrence_allday($recurrence_data, $start, $expected) + { + $start = new DateTime($start); + if (!empty($recurrence_data['UNTIL'])) { + $recurrence_data['UNTIL'] = new DateTime($recurrence_data['UNTIL']); + } + + $event = array('start' => $start, 'recurrence' => $recurrence_data, 'allday' => true); + $object = kolab_format::factory('event', 3.0); + $object->set($event); + + $recurrence = new kolab_date_recurrence($object); + $first = $recurrence->first_occurrence(); + + $this->assertEquals($expected, $first ? $first->format('Y-m-d H:i:s') : ''); + } }