note 32927 deleted from function.strtotime by sniper

From: Date: Tue, 21 Oct 2003 11:01:30 +0000
Subject: note 32927 deleted from function.strtotime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58997@lists.php.net to get a copy of this message
Note Submitter: jill dott ramonsky att aculab dott comm ---- 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

« previous php.notes (#58997) next »