Bug #64155 [Opn->Nab]: Weird bug with time handling
| From: | requinix@php.net | Date: | Thu, 22 Jan 2015 01:31:23 +0000 |
| Subject: | Bug #64155 [Opn->Nab]: Weird bug with time handling | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190126@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64155&edit=1
ID: 64155
Updated by: requinix@php.net
Reported by: espertalhao04 at hotmail dot com
Summary: Weird bug with time handling
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: any linux distro
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2015-01-22 00:33:55] 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.
------------------------------------------------------------------------
[2013-02-05 12:39:48] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64155&edit=1