Jump to content

FileGetTime() uses an improper TZ+DST shift at today's date


Go to solution Solved by LaurentC,

Recommended Posts

That is a helluva lotta if/then code in a UDF just to be precise historically ! You would have to plan your code for all potential variations that may possibly arise in the future as well.

I think I I will leave it to somebody else to write the UDF, or just rely on some embedded DLL present in Windows that does the hard work for me.

Edited by Confuzzled
Link to comment
Share on other sites

1 hour ago, LaurentC said:

I remember you gave us also that :

The wiki page points to the same IANA DB.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi

I've discovered today there was an AutoIt ticket 6 years ago ! 

FileGetTime out by exactly one hour https://www.autoitscript.com/trac/autoit/ticket/3139

The ticket was classified as 'No bug' ! And I think AutoIt is right !! The FileGetTime() function is conformed to Microsoft’s implementation !!! 

That why I mean this is an AutoIt documentation issue (if we can say that, of course  ; -) 

As a new user of FileGettime(), I have started a new subject, because there was no DST warning inside FileGetTime() Help that just replicates the Microsoft behavior not aligned to W10 behavior : a warning as explained in Microsoft documentation... 

Regards 

  

On 5/25/2021 at 3:39 PM, LaurentC said:
...
3/
But, as said above in the link proposed : https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-times
I understand this is certainly a pure Windows mismatch !
These AutoIt functions only reflect Windows functions : these are not original written AutoIt libraries, but a useful mapping to Windows API (?).
If FileGetTime is a pure mapping of Win32 DLL functions and shall be kept as this, Jos, I understand your proposition is becoming even the rule...   😏  
...
5/ Question : Without even discussing code correction, would it be possible, at least, to add a remark in the AutoIt Help AutoIt.chm ?

This will help AutoIt users not to wrongly manipulates dates with FileSetTime()...  

I would have been happy last week to read these forum  explanations in the documentation of AutoIt take care of DST...
...

 

Link to comment
Share on other sites

Perhaps this is the solution: (Courtesy of @hifi55)

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

#include <File.au3>
#include <Date.au3>
#include <WinAPIFiles.au3>
#include <WinAPI.au3>

ConsoleWrite("Modified datetime of this script is " & FileGetTimeExt(@ScriptFullPath, 0, 1) & @CRLF)
ConsoleWrite("Created datetime of this script is " & FileGetTimeExt(@ScriptFullPath, 1, 1) & @CRLF)
ConsoleWrite("Last accessed datetime of this script is " & FileGetTimeExt(@ScriptFullPath, 2, 1) & @CRLF)

Func FileGetTimeExt($filename, $option = 0, $format = 0)
    ; v1.0
    ; Extended FileGetTime function to properly deal with DST (Daylight Saving Time (summertime/wintertime)) on Windows 7+
    ; Usage is identical to the FileGetTime.
    ;
    ; AutoIt Version: 3.3.14.2
    ; This function requires Windows 7 or later.
    ;
    ; Requirements to include in your main program:
    ; #include <File.au3>
    ; #include <Date.au3>
    ; #include <WinAPIFiles.au3>
    ; #include <WinAPI.au3>
    If $option = Default Then $option = 0
    If $format = Default Then $format = 0
    Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "", $ssDir = "", $sDummy1 = "", $sDummy2 = ""
    _PathSplit($filename, $sDrive, $sDir, $sFileName, $sExtension)
    ; extend path to full path if filename has no path or a path relative to ScriptDir
    If $sDrive = "" Then
        _PathSplit(@ScriptFullPath, $sDrive, $ssDir, $sDummy1, $sDummy2)
        $sDir = $ssDir & $sDir
        $filename = _PathMake($sDrive, $sDir, $sFileName, $sExtension)
    EndIf
    Local $aTime, $tDate, $tOut[6], $hFile, $tSystem, $tLocal, $tFile
    FileGetTime($filename, $option, $format) ; test if no error occurs
    If @error Then Return SetError(@error, 0, "")
    ; use _WinAPI_CreateFileEx instead of _WinAPI_CreateFile to include directory access without an 'Access is denied' error
    $hFile = _WinAPI_CreateFileEx($filename, $OPEN_EXISTING, $GENERIC_READ, $FILE_SHARE_READ, $FILE_FLAG_BACKUP_SEMANTICS)
    Switch $option ; convert FileGetTime option 0 to _Date_Time_GetFileTime option 2, 1 to 0 and 2 to 1
        Case 0
            $option = 2 ; Last modified (default)
        Case 1
            $option = 0 ; Created
        Case 2
            $option = 1 ; Last accessed
    EndSwitch
    $aTime = _Date_Time_GetFileTime($hFile)
    _WinAPI_CloseHandle($hFile)
    $aTime = $aTime[$option]
    $tSystem = _Date_Time_FileTimeToSystemTime($aTime)
    $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime($tSystem)
    $tFile = _Date_Time_SystemTimeToFileTime($tLocal)
    $tDate = _Date_Time_FileTimeToArray($tFile)
    $tOut[0] = StringFormat("%04i", $tDate[2]) ; Year
    $tOut[1] = StringFormat("%02i", $tDate[0]) ; Month
    $tOut[2] = StringFormat("%02i", $tDate[1]) ; Day
    $tOut[3] = StringFormat("%02i", $tDate[3]) ; Hour
    $tOut[4] = StringFormat("%02i", $tDate[4]) ; Minutes
    $tOut[5] = StringFormat("%02i", $tDate[5]) ; Seconds
    If $format = 0 Then Return SetError(0, 0, $tOut)
    Return SetError(0, 0, $tOut[0] & $tOut[1] & $tOut[2] & $tOut[3] & $tOut[4] & $tOut[5])
EndFunc   ;==>FileGetTimeExt

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Yes = the same code algorithm than _FileGetTimeDST() that I propose in my previous post, but 5 years ago (!) 

https://www.autoitscript.com/forum/topic/205935-filegettime-uses-an-improper-tzdst-shift-at-todays-date/page/2/?tab=comments#comment-1483426

 

I just coded, additionally, all the FileGetTime() options with the returned string for my usage 

@hifi55 proposes also FileSetTimeExt() ! and all explanations 

Nice 😃 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...