From:
Operating system: Debian 5.0.3
PHP version: 5.3.5
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::createFromFormat's DateTimeZone parameter ignored
Description:
------------
I'm loading a DateTime object by a UNIX timestamp.
I assumed it would use the local timezone configured (e.g. date() behavior)
but it defaults to UTC.
When passing a DateTimeZone object into the third parameter of
DateTime::createFromFormat, it does nothing.
Setting the timezone using DateTime::setTimezone after the DateTime object
has loaded gives the correct result.
See examples.
Test script:
---------------
<?php
$time = 1293800400;
$tz = new DateTimeZone('Australia/Sydney');
// assumes local timezone
var_dump(date('r', $time));
// sets to "+00:00", should assume local timezone
var_dump(DateTime::createFromFormat('U', $time));
// sets to "+00:00", ignores given DateTimeZone object
var_dump(DateTime::createFromFormat('U', $time, $tz));
// adjusts to given timezone correctly
var_dump(DateTime::createFromFormat('U', $time)->setTimezone($tz));
Expected result:
----------------
string(31) "Sat, 01 Jan 2011 00:00:00 +1100"
object(DateTime)#2 (3) {
["date"]=>
string(19) "2011-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Australia/Sydney"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2011-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Australia/Sydney"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2011-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Australia/Sydney"
}
Actual result:
--------------
string(31) "Sat, 01 Jan 2011 00:00:00 +1100"
object(DateTime)#2 (3) {
["date"]=>
string(19) "2010-12-31 13:00:00"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2010-12-31 13:00:00"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2011-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Australia/Sydney"
}
--
Edit bug report at http://bugs.php.net/bug.php?id=53833&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53833&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53833&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53833&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53833&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53833&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53833&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53833&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53833&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53833&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53833&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53833&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53833&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53833&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53833&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53833&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53833&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53833&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53833&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53833&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53833&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53833&r=mysqlcfg