2 commits - plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Jul 4 15:56:27 CEST 2012


 plugins/libkolab/lib/kolab_date_recurrence.php |   28 ++++++++++++++++++++++++-
 plugins/libkolab/lib/kolab_format_event.php    |    8 +++++--
 plugins/libkolab/lib/kolab_storage_cache.php   |    3 +-
 3 files changed, 35 insertions(+), 4 deletions(-)

New commits:
commit 16770f3612d79b913926ea7b1f27faadb815f970
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Wed Jul 4 15:57:19 2012 +0200

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

diff --git a/plugins/libkolab/lib/kolab_date_recurrence.php b/plugins/libkolab/lib/kolab_date_recurrence.php
index 95dfedc..55cc8c3 100644
--- a/plugins/libkolab/lib/kolab_date_recurrence.php
+++ b/plugins/libkolab/lib/kolab_date_recurrence.php
@@ -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');
 
@@ -116,6 +116,32 @@ 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')
+    {
+        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
      */
     private function to_rrule($recurrence)
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 969d400..80a9342 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -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') {


commit 2aa05334e8ca9ad7bb97688ca66796d84f3ceaed
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Wed Jul 4 15:57:05 2012 +0200

    Fix timestamp-to-DateTime conversion

diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php
index 2242d83..0f792eb 100644
--- a/plugins/libkolab/lib/kolab_format_event.php
+++ b/plugins/libkolab/lib/kolab_format_event.php
@@ -282,8 +282,8 @@ class kolab_format_event extends kolab_format_xcal
             'title' => $rec['summary'],
             'location' => $rec['location'],
             'description' => $rec['body'],
-            'start' => new DateTime('@'.$rec['start-date'], self::$timezone),
-            'end'   => new DateTime('@'.$rec['end-date'], self::$timezone),
+            'start' => new DateTime('@'.$rec['start-date']),
+            'end'   => new DateTime('@'.$rec['end-date']),
             'allday' => $allday,
             'recurrence' => $rrule,
             'alarms' => $alarm_value . $alarm_unit,
@@ -295,5 +295,9 @@ class kolab_format_event extends kolab_format_xcal
             'sensitivity' => $rec['sensitivity'],
             'changed' => $rec['last-modification-date'],
         );
+
+        // assign current timezone to event start/end
+        $this->data['start']->setTimezone(self::$timezone);
+        $this->data['end']->setTimezone(self::$timezone);
     }
 }





More information about the commits mailing list