Daylight Savings Time.
It seems that every time we pass in or out of this period, I have some kind of hassle. On previous occasions I would simply slap myself on the forehead, recompile and upload my website and move on, making a mental note to "watch out" for time zone issues in the future.
Not this time. This time I decided to find out why this keeps happening. And to my surprise, I think it may not be entirely my fault!
Stat!
Like a lot of software, my HTML editor checks file modification times to determine when pages need rebuilding. Unfortunately it seems that some incorrect documentation has led me to intepret the values returned by a certain low level system call incorrectly.
The documentation for the _stat(…) function implies that the returned st_mtime member contains a UTC time value, with the sample code using a ctime(…) call to convert it to a string representation, and ctime(…) is designed to take a UTC value as input.
From my own testing however [on an NTFS file system] it seems that st_mtime is pre-adjusted to the local timezone, meaning that passing it to ctime(…) will result in an incorrect time value, representing neither UTC or local time, because it will be performing the adjustment twice.
Returning such an adjusted value in st_mtime seems particularly inappropriate since the raw value will acually vary depending on the current time zone setting of the local machine as well as the Daylight Savings status! This seems to be the root cause of my files getting out of sync when DST changes occur.
I am now in the process of fixing my code so that I get UTC values instead of "adjusted" time when querying file properties… hopefully this will improve some of the issues I’ve been having.