ID:               45543
 User updated by:  tj at systisoft dot com
-Summary:          DateTime::setTimezone kann not set timezones without
                   ID
 Reported By:      tj at systisoft dot com
 Status:           Open
-Bug Type:         Date/time related
+Bug Type:         Feature/Change Request
-Operating System: Mac OS X
+Operating System: All
 PHP Version:      5.3CVS-2008-07-17 (CVS)
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[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 http://bugs.php.net/?id=45543&edit=1

Reply via email to