|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
Thank you for quickly reply. I still consider it as a bug. If I set $to = ?2004-03-28 00:00:00? $march0 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to")); $march1 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 second")); $march2 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 day ")); $march1 gives the correct result, while $march2 gives the wrong result. Because during the midnight of 28th it changed from the wintertime to the summertime for daylight saving. As you pointed out, to add a timezone: $to = "2004-03-28 00:00:00 WET"; $march0 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to")); $march1 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 seconds ")); $march2 = strftime("%Y-%m-%d %H:%M:%S", strtotime("$to +1 day ")); Relative to $march0, $march1 gives the correct output, but these two outputs are not what I expected. $march2 is still totally wrong no matter reference to which dates. The point is, I think, PHP checks the output result with for daylight saving, but not the original input date. Regards, Hua Qu