I'd like to know how to include previous posts in those nifty boxes with the posting details at the top but I'm such a darn newbie.
On July 18 PascalDragon wrote:
NTFS stores the time as UTC, but Windows displays them in your local time. Take 7:42:04 (UTC) for example. In my case (European Central Time - Summertime) it will be displayed as 9:42:04. The operating system itself internally also operates with UTC (thus "system time"). For display purposes however this time is translated into "local time", meaning the time of your timezone. The FindFirst and FindNext functions retrieve (from the operating system) the time in "system time" aka UTC. Now you need to translate that into "local time" so that you get the same time (plus/minus the 2 seconds) that the Explorer displays. In theory the new Timestamp property should do that, but that's only the case in trunk (see below for an explanation). So you'll have to adjust that yourself.
ejohnstone's response:
I believe a difference of one hour occurs when
a) a file was saved during daylight saving time but it's standard (not daylight) time currently, and "Adjust for daylight saving time automatically" is set to "On," or
b) a file was saved during standard time but it's daylight time currently, and "Adjust for daylight saving time automatically" is set to "On,". Is this an FPC bug?
I tested the 8 combinations of those 3 booleans. See the table below.
My computer's Time zone is set to "(UTC-05:00) Eastern Time (US & Canada)." The switch for "Adjust for daylight saving time automatically" is set to "On." Both files were saved with those settings on the dates shown; i.e. I did not change the date manually and then save the files.
FileSaved Daylight Daylight Windows Lazarus UTC
during Time Now? Adjust
Daylight Time?
----------------------------------------------------------------------------------------
y y on July 14, 2020 9:49:41 9:49:42 13:49:41
y y off 8:49:41 8:49:42
y n on 9:49:41 8:49:42 <--
y n off 8:49:41 8:49:42
n y on Dec 19, 2019 22:25:59 23:26:00 <--
n y off 22:25:59 22:26:00
n n on 22:25:59 22:26:00 3:25:59
n n off 22:25:59 22:26:00
It seems like there's logic somewhere that says "If the Daylight Adjustment switch is set to 'On' then
adjust the Timestamp according to whether or not it's Daylight Time currently. That apparent and incorrect logic might be the result of which Windows function or API is called to perform the adjustment from system to local time.
https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-timesIn particular it says:
"To convert a file time to local time, use the FileTimeToLocalFileTime function. However, FileTimeToLocalFileTime uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, it takes daylight saving time into account, even if the file time you are converting is in standard time."
"The NTFS file system records times on disk in UTC. To account for daylight saving time when converting a file time to a local time, use the following sequence of functions instead of using FileTimeToLocalFileTime:
FileTimeToSystemTime
SystemTimeToTzSpecificLocalTime
SystemTimeToFileTime"