note 100692 modified in function.filemtime by danbrown

From: Date: Mon, 01 Nov 2010 12:35:21 +0000
Subject: note 100692 modified in function.filemtime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173646@lists.php.net to get a copy of this message
There's a deeply-seated problem with filemtime() under Windows due to the fact that it calls Windows' stat() function, which implements DST (according to this bug: http://bugs.php.net/bug.php?id=40568). The detection of DST on the time of the file is confused by whether the CURRENT time of the current system is currently under DST. This is a fix for the mother of all annoying bugs: <?php function GetCorrectMTime($filePath) { $time = filemtime($filePath); $isDST = (date('I', $time) == 1); $systemDST = (date('I') == 1); $adjustment = 0; if($isDST == false && $systemDST == true) $adjustment = 3600; else if($isDST == true && $systemDST == false) $adjustment = -3600; else $adjustment = 0; return ($time + $adjustment); } ?> Dustin Oprea --was-- There's a deeply-seated problem with filemtime() under Windows due to the fact that it calls Windows' stat() function, which implements DST (according to this bug: http://bugs.php.net/bug.php?id=40568). The detection of DST on the time of the file is confused by whether the CURRENT time of the current system is currently under DST. This is a fix for the mother of all annoying bugs: function GetCorrectMTime($filePath) { $time = filemtime($filePath); $isDST = (date('I', $time) == 1); $systemDST = (date('I') == 1); $adjustment = 0; if($isDST == false && $systemDST == true) $adjustment = 3600; else if($isDST == true && $systemDST == false) $adjustment = -3600; else $adjustment = 0; return ($time + $adjustment); } Dustin Oprea http://php.net/manual/en/function.filemtime.php

« previous php.notes (#173646) next »