Bug #66705 [NEW]: format inaccurate after setTimezone
| From: | chris at codewiz dot biz | Date: | Thu, 13 Feb 2014 03:01:21 +0000 |
| Subject: | Bug #66705 [NEW]: format inaccurate after setTimezone | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-184277@lists.php.net to get a copy of this message | ||
From: chris at codewiz dot biz
Operating system:
PHP version: Irrelevant
Package: Date/time related
Bug Type: Bug
Bug description:format inaccurate after setTimezone
Description:
------------
---
From manual page: http://www.php.net/datetime.format
---
What is happening:
DateTime()->format() method strange behaviour after
DateTime->setTimezone().
Ignores the public date property, Expected return value (format mask
applied) should be based on the current public timezone and date
properties.
Format method should apply the argument format mask to the date property
based on current timezone property. Instead it appears that an
unknown/undocumented modification to the date property is applied.
test script outputs;
$nowUtc
object(DateTime)[2607]
public 'date' => string '2014-02-13 02:42:48' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
$nowUtc->format('Y-m-d h:i:s')
string '2014-02-13 02:42:48' (length=19)
$nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney' ) )
object(DateTime)[2608]
public 'date' => string '2014-02-13 13:42:48' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Australia/Sydney' (length=16)
$nowUtc->format('Y-m-d h:i:s')
string '2014-02-13 01:42:48' (length=19) // expected 2014-02-13 13:42:48
based on Australia/Sydney
What is 2014-02-13 01:42:48 from anyway!
Test script:
---------------
<?php
$nowUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' )
);
echo '$nowUtc'.PHP_EOL;
var_dump($nowUtc);
$nowUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' )
);
echo '$nowUtc->format(\'Y-m-d h:i:s\')'.PHP_EOL;
var_dump($nowUtc->format('Y-m-d h:i:s'));
$nowUtc->setTimezone( new \DateTimeZone( 'Australia/Sydney'
) );
echo '$nowUtc->setTimezone( new \DateTimeZone(
\'Australia/Sydney\' ) )'.PHP_EOL;
var_dump($nowUtc);
echo '$nowUtc->format(\'Y-m-d h:i:s\')'.PHP_EOL;
var_dump($nowUtc->format('Y-m-d h:i:s'));exit;
?>
Expected result:
----------------
format method should apply the argument format mask to the date property
based on current timezone property.
Actual result:
--------------
Instead it appears that an unknown/undocumented modification to the date
property is applied.
--
Edit bug report at https://bugs.php.net/bug.php?id=66705&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66705&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66705&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66705&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66705&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66705&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66705&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66705&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66705&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66705&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66705&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66705&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66705&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66705&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66705&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66705&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66705&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66705&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66705&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66705&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66705&r=mysqlcfg