Edit report at https://bugs.php.net/bug.php?id=45543&edit=1
ID: 45543
Comment by: rrollins at caltech dot edu
Reported by: tj at systisoft dot com
Summary: DateTime::setTimezone can not set timezones without
ID
Status: Assigned
Type: Feature/Change Request
Package: Date/time related
Operating System: All
PHP Version: 5.3CVS-2008-07-17 (CVS)
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-01-02 20:11:57] 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?
------------------------------------------------------------------------
[2011-01-08 19:56:01] wrzasq at gmail dot com
I confirm the same on PHP 5.3.3, Debian 64bit.
------------------------------------------------------------------------
[2009-06-29 16:25:01] 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());'
------------------------------------------------------------------------
[2008-07-17 14:34:47] 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
------------------------------------------------------------------------
[2008-07-17 13:07:47] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45543&edit=1