Possible issue with ConvertFileTimeToDateTime giving results different from File Explorer due to Daylight Savings Time.

Issue #388 resolved
Mark Ford created an issue

This results in TFileSystemEntry.LastWriteTime being different that the value displayed in FileExplorer if the FileTime was during DST. The Microsoft docs for FileTimeToLocalFileTime mention that it doesn’t support daylight savings information and gives the call sequence needed. Here’s my simple version which gives results that match FileExplorer:

function MyFileTimeToDateTime(AFileTime: FILETIME): TDateTime;
var
  SysTime: TSystemTime;
  LocTime: TSystemTime;
begin
  Result := 0;
  if FileTimeToSystemTime(AFileTime, SysTime) then
    if SystemTimeToTzSpecificLocalTime(nil, SysTime, LocTime) then
      Result := SystemTimeToDateTime(LocTime);
end;

Comments (3)

  1. Mark Ford reporter

    Also it might be convenient for TFileSystemEntry to give access to the raw FILETIME values (just a minor enhancement request.) In my testing the file/dir enumerators work excellently btw!

  2. Log in to comment