Yesterday I came accross a strange bug (at least I think it's a bug as I can't see any logic in the current behaviour).
When I use 'GetFileDate' to read the '#PB_Date_Modified' Date of a file I get different results depending on the DaylightSaving status.
For example the 5.20 x86 purebasic.exe:
GetFileDate returns >1379419754< >2013.09.17 12:09:14< when run with a systemdate BEFORE the daylight-saving change on 27.10.2013 (at least here in Austria), and when I change the systemdate to the current date (after the daylight saving change) I get a different result: >1379416154< >2013.09.17 11:09:14<
Personally I think 'GetFileDate' should always return the same value - regardless of the current daylight saving state.
When I check the modified date directly in windows explorer I'll get always the same result, independent of the current system date (always with 12:09).
So I've wrote a small workaround procedure 'GetFileDateTZ':
(based on the 'Remarks' here: http://msdn.microsoft.com/en-us/library ... 85%29.aspx)
Code: Select all
EnableExplicit
Procedure.i GetFileDateTZ(Filename.s, Datetype.i, UseUTC.b=#False)
Protected FileHdl.i
Protected Create.FILETIME
Protected Access.FILETIME
Protected Write.FILETIME
Protected SystemTime.SYSTEMTIME
Protected LocalTime.SYSTEMTIME
FileHdl = ReadFile(#PB_Any, Filename)
If FileHdl
If Not GetFileTime_(FileID(FileHdl), @Create, @Access, @Write)
Debug "GetFileDateTZ - GetFileTime Error!!"
ProcedureReturn 0
EndIf
CloseFile(FileHdl)
Select Datetype
Case #PB_Date_Created
If Not FileTimeToSystemTime_(@Create, @SystemTime)
Debug "GetFileDateTZ - FileTimeToSystemTime Error!!"
EndIf
Case #PB_Date_Accessed
If Not FileTimeToSystemTime_(@Access, @SystemTime)
Debug "GetFileDateTZ - FileTimeToSystemTime Error!!"
EndIf
Case #PB_Date_Modified
If Not FileTimeToSystemTime_(@Write, @SystemTime)
Debug "GetFileDateTZ - FileTimeToSystemTime Error!!"
EndIf
Default
Debug "GetFileDateTZ - Invalid Datetype >"+Str(Datetype)+"<"
ProcedureReturn 0
EndSelect
If UseUTC
LocalTime=SystemTime
Else
If Not SystemTimeToTzSpecificLocalTime_(#Null, @SystemTime, @LocalTime)
Debug "GetFileDateTZ - SystemTimeToTzSpecificLocalTime Error!!"
ProcedureReturn 0
EndIf
EndIf
ProcedureReturn Date(LocalTime\wYear, LocalTime\wMonth, LocalTime\wDay, LocalTime\wHour, LocalTime\wMinute, LocalTime\wSecond)
Else
Debug "GetFileDateTZ - ReadFile Error!!"
ProcedureReturn 0
EndIf
EndProcedure
Define FileTime.i
Define sFile.s=#PB_Compiler_Home+"\purebasic.exe"
FileTime=GetFileDate(sFile, #PB_Date_Modified)
Debug "GetFileDate: >"+Str(FileTime)+"< >"+FormatDate("%yyyy.%mm.%dd %hh:%ii:%ss", FileTime)+"<"
FileTime=GetFileDateTZ(sFile, #PB_Date_Modified)
Debug "GetFileDateTZ: >"+Str(FileTime)+"< >"+FormatDate("%yyyy.%mm.%dd %hh:%ii:%ss", FileTime)+"<"
FileTime=GetFileDateTZ(sFile, #PB_Date_Modified, #True)
Debug "GetFileDateTZ: (UTC) >"+Str(FileTime)+"< >"+FormatDate("%yyyy.%mm.%dd %hh:%ii:%ss", FileTime)+"<"
Until it's fixed I'll use my workaround
Edit: Changed the procedure slightly, removed the check for filesize, this almost doubled the speed (it's still slower than the original GetFileDate - but fast enough for all my purposes)