Compute the real end date-time of a recurring event for caching

This commit is contained in:
Thomas Bruederli 2012-07-04 15:57:19 +02:00
parent 2aa05334e8
commit 16770f3612
2 changed files with 29 additions and 2 deletions

View file

@ -45,7 +45,7 @@ class kolab_date_recurrence
$this->next = new Horde_Date($object['start'], kolab_format::$timezone->getName());
if (is_object($object['start']) && is_object($object['end']))
$this->duration = $object['end']->diff($object['start']);
$this->duration = $object['start']->diff($object['end']);
else
$this->duration = new DateInterval('PT' . ($object['end'] - $object['start']) . 'S');
@ -115,6 +115,32 @@ class kolab_date_recurrence
return false;
}
/**
* Get the end date of the occurence of this recurrence cycle
*
* @param string Date limit (where infinite recurrences should abort)
* @return mixed Timestamp with end date of the last event or False if recurrence exceeds limit
*/
public function end($limit = 'now +1 year')
{
if ($this->object['recurrence']['UNTIL'])
return $this->object['recurrence']['UNTIL'];
$limit_time = strtotime($limit);
while ($next_start = $this->next_start(true)) {
if ($next_start > $limit_time)
break;
}
if ($this->next) {
$next_end = $this->next->toDateTime();
$next_end->add($this->duration);
return $next_end->format('U');
}
return false;
}
/**
* Convert the internal structured data into a vcalendar RRULE 2.0 string
*/

View file

@ -514,7 +514,8 @@ class kolab_storage_cache
// extend date range for recurring events
if ($object['recurrence']) {
$sql_data['dtend'] = date('Y-m-d H:i:s', $object['recurrence']['UNTIL'] ?: strtotime('now + 2 years'));
$recurrence = new kolab_date_recurrence($object);
$sql_data['dtend'] = date('Y-m-d H:i:s', $recurrence->end() ?: strtotime('now +1 year'));
}
}
else if ($objtype == 'task') {