note 32927 added to function.strtotime
| From: | jill at rack1 dot php dot net | Date: | Wed, 11 Jun 2003 07:36:37 +0000 |
| Subject: | note 32927 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50155@lists.php.net to get a copy of this message | ||
It seems that strtotime() fails to take daylight saving time into account, as the following code
demonstrates:
$stamp = 7516800;
for ($i=0; $i<4; $i++)
{
$s = substr(date('D, d M Y H:i:s T',$stamp),0,29);
$stamp2 = strtotime($s);
$b = ($stamp == $stamp2) ? "OK" : "BUG";
echo "$stamp --> $s --> $stamp2 ($b)\\n";
$stamp += 3600;
}
This produces the following output:
7516800 --> Sun, 29 Mar 1970 00:00:00 GMT --> 7516800 (OK)
7520400 --> Sun, 29 Mar 1970 02:00:00 GMT --> 7524000 (BUG)
7524000 --> Sun, 29 Mar 1970 03:00:00 GMT --> 7527600 (BUG)
7527600 --> Sun, 29 Mar 1970 04:00:00 GMT --> 7531200 (BUG)
I do, however, have a workaround. (This will continue to work even if the bug gets fixed).
function bug_free_strtotime($str)
{
$stamp = strtotime($str);
$str2 = substr(date('D, d m Y H:i:s T',$stamp),0,29);
return ($str == $str2) ? $stamp : $stamp-3600;
}
Jill
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32927
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32927&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32927&report=yes