php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45543 DateTime::setTimezone can not set timezones without ID
Submitted: 2008-07-17 13:07 UTC Modified: 2014-07-30 10:52 UTC
Votes:19
Avg. Score:4.4 ± 0.7
Reproduced:19 of 19 (100.0%)
Same Version:4 (21.1%)
Same OS:10 (52.6%)
From: tj at systisoft dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3CVS-2008-07-17 (CVS) OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tj at systisoft dot com
New email:
PHP Version: OS:

 

 [2008-07-17 13:07 UTC] tj at systisoft dot com
Description:
------------
if you set a time zone for a DateTime via DateTime::setTimeZone() and that time zone has no ID you get an error message and the time zone will not be set.

This can lead to Problems if you have two DateTime objects from a surce you do not control and want to format the secont DateTime object in the same time zone as the first.

Reproduce code:
---------------
$d1 = new DateTime('2008-01-01 12:00:00 +02:00');
$d2 = new DateTime('2008-01-01 12:00:00 UTC');
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
$d2->setTimeZone($d1->getTimeZone());
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;

Expected result:
----------------
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
2008-01-01T12:00:00+0200
2008-01-01T14:00:00+0200

Actual result:
--------------
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
PHP Warning:  DateTime::setTimezone(): Can only do this for zones with ID for now in /Users/tobias/test.php on line 5

Warning: DateTime::setTimezone(): Can only do this for zones with ID for now in /Users/tobias/test.php on line 5
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-17 14:34 UTC] tj at systisoft dot com
Description:
------------
If you set a time zone for a DateTime via DateTime::setTimeZone() and that time zone has no ID you get an error message and the time zone will not be set.

This can lead to problems if you have two DateTime objects from a source you do not control and want to format the second DateTime object in the same time zone as the first.

Reproduce code:
---------------
$d1 = new DateTime('2008-01-01 12:00:00 +02:00');
$d2 = new DateTime('2008-01-01 12:00:00 UTC');
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
$d2->setTimeZone($d1->getTimeZone());
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;

Expected result:
----------------
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
2008-01-01T12:00:00+0200
2008-01-01T14:00:00+0200

Actual result:
--------------
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
PHP Warning:  DateTime::setTimezone(): Can only do this for zones with
ID for now in /Users/tobias/test.php on line 5

Warning: DateTime::setTimezone(): Can only do this for zones with ID for
now in /Users/tobias/test.php on line 5
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
 [2009-06-29 16:25 UTC] scott at crisscott dot com
I was able to reproduce this with PHP 5.2.9 from the commandline. 

php -v
PHP 5.2.9 (cli) (built: May  1 2009 13:47:24) 

$> php -r '$d = new DateTime("2009-01-01 00:00:00+0400"); $d->setTimezone($d->getTimezone());'
 [2010-12-20 14:26 UTC] jani@php.net
-Package: Feature/Change Request +Package: Date/time related
 [2011-01-08 19:56 UTC] wrzasq at gmail dot com
I confirm the same on PHP 5.3.3, Debian 64bit.
 [2013-01-02 20:11 UTC] info at strictcoding dot co dot uk
Still the same in PHP 5.4.10.
This bug is more than 4 years old, could it be looked into?
 [2013-02-26 19:49 UTC] rrollins at caltech dot edu
I'm getting this warning when trying to set a DateTime's timezone to 
"America/Los_Angeles". I don't know what an ID is in this context, but surely 
America/Los_Angeles has one... right? I'm using PHP 5.3.21 on OSX Mountain Lion.
 [2014-01-26 13:03 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 [2014-01-26 13:03 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2014-01-26 13:04 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 [2014-01-28 10:40 UTC] ab@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 [2014-02-12 08:46 UTC] tyrael@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 [2014-07-30 10:48 UTC] phil at patient-radio dot de
Great to see it fixed - but confused in which release though :/

Bug 45543 is not referenced on the changelog (http://php.net/ChangeLog-5.php) - try&error tells me that on 5.4.31 the problem's gone, while on 5.3.23 (the machine on which i just happened to see this for the first time ever) it isn't.

Judging from the latest 5.3.28 release date i reckon it's not fixed in that (?)

It would be really important to know at this point which version to jump to - this way i'm doomed to work around the error, as i'm deploying to a customers' managed server and cannot be sure which available version will fix it.
 [2014-07-30 10:52 UTC] derick@php.net
http://3v4l.org/mlZX7 indicates 5.4.26 and 5.5.10.
 [2014-10-07 23:16 UTC] stas@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 [2014-10-07 23:27 UTC] stas@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=22dba2f5f3211efe6c3b9bb24734c811ca64c68c
Log: Fixed bug #45543: DateTime::setTimezone can not set timezones without ID.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC