2 commits - plugins/libcalendaring

Thomas Brüderli bruederli at kolabsys.com
Wed Sep 25 17:13:08 CEST 2013


 plugins/libcalendaring/libvcalendar.php       |    3 ++-
 plugins/libcalendaring/tests/libvcalendar.php |   13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

New commits:
commit e9b20a23bc846126045e7a8a08ecb00bf5134426
Merge: 3bea790 6556c1a
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Sep 25 17:12:44 2013 +0200

    Merge branch 'master' of ssh://git.kolab.org/git/roundcubemail-plugins-kolab



commit 3bea790bd05cff4ce5ce6e62a84a5f3aa4758dad
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Sep 25 17:12:27 2013 +0200

    Fix datetime encoding when in UTC timezone

diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php
index b4fdce3..f64499f 100644
--- a/plugins/libcalendaring/libvcalendar.php
+++ b/plugins/libcalendaring/libvcalendar.php
@@ -576,9 +576,10 @@ class libvcalendar
      */
     public static function datetime_prop($name, $dt, $utc = false, $dateonly = null)
     {
+        $is_utc = $utc || (($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC','GMT','Z')));
         $vdt = new VObject\Property\DateTime($name);
         $vdt->setDateTime($dt, $dt->_dateonly || $dateonly ? VObject\Property\DateTime::DATE :
-            ($utc ? VObject\Property\DateTime::UTC : VObject\Property\DateTime::LOCALTZ));
+            ($is_utc ? VObject\Property\DateTime::UTC : VObject\Property\DateTime::LOCALTZ));
         return $vdt;
     }
 
diff --git a/plugins/libcalendaring/tests/libvcalendar.php b/plugins/libcalendaring/tests/libvcalendar.php
index c891145..3404473 100644
--- a/plugins/libcalendaring/tests/libvcalendar.php
+++ b/plugins/libcalendaring/tests/libvcalendar.php
@@ -323,6 +323,19 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
         $this->assertEquals($num, substr_count($output, 'END:VEVENT'),   "VEVENT encapsulation END");
     }
 
+    function test_datetime()
+    {
+        $localtime = libvcalendar::datetime_prop('DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('Europe/Berlin')));
+        $localdate = libvcalendar::datetime_prop('DTSTART', new DateTime('2013-09-01', new DateTimeZone('Europe/Berlin')), false, true);
+        $utctime   = libvcalendar::datetime_prop('DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('UTC')));
+        $asutctime = libvcalendar::datetime_prop('DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('Europe/Berlin')), true);
+
+        $this->assertContains('TZID=Europe/Berlin', $localtime->serialize());
+        $this->assertContains('VALUE=DATE', $localdate->serialize());
+        $this->assertContains('20130901T120000Z', $utctime->serialize());
+        $this->assertContains('20130901T100000Z', $asutctime->serialize());
+    }
+
     function get_attachment_data($id, $event)
     {
         return $this->attachment_data;




More information about the commits mailing list