php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69916 DateTime and bad behaviour with DateTimeZone
Submitted: 2015-06-23 22:57 UTC Modified: 2015-06-24 14:33 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: marcus at onlab dot org Assigned:
Status: Verified Package: Date/time related
PHP Version: 5.6.10 OS: *
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: marcus at onlab dot org
New email:
PHP Version: OS:

 

 [2015-06-23 22:57 UTC] marcus at onlab dot org
Description:
------------
Reproduced on PHP 5.6.10 (cli) (built: Jun 12 2015 10:07:24) osx Yosemit 10.10.3 Darwin Kernel Version 14.3.0, and PHP 5.5.23 (cli) (built: Mar 23 2015 01:47:37) 

php.ini
date.timezone => UTC => UTC


Reproduced on Amazon machines: PHP 5.6.10-1+deb.sury.org~trusty+1 (cli)


Test script:
---------------
More cases: https://gist.github.com/onlab/71a863feed01f79e7b7a

$baseDate = \DateTime::createFromFormat(\DateTime::ISO8601, '2015-06-23T18:00:00-0300');

echo '----- Everything works fine here -----' . PHP_EOL;
echo "SET America/Sao_Paulo \t" . $baseDate->format(\DateTime::ISO8601) . PHP_EOL;
$baseDate->setTimezone(new \DateTimeZone('America/Sao_Paulo'));

echo "SET GMT-3 \t\t" . $baseDate->format(\DateTime::ISO8601) . PHP_EOL;
$baseDate->setTimezone(new \DateTimeZone('GMT-3'));

echo "SET America/Sao_Paulo \t" . $baseDate->format(\DateTime::ISO8601) . PHP_EOL;
$baseDate->setTimezone(new \DateTimeZone('America/Sao_Paulo'));

echo '----- Time will be changed -3 hours (bug) -----' . PHP_EOL;
echo "SET America/Sao_Paulo \t" . $baseDate->format(\DateTime::ISO8601) . PHP_EOL;
$baseDate->setTimezone(new \DateTimeZone('America/Sao_Paulo'));

echo '----- Everything works fine here -----' . PHP_EOL;
echo "SET GMT-3 \t\t" . $baseDate->format(\DateTime::ISO8601) . PHP_EOL;
$baseDate->setTimezone(new \DateTimeZone('GMT-3'));

Expected result:
----------------
Regardless of the timezone I'm using, both represents GMT-3. So the result should be the below result in any result:

2015-06-23T18:00:00-0300

Actual result:
--------------
----- Everything works fine here -----
SET America/Sao_Paulo 	2015-06-23T18:00:00-0300
SET GMT-3 		2015-06-23T18:00:00-0300
SET America/Sao_Paulo 	2015-06-23T18:00:00-0300
----- Time will be changed -3 hours (bug) -----
SET America/Sao_Paulo 	2015-06-23T15:00:00-0300
----- Everything works fine here -----
SET GMT-3 		2015-06-23T15:00:00-0300

Patches

timezone-quickfix (last revision 2015-06-24 14:32 UTC) by cmb@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-23 23:10 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2015-06-23 23:10 UTC] requinix@php.net
Your output is backwards: you show the time before you change the timezone.

Not backwards: http://3v4l.org/8Gm26
Switching from GMT-3 to America/Sao_Paulo moves the hour -3 every time but the first.
 [2015-06-24 00:18 UTC] cmb@php.net
However, the documentation on other timezone identifiers[1] (such
as GMT-3) states:

| Please do not use any of the timezones listed here (besides
| UTC), they only exist for backward compatible reasons.

| If you disregard the above warning, please also note that the
| IANA timezone database that provides PHP's timezone support uses
| POSIX style signs, which results in the Etc/GMT+n and Etc/GMT-n
| time zones being reversed from common usage.

[1] <http://www.php.net/manual/en/timezones.others.php>
 [2015-06-24 05:32 UTC] marcus at onlab dot org
This means that I can't rely on DateTime formats to persist and work with it so PHP should deprecate this formats and suggest a new one that works, don't you think?

I tested each format and all of them have the same issue
(I can't post all links here due SPAM policy https://gist.github.com/anonymous/c4e4a482220ebe5f2055 )

ATOM http://3v4l.org/1idd6
 [2015-06-24 14:32 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: timezone-quickfix
Revision:   1435156337
URL:        https://bugs.php.net/patch-display.php?bug=69916&patch=timezone-quickfix&revision=1435156337
 [2015-06-24 14:33 UTC] cmb@php.net
-Operating System: osx +Operating System: *
 [2015-06-24 14:33 UTC] cmb@php.net
I just wanted to point out that showing misbehavior by using
deprecated and potentially unsupported timezone identifiers is not
necessarily an indication of a bug.

However, the test script on <http://3v4l.org/1idd6> clearly shows
a bug. I've simplified this a bit (<http://3v4l.org/ldOMb>), and,
interestingly, when commenting out line 9, the result is as
expected.

The attached patch (timezone-quickfix) is supposed to fix the
issue, but it rather feels like a workaround instead of a
solution.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC