Bug #66705 [Opn]: format inaccurate after setTimezone
| From: | chris at codewiz dot biz | Date: | Thu, 13 Feb 2014 03:03:44 +0000 |
| Subject: | Bug #66705 [Opn]: format inaccurate after setTimezone | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184278@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66705&edit=1
ID: 66705
User updated by: chris at codewiz dot biz
Reported by: chris at codewiz dot biz
Summary: format inaccurate after setTimezone
Status: Open
Type: Bug
Package: Date/time related
-Operating System:
+Operating System: Ubuntu 13.10
-PHP Version: Irrelevant
+PHP Version: 5.5.3
Block user comment: N
Private report: N
New Comment:
fixed version and os
Previous Comments:
------------------------------------------------------------------------
[2014-02-13 03:01:20] chris at codewiz dot biz
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 this bug report at https://bugs.php.net/bug.php?id=66705&edit=1