Fix datetime encoding when in UTC timezone
This commit is contained in:
parent
4700a07a89
commit
3bea790bd0
2 changed files with 15 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue