Req #45543 [Asn->Csd]: DateTime::setTimezone can not set timezones without ID

From: Date: Sun, 26 Jan 2014 13:03:24 +0000
Subject: Req #45543 [Asn->Csd]: DateTime::setTimezone can not set timezones without ID
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184013@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=45543&edit=1

 ID:                 45543
 Updated by:         derick@php.net
 Reported by:        tj at systisoft dot com
 Summary:            DateTime::setTimezone can not set timezones without
                     ID
-Status:             Assigned
+Status:             Closed
 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:

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.


Previous Comments:
------------------------------------------------------------------------
[2013-02-26 19:49:22] 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.

------------------------------------------------------------------------
[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

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=45543


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=45543&edit=1


Thread (10 messages)

« previous php.bugs (#184013) next »