Opened 2 months ago

Closed 2 months ago

Last modified 3 weeks ago

#4044 closed Bug (Fixed)

Time macros don't adjust to timezone changes while running script — at Version 9

Reported by: argumentum Owned by:
Milestone: Component: AutoIt
Version: 3.3.16.1 Severity: None
Keywords: Cc:

Description (last modified by mLipok)

The forum entry is at [ https://www.autoitscript.com/forum/topic/213051-autoit-error-getting-current-time/#comment-1544988 ]

A test script:

#include <Date.au3>

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit
EndFunc   ;==>Terminate

Exit test()
Func test()
    Local $hTimer = TimerInit(), $iSec = 88
    While 1
        Sleep(200)
        If $iSec = @SEC Then ContinueLoop
        $iSec = @SEC
        If Mod($iSec, 5) Then ContinueLoop
        ConsoleWrite('- NowCalc: ' & _NowCalc() & @TAB & @TAB & TimeZone() & @TAB & 'viaMacros: ' & _NowCalc_viaMacros() & @CRLF)
    WEnd
EndFunc   ;==>test

Func _NowCalc_viaMacros()
    Return @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC
EndFunc   ;==>_NowCalc_viaMacros

Func TimeZone()
    Local $aInfo = _Date_Time_GetTimeZoneInformation()
    ShowTimeZoneInformation($aInfo, "")
    Return $aInfo[1] & '(' & $aInfo[7] & ')'
EndFunc   ;==>TimeZone

; Show time zone information
Func ShowTimeZoneInformation(ByRef $aInfo, $sComment)
    ConsoleWrite("+ ******************* " & $sComment & " *******************" & @CRLF)
    Local $aDaylightSavingsSetting[4] = ["Failure", "not used in the current time zone", _
            "operating with standard time", "operating with daylight savings time"]
    ConsoleWrite("+ Result ............: " & $aInfo[0] & ' = ' & $aDaylightSavingsSetting[$aInfo[0] + 1] & @CRLF)
    ConsoleWrite("+ Current bias ......: " & $aInfo[1] & @CRLF)
    ConsoleWrite("+ Standard name .....: " & $aInfo[2] & @CRLF)
    ConsoleWrite("+ Standard date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[3]) & @CRLF)
    ConsoleWrite("+ Standard bias......: " & $aInfo[4] & @CRLF)
    ConsoleWrite("+ Daylight name .....: " & $aInfo[5] & @CRLF)
    ConsoleWrite("+ Daylight date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[6]) & @CRLF)
    ConsoleWrite("+ Daylight bias......: " & $aInfo[7] & @CRLF)
EndFunc   ;==>ShowTimeZoneInformation

Change History (9)

comment:1 Changed 2 months ago by Jpm

under Beta 3.3.17.1 i don't see any discrepency

comment:2 Changed 2 months ago by argumentum

Tested under Win11 and Win10 and shows the bug in v3.3.16.1 and the new beta v3.3.17.1.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_SaveSource=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>

HotKeySet("{ESC}", "Terminate")
Func Terminate()
        Exit
EndFunc   ;==>Terminate

Global $idEdit

Exit test()
Func test()
        ; change TimeZones while running this script

        GUICreate(StringTrimRight(@ScriptName, 4) & ' - ' & @AutoItVersion & ' (' & (@AutoItX64 ? 'x64)' : 'x86)'), 600, 400)
        $idEdit = GUICtrlCreateEdit("", 0, 0, 600, 400)
        GUISetState()
        GUICtrlSetData($idEdit, "Press ESC to exit" & @CRLF & @CRLF, 1)

        ConsoleWriteIt()
        AdlibRegister(ConsoleWriteIt, 5000) ; ConsoleWriteIt every 5 sec.
        Do
        Until GUIGetMsg() = -3
EndFunc   ;==>test

Func ConsoleWriteIt()
        Local $sOut = (_NowCalc() = _NowCalc_viaMacros() ? '-' : '! !!!') & ' NowCalc: ' & _NowCalc() & _
                        @TAB & TimeZone() & @TAB & 'viaMacros: ' & _NowCalc_viaMacros() & @CRLF
        ConsoleWrite($sOut)
        GUICtrlSetData($idEdit, $sOut, 1)
EndFunc   ;==>ConsoleWriteIt

Func _NowCalc_viaMacros()
        Return @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC
EndFunc   ;==>_NowCalc_viaMacros

Func TimeZone()
        Local $aInfo = _Date_Time_GetTimeZoneInformation()
        If @error Then Dim $aInfo[8] = [-2]
        ShowTimeZoneInformation($aInfo, "")
        Return StringRight('    ' & $aInfo[1] & '(' & $aInfo[7] & ')', 11)
EndFunc   ;==>TimeZone

; Show time zone information
Func ShowTimeZoneInformation(ByRef $aInfo, $sComment)
        ConsoleWrite(@CRLF & "+ ******************* " & $sComment & " *******************" & @CRLF)
        Local $aDaylightSavingsSetting[5] = ["Error", "Failure", "not used in the current time zone", _
                        "operating with standard time", "operating with daylight savings time"]
        ConsoleWrite("+ Result ............: " & $aInfo[0] & ' = ' & $aDaylightSavingsSetting[$aInfo[0] + 2] & @CRLF)
        ConsoleWrite("+ Current bias ......: " & $aInfo[1] & @CRLF)
        ConsoleWrite("+ Standard name .....: " & $aInfo[2] & @CRLF)
        ConsoleWrite("+ Standard date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[3]) & @CRLF)
        ConsoleWrite("+ Standard bias......: " & $aInfo[4] & @CRLF)
        ConsoleWrite("+ Daylight name .....: " & $aInfo[5] & @CRLF)
        ConsoleWrite("+ Daylight date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[6]) & @CRLF)
        ConsoleWrite("+ Daylight bias......: " & $aInfo[7] & @CRLF)
EndFunc   ;==>ShowTimeZoneInformation

Last edited 3 weeks ago by mLipok (previous) (diff)

comment:3 Changed 2 months ago by argumentum

Even fixed the version from 3.2.x.x

ConsoleWrite(_NowCalc_v32() & @CRLF)
Func _NowCalc_v32()
        Local $tLocalTime = DllStructCreate("short Year;short Month;short Dow;short Day;short Hour;short Minute;short Second;short MSeconds")
        DllCall("Kernel32.dll", "none", "GetLocalTime", "ptr", DllStructGetPtr($tLocalTime))
        If @error Then Return SetError(@error, @extended, "oops1")
        Return DllStructGetData($tLocalTime, "Year") & "/" & StringRight('00' & DllStructGetData($tLocalTime, "Month"), 2) & "/" & StringRight('00' & DllStructGetData($tLocalTime, "Day"), 2) & " " & _
                        StringRight('00' & DllStructGetData($tLocalTime, "Hour"), 2) & ":" & StringRight('00' & DllStructGetData($tLocalTime, "Minute"), 2) & ":" & StringRight('00' & DllStructGetData($tLocalTime, "Second"), 2)
EndFunc   ;==>_NowCalc_v32

to track down when did it started, and the "bug" is been there since always.

...that to tell you the truth, I would have ever find on my own because who would do that ! but, is true and as it seems other users do change time zones more than just at the setup of the OS in the beginning.

And I don't consider this a bug but rather an overlooked possibility while coding. A "..what if.." kind of thing.

Last edited 3 weeks ago by mLipok (previous) (diff)

comment:4 Changed 2 months ago by argumentum

http://msdn.microsoft.com/en-us/library/windows/desktop/ms725498%28v=vs.85%29.aspx
If you register it

#include <GUIConstants.au3>
#include <WinApi.au3>
GUIRegisterMsg($WM_TIMECHANGE, _WM_TIMECHANGE)
Func _WM_TIMECHANGE($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg, $wParam, $lParam
        ConsoleWrite('> >>> WM_TIMECHANGE' & @CRLF)
EndFunc

it should solve it. Recalculate the internals for time macros if it triggers.

Last edited 3 weeks ago by mLipok (previous) (diff)

comment:5 Changed 2 months ago by anonymous

even with

Func ConsoleWriteIt()
        Local $sNowCalc = _NowCalc()
        Local $sNowCalc_viaMacros = _NowCalc_viaMacros()
        If $sNowCalc <> $sNowCalc_viaMacros Then
                Local $sOut = ($sNowCalc = $sNowCalc_viaMacros ? '-' : '! !!!') & ' NowCalc: ' & $sNowCalc & _
                                @TAB & TimeZone() & @TAB & 'viaMacros: ' & $sNowCalc_viaMacros & @CRLF
                ConsoleWrite($sOut)
                GUICtrlSetData($idEdit, $sOut, 1)
        EndIf
EndFunc   ;==>ConsoleWriteIt


I don't see any console write after hours

Last edited 3 weeks ago by mLipok (previous) (diff)

comment:6 Changed 2 months ago by Jpm

anonymous it is me

comment:7 Changed 2 months ago by argumentum

Jpm, there is nothing to wait for.

Goto

https://www.autoitscript.com/forum/uploads/monthly_2025_08/image.png.0a19a4e3970924bebf891dbceb4b8f83.png

and change the time zone

https://www.autoitscript.com/forum/uploads/monthly_2025_08/image.png.9da6af441cf8d0bc685bb28706228ddd.png

and that will show the time difference between @macros and system time.

comment:8 Changed 2 months ago by Jpm

  • Resolution set to Fixed
  • Status changed from new to closed

Already Solve with the #3887 solution

comment:9 Changed 3 weeks ago by mLipok

  • Description modified (diff)
Note: See TracTickets for help on using tickets.