summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-10-21 15:14:11 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-10-21 15:15:26 (GMT)
commitb275e023f2828048eda2036c48506c96a687be4d (patch)
treece25a540bf86add5d7b3139cc6e71453f0e6a0aa /plugins
parent4808db21e122e5b08c238e17f03a30b3880573ef (diff)
downloadroundcubemail-plugins-kolab-b275e023f2828048eda2036c48506c96a687be4d.tar.gz
Fix computation of recurrence end date (#2393)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/libkolab/lib/kolab_date_recurrence.php27
-rw-r--r--plugins/libkolab/lib/kolab_storage_cache_event.php2
2 files changed, 24 insertions, 5 deletions
diff --git a/plugins/libkolab/lib/kolab_date_recurrence.php b/plugins/libkolab/lib/kolab_date_recurrence.php
index 3aaa399..85ffd91 100644
--- a/plugins/libkolab/lib/kolab_date_recurrence.php
+++ b/plugins/libkolab/lib/kolab_date_recurrence.php
@@ -101,16 +101,35 @@ class kolab_date_recurrence
/**
* 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')
+ public function end()
{
- $limit_dt = new DateTime($limit);
- if ($this->engine && ($cend = $this->engine->getLastOccurrence()) && ($end_dt = kolab_format::php_datetime(new cDateTime($cend))) && $end_dt < $limit_dt) {
+ $event = $this->object->to_array();
+
+ // recurrence end date is given
+ if ($event['recurrence']['UNTIL'] instanceof DateTime) {
+ return $event['recurrence']['UNTIL']->format('U');
+ }
+
+ // let libkolab do the work
+ if ($this->engine && ($cend = $this->engine->getLastOccurrence()) && ($end_dt = kolab_format::php_datetime(new cDateTime($cend)))) {
return $end_dt->format('U');
}
+ // determine a reasonable end date if none given
+ if (!$event['recurrence']['COUNT']) {
+ switch ($event['recurrence']['FREQ']) {
+ case 'YEARLY': $intvl = 'P100Y'; break;
+ case 'MONTHLY': $intvl = 'P20Y'; break;
+ default: $intvl = 'P10Y'; break;
+ }
+
+ $end_dt = clone $event['start'];
+ $end_dt->add(new DateInterval($intvl));
+ return $end_dt->format('U');
+ }
+
return false;
}
}
diff --git a/plugins/libkolab/lib/kolab_storage_cache_event.php b/plugins/libkolab/lib/kolab_storage_cache_event.php
index 69134e7..876c3b4 100644
--- a/plugins/libkolab/lib/kolab_storage_cache_event.php
+++ b/plugins/libkolab/lib/kolab_storage_cache_event.php
@@ -41,7 +41,7 @@ class kolab_storage_cache_event extends kolab_storage_cache
// extend date range for recurring events
if ($object['recurrence'] && $object['_formatobj']) {
$recurrence = new kolab_date_recurrence($object['_formatobj']);
- $sql_data['dtend'] = date('Y-m-d 23:59:59', $recurrence->end() ?: strtotime('now +1 year'));
+ $sql_data['dtend'] = date('Y-m-d 23:59:59', $recurrence->end() ?: strtotime('now +10 years'));
}
return $sql_data;