Fix bug where it wasn't possible to change all-day event e.g. from one day to many days and vice-versa (Bifrost#T30559)

This commit is contained in:
Aleksander Machniak 2017-04-28 11:54:45 +02:00
parent 35eb29594d
commit c1c2b10e49

View file

@ -1141,11 +1141,11 @@ class kolab_driver extends calendar_driver
// use start date from master but try to be smart on time or duration changes
$old_start_date = $old['start']->format('Y-m-d');
$old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
$old_duration = $old['allday'] ? 0 : $old['end']->format('U') - $old['start']->format('U');
$old_duration = self::event_duration($old['start'], $old['end'], $old['allday']);
$new_start_date = $event['start']->format('Y-m-d');
$new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
$new_duration = $event['allday'] ? 0 : $event['end']->format('U') - $event['start']->format('U');
$new_duration = self::event_duration($event['start'], $event['end'], $event['allday']);
$diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;
$date_shift = $old['start']->diff($event['start']);
@ -1154,7 +1154,7 @@ class kolab_driver extends calendar_driver
if ($diff && ($old_start_date == $new_start_date || $old_duration == $new_duration)) {
$event['start'] = $master['start']->add($date_shift);
$event['end'] = clone $event['start'];
$event['end']->add(new DateInterval('PT'.$new_duration.'S'));
$event['end']->add(new DateInterval($new_duration));
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event()
if ($old_start_date != $new_start_date) {
@ -1230,6 +1230,19 @@ class kolab_driver extends calendar_driver
return $success;
}
/**
* Calculate event duration, returns string in DateInterval format
*/
protected static function event_duration($start, $end, $allday = false)
{
if ($allday) {
$diff = $start->diff($end);
return 'P' . $diff->days . 'D';
}
return 'PT' . ($end->format('U') - $start->format('U')) . 'S';
}
/**
* Determine whether the current change affects scheduling and reset attendee status accordingly
*/