ID: 46641 User updated by: cross+php at distal dot com Reported By: cross+php at distal dot com Status: Bogus Bug Type: Date/time related Operating System: * PHP Version: 5CVS, 6CVS (2008-11-21) New Comment:
Okay. I can see this point, and thought something like that was involved, the transition through a timestamp. However, I would still like to know how to get 'T' (and 'e') to return what I expect. For example, I'd rather see 'EDT' than 'GMT-0500', and I still feel that '-05:00.0' instead of the expected long name may in fact be a [different] bug/error. Do you know how I can resolve this? It seems that setting the timezone of the DateTime causes the results of the 'T' and 'e' formatting parameter to work as expected. If I set the timezone to date_default_timezone_get, or assumedly anything else, it will return the format I expect for 'e' and 'T'. Is that the correct thing I should do to get the behaviour I expected? Thanks. Previous Comments: ------------------------------------------------------------------------ [2008-11-22 11:27:03] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is expected. Without converting to an integer with strtotime(), the DateTime object remembers which timezone it was created with. In this case the timezone it knows is "GMT-0500". If you use date(), this information is not available and it will use the default timezone. The following example shows this a bit better: [EMAIL PROTECTED]:/tmp$ cat bug46641.php <?php date_default_timezone_set('Europe/Oslo'); $timestr = "2008-11-19 10:51:35.199665-05"; $outformat = "M j Y H:i:s T (e,I,O,P,T,Z)"; $obj = new DateTime($timestr); print date($outformat, strtotime($timestr)) . "\n"; print $obj->format($outformat) . "\n"; ?> [EMAIL PROTECTED]:/tmp$ php bug46641.php Nov 19 2008 16:51:35 CET (Europe/Oslo,0,+0100,+01:00,CET,3600) Nov 19 2008 10:51:35 GMT-0500 (-05:00,0,-0500,-05:00,GMT-0500,-18000) ------------------------------------------------------------------------ [2008-11-21 17:46:13] cross+php at distal dot com Description: ------------ When using some of the timezone output format characters, notably "e" and "T", produce different results on a DateTime built from a string time and calling date() on the results of strtotime(). Reproduce code: --------------- <?php $timestr = "2008-11-19 10:51:35.199665-05"; $outformat = "M j Y H:i:s T (e,I,O,P,T,Z)"; $obj = new DateTime($timestr); print date($outformat, strtotime($timestr)) . "\n"; print $obj->format($outformat) . "\n"; ?> Expected result: ---------------- Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000) Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000) Actual result: -------------- Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000) Nov 19 2008 10:51:35 GMT-0500 (-05:00,0,-0500,-05:00,GMT-0500,-18000) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46641&edit=1
