php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62185 strtotime() returns incorrect time around DST (America)
Submitted: 2012-05-29 23:07 UTC Modified: 2017-03-19 10:15 UTC
Votes:8
Avg. Score:4.2 ± 1.1
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:4 (50.0%)
From: omg00dness at yahoo dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 5.3.13 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: omg00dness at yahoo dot com
New email:
PHP Version: OS:

 

 [2012-05-29 23:07 UTC] omg00dness at yahoo dot com
Description:
------------
For an American timezone (at least those that observe Daylight Savings Time), strtotime() is outputting incorrectly when adding a negative time string.

Example uses March 11, 2012 at 2:00am, where the local time jumps instead to 3:00am.

Test script:
---------------
<?php
date_default_timezone_set('America/Los_Angeles'); 
echo date("M j Y H:i:s I", strtotime("2012-03-11 5:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 4:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:00:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:01:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 2:59:00 -1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 1:00:00 +1 hour")) . "\n";
echo date("M j Y H:i:s I", strtotime("2012-03-11 0:00:00 +1 hour")) . "\n";
?>

Expected result:
----------------
Mar 11 2012 04:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0
Mar 11 2012 01:01:00 0
Dec 31 1969 16:00:00 0 //Perhaps output false?
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0

Actual result:
--------------
Mar 11 2012 04:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 03:00:00 1
Mar 11 2012 03:01:00 1
Mar 11 2012 01:59:00 0
Mar 11 2012 03:00:00 1
Mar 11 2012 01:00:00 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-30 03:16 UTC] riptide dot tempora at opinehub dot com
Improved test script:

<?php
date_default_timezone_set('America/Los_Angeles'); 
echo strtotime("2012-03-11 5:00:00 -1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 5:00:00 -1 hour")) . "\n";
echo strtotime("2012-03-11 4:00:00 -1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 4:00:00 -1 hour")) . "\n";
echo strtotime("2012-03-11 3:00:00 -1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:00:00 -1 hour")) . "\n";
echo strtotime("2012-03-11 3:01:00 -1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 3:01:00 -1 hour")) . "\n";
echo strtotime("2012-03-11 2:59:00 -1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 2:59:00 -1 hour")) . "\n";
echo strtotime("2012-03-11 1:00:00 +1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 1:00:00 +1 hour")) . "\n";
echo strtotime("2012-03-11 0:00:00 +1 hour") . "\t";
echo date("M j Y H:i:s I", strtotime("2012-03-11 0:00:00 +1 hour")) . "\n";
?>

My server produced (PHP Version 5.3.13):
1331463600	Mar 11 2012 04:00:00 1
1331460000	Mar 11 2012 03:00:00 1
1331460000	Mar 11 2012 03:00:00 1
1331460060	Mar 11 2012 03:01:00 1
1331459940	Mar 11 2012 01:59:00 0
1331460000	Mar 11 2012 03:00:00 1
1331456400	Mar 11 2012 01:00:00 0

http://www.alpha7f.com/phpt/bug62185.php
 [2017-03-19 10:15 UTC] heiglandreas@php.net
-Status: Open +Status: Duplicate
 [2017-03-19 10:15 UTC] heiglandreas@php.net
We're now tracking this in https://bugs.php.net/bug.php?id=74274
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC