Fix finding first occurrence for all-day events (Bifrost#T82770)

Bug caused e.g. annual all-day events not displayed on the first occurrence (start date)
This commit is contained in:
Aleksander Machniak 2018-03-16 15:16:04 +00:00
parent 77aa438b51
commit 700a64b40d
2 changed files with 35 additions and 8 deletions

View file

@ -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;
}

View file

@ -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') : '');
}
}