diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php index b4fdce32..f64499fb 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 c8911454..34044736 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;