php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66294 Timezone display and Timestamps are incorrect when using GMT+/- timezones
Submitted: 2013-12-14 07:18 UTC Modified: 2017-03-19 11:27 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: jrossiter at dlvr dot it Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.5.7 OS: Ubuntu 13.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jrossiter at dlvr dot it
New email:
PHP Version: OS:

 

 [2013-12-14 07:18 UTC] jrossiter at dlvr dot it
Description:
------------
Creating a new DateTime object using a fixed string with a "GMT(+/-)nn" timezone (e.g. "GMT+12" or "GMT-10") results in the correct date and time being displayed, with but a badly formatted timezone ("GMT+1200", "GMT-1000")

(A note if the reader isn't aware... the Etc/GMT timezones actually perform the opposite of what they appear to be requesting.  GMT+12 is actually GMT minus 12 hours, and GMT-10 is actually GMT plus 10 hours)

The unix timestamp returned by this object is incorrect by 2*offset.  So, the GMT+12 returns a timestamp decremented 24 hours.  The GMT-10 returns a date/time incremented by 20 hours.

Creating a new DateTime object and passing in a DateTimeZone object using an Etc/GMT(+/-)nn (e.g.  "Etc/GMT+12") timezone displays timestamps and formatted timezone as expected.

Test script:
---------------
foreach (['Etc/GMT+12', 'Etc/GMT-10'] as $timezone) {
    $dTZ = new DateTimeZone($timezone);

    // Create a DateTime using the DateTimeZone object
    // This will display both formatted and unix timestamp as expected
    $dT = new DateTime('2013-12-13 18:49:00', $dTZ);
    echo $dT->format('Y-m-d H:i:s T'), PHP_EOL;
    echo $dT->getTimestamp(), PHP_EOL;


    // Create a DateTime using only a string representation
    // This will display the formatted date/time as expected, 
    // but with the incorrect timezone
    // The value returned by getTimestamp() for format('U') will
    // be off by 2*offset
    $dT2 = new DateTime($dT->format('Y-m-d H:i:s T'));
    echo $dT2->format('Y-m-d H:i:s T'), PHP_EOL;
    echo $dT2->getTimestamp(), PHP_EOL, PHP_EOL;
}

Expected result:
----------------
2013-12-13 18:49:00 GMT+12
1387003740
2013-12-13 18:49:00 GMT+12
1387003740

2013-12-13 18:49:00 GMT-10
1386924540
2013-12-13 18:49:00 GMT-10
1386924540


Actual result:
--------------
2013-12-13 18:49:00 GMT+12
1387003740
2013-12-13 18:49:00 GMT+1200
1386917340

2013-12-13 18:49:00 GMT-10
1386924540
2013-12-13 18:49:00 GMT-1000
1386996540

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-08 14:47 UTC] cmb@php.net
Confirmed: <https://3v4l.org/RCA06>.

However, the manual strongly advises against using the Etc/GMT*
timezones[1], so I suppose that this issue won't be fixed.

[1] <http://www.php.net/manual/en/timezones.others.php>
 [2017-03-19 11:27 UTC] heiglandreas@php.net
-Status: Open +Status: Wont fix
 [2017-03-19 11:27 UTC] heiglandreas@php.net
As already pointed out, you are advised to *not* use the GMT-Timezone identifiers as stated at http://www.php.net/manual/en/timezones.others.php.

Therefore we won't fix this issue!
 [2017-03-22 16:59 UTC] krossiter at dlvr dot it
There was no such proscription at the time the bug was filed.

Also, since these are valid timezones, they should be operating as expected.  The user cannot always define what format they receive timezone strings in, and being required to add significant special-case handling of the Etc/UTC timezones is ridiculous.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 21:03:16 2021 UTC