From: peter dot bex at solide-ict dot nl Operating system: NetBSD/amd64 PHP version: 5.2.6 PHP Bug Type: Date/time related Bug description: timezones returned by datetime objects are not accepted by other functions
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 bug report at http://bugs.php.net/?id=45167&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45167&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45167&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45167&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45167&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45167&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45167&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45167&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45167&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45167&r=support Expected behavior: http://bugs.php.net/fix.php?id=45167&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45167&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45167&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45167&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45167&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45167&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45167&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45167&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45167&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45167&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45167&r=mysqlcfg