php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27780 strtotime does not respect DST
Submitted: 2004-03-30 10:52 UTC Modified: 2005-10-21 11:37 UTC
From: Hua dot Qu at volvo dot com Assigned: derick
Status: Closed Package: Date/time related
PHP Version: 5.1.0RC3, 4.3.11 OS: Windows 2000, Cygwin
Private report: No CVE-ID:
 [2004-03-30 10:52 UTC] Hua dot Qu at volvo dot com
Description:
------------
strtotime($tm + 1 xxx) always adds one more hour to the result, if the result-time is in the summertime, no matter $tm is in the summertime or not.

It is the same in PHP CVS (5.0.x-dev) Built On: Mar 30, 2004 14:30 GMT

I think it is the daylight-savings-time problem. Perhaps, $tm is not checked if it is already in the daylight-savings-time. 

There are already some similar reports, but they did not get the point, and the bug has not been corrected untill  Mar 30, 2004 14:30 GMT.


Reproduce code:
---------------
echo "I have get one hour too much!<br><br>";

$to = "2004-06-01 00:00:00";
echo strtotime($to)."<br>\n";
echo strtotime("$to +1 seconds ")."<br><br>\n";
		
$newtime1 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 seconds "));
$newtime2   = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 day "));

echo "$to <br>\n";
echo "+1 s= $newtime1<br>\n";
echo "+1day=$newtime2<br><br>\n";
		
$correct = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 second -1 hour"));
echo "correct: +1 s=$correct<br>";


Expected result:
----------------
If $tm is the summertime, strtotime($tm +1 day) should return 24 hours more, not 25 hours more.

If $tm is the wintertime and result is in the summertime, it should return one extra hour. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-30 12:12 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to add timezone information to the original date. 
For example change your text time to "2004-06-01 00:00:00 
EST". 
 
The end result will be that strtotime($to) will be 1 
smaller then  strtotime("$to +1 seconds "), which is the 
correct output. 
 [2004-03-31 02:41 UTC] Hua dot Qu at volvo dot com

 [2004-03-31 02:56 UTC] derick@php.net
Right, this is a valid bug. 
 [2004-04-01 15:38 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Please test the snapshot (in 4 hours)!
 [2004-06-03 11:06 UTC] neilus at dcs dot kcl dot ac dot uk
this is re-occurring in the 4.3 tests, so either the test or bug needs to be fixed
 [2005-10-18 15:36 UTC] nohn@php.net
This reoccurs with 5.1.0RC3 on Cygwin.

The test expects

1076824799 [2004-02-14 23:59:59 CST] [2004-04-07 00:00:00 -2 months +7 days +23 
hours +59 minutes +59 seconds]

but the result is 

1076824799 [2004-02-14 23:59:59 GMT] [2004-04-07 00:00:00 -2 months +7 days +23 hour
s +59 minutes +59 seconds]

I suppose, the test case is broken here.
 [2005-10-21 11:37 UTC] derick@php.net
Nothing is broken here. Cygwin's strftime() simply doesn't support it.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC