ID: 45167
Updated by: [EMAIL PROTECTED]
Reported By: peter dot bex at solide-ict dot nl
-Status: Open
+Status: Assigned
Bug Type: Date/time related
Operating System: NetBSD/amd64
PHP Version: 5.2.6
-Assigned To:
+Assigned To: derick
New Comment:
Not really a bug, as it wasn't meant to do this for anything else than
timezone objects of type 3 (identifiers) - but that doesn't mean we
can't add it.
Previous Comments:
------------------------------------------------------------------------
[2008-06-04 10:13:19] peter dot bex at solide-ict dot nl
Description:
------------
When creating a datetime object from a string that includes timezone
offset information (like "10:00:00+02:00"), the timezone object's name
can not be used for creating new timezone objects or setting the default
timezone. In effect, it's an "impossible object": there's no way to
recreate an object like that yourself.
This also means you would get unexpected results when using, for
example, strftime(). If you use date_default_timezone_set to change the
timezone to the object's timezone and print the date info, it will give
you the wrong output.
Reproduce code:
---------------
<?php
date_default_timezone_set('UTC');
echo "Before: ".date_default_timezone_get()."\n";
$foo = new datetime('10:00:00+02:00');
$name = $foo->getTimeZone()->getName();
echo "Setting timezone: $name\n";
date_default_timezone_set($name);
echo "After: ".date_default_timezone_get()."\n";
echo "strftime: ".strftime('%H:%M:%S', $foo->format('U'))."\n";
$bar = new datetimezone($name);
echo "datetimezone object name: ".$bar->getName();
?>
Expected result:
----------------
Before: UTC
Setting timezone: GMT+02
After: GMT+02
strftime: 10:00:00
datetimezone object name: GMT+02
(not sure if GMT+02 is the correct timezone name. In any case, it
should be some timezone name that's accepted by other timezone-related
functions/classes)
Actual result:
--------------
Before: UTC
Setting timezone: +02:00
After: UTC
strftime: 08:00:00
PHP Fatal error: Uncaught exception 'Exception' with message
'DateTimeZone::__construct(): Unknown or bad timezone (+02:00)' in
/path/to/index.php:10
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45167&edit=1