php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64155 Weird bug with time handling
Submitted: 2013-02-05 12:39 UTC Modified: 2015-01-22 01:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: espertalhao04 at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: any linux distro
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: espertalhao04 at hotmail dot com
New email:
PHP Version: OS:

 

 [2013-02-05 12:39 UTC] espertalhao04 at hotmail dot com
Description:
------------
There is a weird bug in time handling (strtotime and date) functions.
You must specify your timezone to perform operations with specified timezone!


There was no section to write this, so i put it here:

If there is a timezone specified, it should use it to treat this specific date.

Possible solution:
Verify if the timezone is valid, perform offset calculations and return the date.
This way, we would be sure that the date is in the same timezone as specified.

Test script:
---------------
<?=date('d-m-Y h:i:s',strtotime(date('d-m-Y h:i:s',strtotime('02:07:03  Feb  04,  2013  PST'))." GMT"))."<br>"?>
<?date_default_timezone_set('GMT')?>
<?=date('d-m-Y h:i:s',strtotime(date('d-m-Y h:i:s',strtotime('02:07:03  Feb  04,  2013  PST'))." GMT"));?>
<?=date_default_timezone_get()?>

Expected result:
----------------
04-02-2013 10:07:03
04-02-2013 10:07:03 GMT

Actual result:
--------------
04-02-2013 12:07:03
04-02-2013 10:07:03 GMT

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-15 00:28 UTC] neufeind@php.net
-Package: *General Issues +Package: Date/time related
 [2015-01-22 00:33 UTC] cmbecker69 at gmx dot de
I have rewritten your test script to be able to better explain the
behavior: <http://3v4l.org/I96tr>.

Independently of the default time zone, $time1 has the same value,
but $string1 differs for different default time zones, because
there is no time zone specified for the conversion (other than the
default time zone):

  $string1 = date('d-m-Y h:i:s', $time1);
  
The following results are logical consequences. So there is
clearly no weird bug in time handling, and certainly, specified
time zones are taken into account.
 [2015-01-22 01:31 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-01-22 01:31 UTC] requinix@php.net
That. The first date string will vary based on your original timezone as each date() will be formatting the timestamp according to it; since you use two of them and get a drift of +2 hours I suspect your timezone is GMT+1.

Once you do the date_default_timezone_set() to GMT (to match the timezone you're passing to strtotime()) the result will be stable at 10:07.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 07:01:32 2024 UTC