plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Mon Oct 21 17:15:59 CEST 2013
plugins/libkolab/lib/kolab_date_recurrence.php | 27 +++++++++++++++++----
plugins/libkolab/lib/kolab_storage_cache_event.php | 2 -
2 files changed, 24 insertions(+), 5 deletions(-)
New commits:
commit f001ae250bc60da7d3d30041b785c8f3492ac8e2
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Mon Oct 21 17:14:11 2013 +0200
Fix computation of recurrence end date (#2393)
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;
More information about the commits
mailing list