note 100692 added to function.filemtime
| From: | myselfasunder at gmail dot XYZ dot com | Date: | Sun, 31 Oct 2010 22:02:44 +0000 |
| Subject: | note 100692 added to function.filemtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173626@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:
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
----
Server IP: 192.41.42.26
Probable Submitter: 76.108.78.175
----
Manual Page -- http://www.php.net/manual/en/function.filemtime.php
Edit -- https://master.php.net/note/edit/100692
Del: integrated -- https://master.php.net/note/delete/100692/integrated
Del: useless -- https://master.php.net/note/delete/100692/useless
Del: bad code -- https://master.php.net/note/delete/100692/bad+code
Del: spam -- https://master.php.net/note/delete/100692/spam
Del: non-english -- https://master.php.net/note/delete/100692/non-english
Del: in docs -- https://master.php.net/note/delete/100692/in+docs
Del: other reasons-- https://master.php.net/note/delete/100692
Reject -- https://master.php.net/note/reject/100692
Search -- https://master.php.net/manage/user-notes.php