php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30532 strtotime - crossing daylight savings time
Submitted: 2004-10-22 17:33 UTC Modified: 2005-06-16 21:31 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rbro at hotmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.*, 4.* OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rbro at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-10-22 17:33 UTC] rbro at hotmail dot com
Description:
------------
In the US, Daylight Savings Time ends on October 31, 2004 at 2am where clocks are then reset back to 1am.  I am in the Eastern time zone.  If I run the following script where I'm adding 1 hour, 2 hours, and 3 hours to the date 2004-10-31, I'm getting different results from including EDT in the date or not, when I thought that strtotime() defaults to the local timezone.

Reproduce code:
---------------
<?php
echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +1 hour'))."\n";
echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +2 hours'))."\n";
echo date('Y-m-d H:i:s', strtotime('2004-10-31 EDT +3 hours'))."\n";

echo "\n";

echo date('Y-m-d H:i:s', strtotime('2004-10-31 +1 hour'))."\n";
echo date('Y-m-d H:i:s', strtotime('2004-10-31 +2 hours'))."\n";
echo date('Y-m-d H:i:s', strtotime('2004-10-31 +3 hours'))."\n";
?>


Expected result:
----------------
2004-10-31 01:00:00
2004-10-31 01:00:00
2004-10-31 02:00:00

2004-10-31 01:00:00
2004-10-31 01:00:00
2004-10-31 02:00:00

Actual result:
--------------
2004-10-31 01:00:00
2004-10-31 01:00:00
2004-10-31 02:00:00

2004-10-31 01:00:00
2004-10-31 02:00:00
2004-10-31 03:00:00


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-22 22:32 UTC] rbro at hotmail dot com
Further information: The following script does give the expected results:

<?php
echo date('Y-m-d H:i:s', strtotime('+1 hour', strtotime('2004-10-31')))."\n";
echo date('Y-m-d H:i:s', strtotime('+2 hours', strtotime('2004-10-31')))."\n";
echo date('Y-m-d H:i:s', strtotime('+3 hours', strtotime('2004-10-31')))."\n";
?>

of 

2004-10-31 01:00:00
2004-10-31 01:00:00
2004-10-31 02:00:00

So now I believe the issue is that the following 2 statements give different output though they should have the same output:

<?php
echo strtotime('2004-10-31 +2 hours')."\n";
echo strtotime('+2 hours', strtotime('2004-10-31'))."\n";
?>
 [2005-02-06 22:58 UTC] rbro at hotmail dot com
Thanks - I just tried it using php4-STABLE-200502051730, but I seem to be still getting the same result.  My test script is:

<?php
echo date('Y-m-d H:i:s', strtotime('2004-10-31 +2 hours'))."\n";
echo date('Y-m-d H:i:s', strtotime('+2 hours', strtotime('2004-10-31')))."\n";
?>

The output I am getting is:

2004-10-31 02:00:00
2004-10-31 01:00:00

while I expected to get:

2004-10-31 01:00:00
2004-10-31 01:00:00
 [2005-02-06 23:13 UTC] derick@php.net
There is being worked on this.
 [2005-06-16 21:31 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.

Fixed for PHP 5.1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC