Jump to content

Issue with _Date_Time_GetTimeZoneInformation and $tagSYSTEMTIME


Recommended Posts

I have a little script I am writing that I would to get the dates for the start of Daylight Savings Time and the start of Standard Time for my system. I will be turning those into a Windows timestamp that is passed as a number to another program. Rainmeter, which uses Windows timestamps in its time functionality. (seconds since Jan 1 1601)

I understand that all I should need for it is available using _Date_Time_GetTimeZoneInformation, but I'm having a problem with that function. It seems to be returning the wrong value for the date of the start of DST for my system.

If I run this code:

#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

; Under Vista the Windows API "SetTimeZoneInformation" may be rejected due to system security

Global $iMemo


Func Example()
    Local $aOld, $aNew

    ; Create GUI
    GUICreate("Time", 400, 300)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

    ; Show current time zone information
    $aOld = _Date_Time_GetTimeZoneInformation()
    ShowTimeZoneInformation($aOld, "Current")

    ; Loop until the user exits.
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; Show time zone information
Func ShowTimeZoneInformation(ByRef $aInfo, $comment)
    MemoWrite("******************* " & $comment & " *******************")
    MemoWrite("Result ............: " & $aInfo[0])
    MemoWrite("Current bias ......: " & $aInfo[1])
    MemoWrite("Standard name .....: " & $aInfo[2])
    MemoWrite("Standard date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[3]))
    MemoWrite("Standard bias......: " & $aInfo[4])
    MemoWrite("Daylight name .....: " & $aInfo[5])
    MemoWrite("Daylight date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[6]))
    MemoWrite("Daylight bias......: " & $aInfo[7])
EndFunc   ;==>ShowTimeZoneInformation

Which is just the example from the help file, but not trying to "set" anything, just displaying the current values, I get:


******************* Current *******************

Result ............: 1
Current bias ......: 300
Standard name .....: Eastern Standard Time
Standard date/time : 11/01/0000 02:00:00
Standard bias......: 0
Daylight name .....: Eastern Daylight Time
Daylight date/time : 03/02/0000 02:00:00
Daylight bias......: -60


Two issues with this:

1) Without the "year", it is a bit hard to convert this to a Windows timestamp, I'm not even sure how I would go about that. I'm not looking to end up with a "structure", or a formatted date/time string, but a Windows timestamp number like 13067520236.

2) The value for Daylight date/time is just incorrect. In Washington DC, USA (my location) the change to DST will be on 03/08/2015 02:00:00.

I suspect it is somehow related to the way the $tagSYSTEMTIME structure works, with the date for "day" seeming to consist of the "number of the week" in the month, and the "number of the day" in the week. The 8th of March 2015 is in fact the "zeroth" day of the week (Sunday) of the "2nd" week of the month, which is where I assume the bogus "day 2" is coming from. That's fine, however, I would assume that _Date_Time_SystemTimeToDateTimeStr would be able to handle that. Anyone run into this or have any idea why the example from the AutoIt help wouldn't work as expected?

Windows 8.1 64bit

AutoIt v3.3.12.0

Edited by jsmorley
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

  • Recently Browsing   0 members

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