note 58404 added to function.stat
| From: | admin at smitelli dot com | Date: | Thu, 03 Nov 2005 07:27:51 +0000 |
| Subject: | note 58404 added to function.stat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98010@lists.php.net to get a copy of this message | ||
There's an important (yet little-known) problem with file dates on Windows and Daylight
Savings. This affects the 'atime' and 'mtime' elements returned by stat(), and
it also affects other filesystem-related functions such as fileatime() and filemtime().
During the winter months (when Daylight Savings isn't in effect), Windows will report a certain
timestamp for a given file. However, when summer comes and Daylight Savings starts, Windows will
report a DIFFERENT timestamp! Even if the file hasn't been altered at all, Windows will shift
every timestamp it reads forward one full hour during Daylight Savings.
This all stems from the fact that M$ decided to use a hackneyed method of tracking file dates to
make sure there are no ambiguous times during the "repeated hour" when DST ends in
October, maintain compatibility with older FAT partitions, etc. An excellent description of what/why
this is can be found at http://www.codeproject.com/datetime/dstbugs.asp
This is noteworthy because *nix platforms don't have this problem. This could introduce some
hard-to-track bugs if you're trying to move scripts that track file timestamps between
platforms.
I spent a fair amount of time trying to debug one of my own scripts that was suffering from this
problem. I was storing file modification times in a MySQL table, then using that information to see
which files had been altered since the last run of the script. After each Daylight Savings change,
every single file the script saw was considered "changed" since the last run, since all
the timestamps were off by +/- 3600 seconds.
This one-liner is probably one of the most incorrect fixes that could ever be devised, but it's
worked flawlessly in production-grade environments... Assuming $file_date is a Unix timestamp
you've just read from a file:
<?php
if (date('I') == 1) $file_date -= 3600;
?>
That will ensure that the timestamp you're working with is always consistently reported,
regardless of whether the machine is in Daylight Savings or not.
----
Manual Page -- http://www.php.net/manual/en/function.stat.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58404
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58404&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58404&report=yes
Search -- http://master.php.net/manage/user-notes.php