note 82759 added to function.stat

From: Date: Thu, 24 Apr 2008 18:19:14 +0000
Subject: note 82759 added to function.stat
Groups: php.notes 
Request: Send a blank email to php-notes+get-138744@lists.php.net to get a copy of this message
In response to the note whose first line is: Re note posted by "admin at smitelli dot com" I believe you have the conversion backwards. You should add an hour to filemtime if the system is in DST and the file is not. Conversely, you should subtract an hour if the file time is DST and the current OS time is not. Here's a simplified, corrected version: <?php function getmodtime($file) { //returns the time a file was modified. $mtime = filemtime($file); //date('I') returns 1 if DST is on and 0 if off. $diff = date('I')-date('I', $mtime); //diff = 0 if file-time and os-time are both in the same DST setting //diff = 1 if os is DST and file is not //diff = -1 if file is DST and os is not return $mtime + $diff*3600; } ?> Here's a test: <?php //create two dummy files: $file0 = 'file1.txt'; $file1 = 'file2.txt'; file_put_contents($file0, ''); file_put_contents($file1, ''); $time0=strtotime('Jan 1 2008 10:00'); echo 'Date0 (ST): ' . date(DATE_COOKIE, $time0)."\n"; $time1=strtotime('Aug 1 2008 10:00'); echo 'Date1 (DT): ' . date(DATE_COOKIE, $time1)."\n"; touch($file0, $time0); //set file0 to Winter (Non-DST) touch($file1, $time1); //set file1 to Summer (DST) $ftime0 = filemtime($file0); $ftime1 = filemtime($file1); echo "\nUncorrected: \n"; echo 'File 0: ' . ($ftime0-$time0) ."\n"; echo 'File 1: ' . ($ftime1-$time1) ."\n"; //if your system adjusts for DST, then _one_ of the above should be 3600 or -3600, depending on the time of year $ftime0 = getmodtime($file0); //use filemtime correction $ftime1 = getmodtime($file1); //use filemtime correction echo "\nCorrected: \n"; echo 'File 0: ' . ($ftime0-$time0) ."\n"; echo 'File 1: ' . ($ftime1-$time1) ."\n"; //both of the corrected values output should be 0. ?> Output: ------------------------------ (when run in summer) ------------------------------ Date0 (ST): Tuesday, 01-Jan-08 10:00:00 EST Date1 (DT): Friday, 01-Aug-08 10:00:00 EDT Uncorrected: File 0: -3600 File 1: 0 Corrected: File 0: 0 File 1: 0 ------------------------------ (when run in winter--dates omitted) ------------------------------ Uncorrected: File 0: 0 File 1: 3600 Corrected: File 0: 0 File 1: 0 In response to Re note posted by "admin at smitelli dot com", your version below gives the following output when substituted into my test: ------------------------------ (when run in summer--dates omitted) ------------------------------ Uncorrected: File 0: -3600 File 1: 0 Corrected: File 0: -7200 File 1: 0 ------------------------------ You can see that the operation is the opposite of what it should be. ---- Server IP: 208.69.120.35 Probable Submitter: 128.2.228.111 ---- Manual Page -- http://www.php.net/manual/en/function.stat.php Edit -- https://master.php.net/note/edit/82759 Del: integrated -- https://master.php.net/note/delete/82759/integrated Del: useless -- https://master.php.net/note/delete/82759/useless Del: bad code -- https://master.php.net/note/delete/82759/bad+code Del: spam -- https://master.php.net/note/delete/82759/spam Del: non-english -- https://master.php.net/note/delete/82759/non-english Del: in docs -- https://master.php.net/note/delete/82759/in+docs Del: other reasons-- https://master.php.net/note/delete/82759 Reject -- https://master.php.net/note/reject/82759 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138744) next »