Bug #67302 [Com]: DateTime->setTimezone does not set TZ correctly
| From: | arjen at react dot com | Date: | Fri, 23 May 2014 08:00:06 +0000 |
| Subject: | Bug #67302 [Com]: DateTime->setTimezone does not set TZ correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185908@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67302&edit=1
ID: 67302
Comment by: arjen at react dot com
Reported by: alan at bulbstudios dot com
Summary: DateTime->setTimezone does not set TZ correctly
Status: Open
Type: Bug
Package: Date/time related
Operating System: OSX, Debian GNU/Linux
PHP Version: 5.5.12
Block user comment: N
Private report: N
New Comment:
Already reported in https://bugs.php.net/bug.php?id=67077
Previous Comments:
------------------------------------------------------------------------
[2014-05-20 11:24:26] arjen at react dot com
DateTimeZone objects cannot be constructed by passing a timezone abbreviation anymore since 5.5.10:
http://3v4l.org/Ui5ab#v5510
Probably broken by https://bugs.php.net/bug.php?id=45543
------------------------------------------------------------------------
[2014-05-19 15:02:35] alan at bulbstudios dot com
Another test case that shows the time is preserved when using a cloned DateTime, and also that the
DateTimeZone offsets appear to be causing issues: http://3v4l.org/QpJYP
------------------------------------------------------------------------
[2014-05-19 14:12:28] alan at bulbstudios dot com
A multi-version test case is available at: http://3v4l.org/mvReq
------------------------------------------------------------------------
[2014-05-19 12:24:05] alan at bulbstudios dot com
The test script is actually:
#!/usr/bin/env php
<?php
date_default_timezone_set('UTC');
echo date_default_timezone_get(), PHP_EOL;
$utc = new DateTimeZone('UTC');
$time = DateTime::createFromFormat('Y-m-d H:i:s', '2014-05-19 11:30:00');
foreach (['BST', 'Etc/GMT+1', 'GMT+1', 'CEST'] as $abbr) {
$time->setTimezone(new DateTimeZone($abbr));
echo "{$abbr}: {$time->format(DATE_RFC822)}", PHP_EOL;
}
------------------------------------------------------------------------
[2014-05-19 12:19:19] alan at bulbstudios dot com
Description:
------------
Setting a timezone of either BST, GMT+1, Etc/GMT+1 or CEST on a DateTime object seems to modify the
time of the object and set the timezone incorrectly.
Works fine on PHP 5.4.28, barring the missing GMT+1.
Test script:
---------------
#!/usr/bin/env php
<?php
echo date_default_timezone_get(), PHP_EOL;
$utc = new DateTimeZone('UTC');
$time = DateTime::createFromFormat('Y-m-d H:i:s', '2014-05-19 11:30:00');
foreach (['BST', 'GMT+1', 'CEST'] as $abbr) {
$time->setTimezone(new DateTimeZone($abbr));
echo "{$abbr}: {$time->format(DATE_RFC822)}", PHP_EOL;
}
Expected result:
----------------
UTC
BST: Mon, 19 May 14 12:30:00 +0100
Etc/GMT+1: Mon, 19 May 14 12:30:00 +0100
GMT+1: Mon, 19 May 14 12:30:00 +0100
CEST: Mon, 19 May 14 14:30:00 +0200
Actual result:
--------------
UTC
BST: Mon, 19 May 14 12:30:00 +0100
Etc/GMT+1: Mon, 19 May 14 11:30:00 -0100
GMT+1: Mon, 19 May 14 13:30:00 +0100
CEST: Mon, 19 May 14 14:30:00 +0100
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67302&edit=1