BeardedBlunder Posted June 16, 2007 Posted June 16, 2007 This has me stumped, my abilities with AutoIT run to simple Do-Until loops & If-Then type stuff, I would greatly appreciate if someone could come up with a simple method of determining the local time offset from UTC (GMT) at the time a given file was created. Ideally something that will run on the machine that created the file & return the offset in hours so that a footnote can be added "Timestamps printed within this log are GMT +/-n hours" matters being complicated by the fact the daily logs may be up to a couple of years old, & in regions which may or may not use daylight saving times, & may be running either 9x/ME or an NT variant (4 through Vista) I'm afraid my eyeballs are bleeding after reading possible calls to windows DLL files on MSDN, or trying to query the registry for offsets.. the calculation as to if or if not DST was in effect would be complex enough (although doable) but (I'm probably dim) I couldn't turn the value listed in my registry into a one hour offset for BST by any obvious means... and as for translating the DST starts & ends values.... I think Mr Gate$ purposely stored the info in an awkward fashion... though the current offset can at least be read from there, the difficulty is, that may not have been the offset last week...
herewasplato Posted June 16, 2007 Posted June 16, 2007 Maybe someone can help with AutoIt/WMI and this info:http://www.microsoft.com/technet/scriptcen...u.mspx?mfr=true [size="1"][font="Arial"].[u].[/u][/font][/size]
BeardedBlunder Posted June 16, 2007 Author Posted June 16, 2007 thanks for the input, looks like i have some serious reading to do, both there & in the helpfile.
PaulIA Posted June 16, 2007 Posted June 16, 2007 thanks for the input, looks like i have some serious reading to do, both there & in the helpfile.You might want to have a look at the Auto3Lib Time functions (see my signature for download). There are several functions that convert times between the 5 different times that Windows supports. I believe what you are looking for would be handled by _Time_FileTimeToSystemTime. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 16, 2007 Author Posted June 16, 2007 thanks for the heads up on functions to use these calls, i'm positive i can now get the information i'm after _Time_GetFileTime (should be UTC right?) _Time_FileTimeToLocalFileTime simple sums should get me the difference between local time & UTC when the file was created yes? this is the specific info i'm needing to determine. _Time_GetTimeZoneInformation looks like it will/might come in handy too
PaulIA Posted June 16, 2007 Posted June 16, 2007 thanks for the heads up on functions to use these calls, i'm positive i can now get the information i'm after_Time_GetFileTime (should be UTC right?)_Time_FileTimeToLocalFileTimesimple sumsshould get me the difference between local time & UTC when the file was created yes?this is the specific info i'm needing to determine._Time_GetTimeZoneInformationlooks like it will/might come in handy tooI think you've got it. GetFileTime will give you the local time in UTC. FileTimeToLocalTime will covert that value to your local time. GetTimeZoneInformation will give you daylight savings time information and the time bias (difference between UTC and local time) for your time zone. Feel free to PM me if you have any problems/questions/suggestions. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 17, 2007 Author Posted June 17, 2007 OK, seems reasonable now I've slept some, except for some odd reason _Time_GetTimeZoneInformation fails to return the correct active bias on my system.... although the rest of the information seems correct & I'm rather at a loss what's going on... having edited the example script down to this: #include <A3LTime.au3> ; Global variables Global $hGUI, $iMemo, $aOld ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Show current time zone information $aOld = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aOld) ; Loop until user exits do until GUIGetMsg() = $GUI_EVENT_CLOSE ; Show time zone information Func ShowTimeZoneInformation(ByRef $aInfo) MemoWrite("Result ............: " & $aInfo[0] ) MemoWrite("Current bias ......: " & $aInfo[1] ) MemoWrite("Standard name .....: " & $aInfo[2] ) MemoWrite("Standard date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[3])) MemoWrite("Standard bias......: " & $aInfo[4] ) MemoWrite("Daylight name .....: " & $aInfo[5] ) MemoWrite("Daylight date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[6])) MemoWrite("Daylight bias......: " & $aInfo[7] ) MemoWrite() EndFunc I get the following Result Result ............: 2 Current bias ......: 0 Standard name .....: GMT Standard Time Standard date/time : 10/05/0000 02:00:00 Standard bias......: 0 Daylight name .....: GMT Daylight Time Daylight date/time : 03/05/0000 01:00:00 Daylight bias......: -60 clearly incorrect for British Summer Time (GMT Daylight Time if you must) where the bias should clearly be -60) indeed consulting my registry HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation it shows this: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] "Bias"=dword:00000000 "StandardName"="GMT Standard Time" "StandardBias"=dword:00000000 "StandardStart"=hex:00,00,0a,00,05,00,02,00,00,00,00,00,00,00,00,00 "DaylightName"="GMT Daylight Time" "DaylightBias"=dword:ffffffc4 "DaylightStart"=hex:00,00,03,00,05,00,01,00,00,00,00,00,00,00,00,00 "ActiveTimeBias"=dword:ffffffc4 Since "ActiveTimeBias"=dword:ffffffc4 And "DaylightBias"=dword:ffffffc4 (-60 Minutes) Clearly Current bias ......: 0 is WRONG...
PaulIA Posted June 17, 2007 Posted June 17, 2007 OK, seems reasonable now I've slept some, except for some odd reason _Time_GetTimeZoneInformation fails to return the correct active bias on my system.... although the rest of the information seems correct & I'm rather at a loss what's going on... having edited the example script down to this: #include <A3LTime.au3> ; Global variables Global $hGUI, $iMemo, $aOld ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Show current time zone information $aOld = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aOld) ; Loop until user exits do until GUIGetMsg() = $GUI_EVENT_CLOSE ; Show time zone information Func ShowTimeZoneInformation(ByRef $aInfo) MemoWrite("Result ............: " & $aInfo[0] ) MemoWrite("Current bias ......: " & $aInfo[1] ) MemoWrite("Standard name .....: " & $aInfo[2] ) MemoWrite("Standard date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[3])) MemoWrite("Standard bias......: " & $aInfo[4] ) MemoWrite("Daylight name .....: " & $aInfo[5] ) MemoWrite("Daylight date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[6])) MemoWrite("Daylight bias......: " & $aInfo[7] ) MemoWrite() EndFunc I get the following Result Result ............: 2 Current bias ......: 0 Standard name .....: GMT Standard Time Standard date/time : 10/05/0000 02:00:00 Standard bias......: 0 Daylight name .....: GMT Daylight Time Daylight date/time : 03/05/0000 01:00:00 Daylight bias......: -60 clearly incorrect for British Summer Time (GMT Daylight Time if you must) where the bias should clearly be -60) indeed consulting my registry HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation it shows this: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] "Bias"=dword:00000000 "StandardName"="GMT Standard Time" "StandardBias"=dword:00000000 "StandardStart"=hex:00,00,0a,00,05,00,02,00,00,00,00,00,00,00,00,00 "DaylightName"="GMT Daylight Time" "DaylightBias"=dword:ffffffc4 "DaylightStart"=hex:00,00,03,00,05,00,01,00,00,00,00,00,00,00,00,00 "ActiveTimeBias"=dword:ffffffc4 Since "ActiveTimeBias"=dword:ffffffc4 And "DaylightBias"=dword:ffffffc4 (-60 Minutes) Clearly Current bias ......: 0 is WRONG... There's nothing wrong with the output other than the way you're trying to read it. Take a look at MSDN and read the bias descriptions carefully and then consider that you're in GMT time, where there is no time offset. I think you'll figure it out. Just use the appropriate calls to convert file time to system time and vice versa and you won't drive yourself bonkers trying to figure out how it works. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 17, 2007 Author Posted June 17, 2007 There's no offset in the winter, you're quite correct, however there IS currently an hour's offset as we're in daylight saving time..which the very fist item on the output indicates..quoting from http://msdn2.microsoft.com/en-us/library/ms724421.aspxReturn Value If the function succeeds, it returns one of the following values. Return code/value Description TIME_ZONE_ID_UNKNOWN 0 Daylight saving time is not used in the current time zone, because there are no transition dates. TIME_ZONE_ID_STANDARD 1 The system is operating in the range covered by the StandardDate member of the TIME_ZONE_INFORMATION structure. Windows Me/98/95: This value is returned if daylight saving time is not used in the current time zone, because there are no transition dates. TIME_ZONE_ID_DAYLIGHT 2 The system is operating in the range covered by the DaylightDate member of the TIME_ZONE_INFORMATION structure.as you see in my previous post, the return value is 2 correctly stating that i'm in the daylight saving timespani might add, that before i edited the example script down to what's above, i watched my clock change one hour as it "restored" me to GMT when i started on BST (sorry "GMT Daylight Time")..& each time i then had to open regional settings, uncheck & recheck "automatically adjust for DST", hitting apply between each to get back to daylight saving time...
PaulIA Posted June 18, 2007 Posted June 18, 2007 There's no offset in the winter, you're quite correct, however there IS currently an hour's offset as we're in daylight saving time.. which the very fist item on the output indicates.. quoting from http://msdn2.microsoft.com/en-us/library/ms724421.aspx Return Value If the function succeeds, it returns one of the following values. Return code/value Description TIME_ZONE_ID_UNKNOWN 0 Daylight saving time is not used in the current time zone, because there are no transition dates. TIME_ZONE_ID_STANDARD 1 The system is operating in the range covered by the StandardDate member of the TIME_ZONE_INFORMATION structure. Windows Me/98/95: This value is returned if daylight saving time is not used in the current time zone, because there are no transition dates. TIME_ZONE_ID_DAYLIGHT 2 The system is operating in the range covered by the DaylightDate member of the TIME_ZONE_INFORMATION structure. as you see in my previous post, the return value is 2 correctly stating that i'm in the daylight saving timespan i might add, that before i edited the example script down to what's above, i watched my clock change one hour as it "restored" me to GMT when i started on BST (sorry "GMT Daylight Time").. & each time i then had to open regional settings, uncheck & recheck "automatically adjust for DST", hitting apply between each to get back to daylight saving time...You're still missing the point. I know you're in DST, but you totally ignored my advice about looking at MSDN regarding the bias value, so I guess I'll have to do it for you. DaylightBias The bias value to be used during local time translations that occur during daylight saving time. This member is ignored if a value for the DaylightDate member is not supplied. This value is added to the value of the Bias member to form the bias used during daylight saving time. In most time zones, the value of this member is 60.The part you should have paid attention to is: This value is added to the value of the Bias member to form the bias used during daylight saving time.So if you want to calculate the bias used during DST, you'd add the DaylightBias value to the Bias value to get your answer. Likewise, if you want to calculate the bias when you're not in DST, you'd add the StandardBias value to the Bias value to get your answer. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 18, 2007 Author Posted June 18, 2007 (edited) Well here's MY point: Runninhg your example script quoted below: expandcollapse popup#include <A3LTime.au3> ; Global variables Global $hGUI, $iMemo, $aOld, $aNew ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Show current time zone information $aOld = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aOld) ; Set new time zone information _Time_SetTimeZoneInformation($aOld[1], "A3L CST", $aOld[3], $aOld[4], "A3L CDT", $aOld[6], $aOld[7]) ; Show new time zone information $aNew = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aNew) ; Reset original time zone information _Time_SetTimeZoneInformation($aOld[1], $aOld[2], $aOld[3], $aOld[4], $aOld[5], $aOld[6], $aOld[7]) ; Loop until user exits do until GUIGetMsg() = $GUI_EVENT_CLOSE ; Write message to memo Func MemoWrite($sMessage="") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ; Show time zone information Func ShowTimeZoneInformation(ByRef $aInfo) MemoWrite("Result ............: " & $aInfo[0] ) MemoWrite("Current bias ......: " & $aInfo[1] ) MemoWrite("Standard name .....: " & $aInfo[2] ) MemoWrite("Standard date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[3])) MemoWrite("Standard bias......: " & $aInfo[4] ) MemoWrite("Daylight name .....: " & $aInfo[5] ) MemoWrite("Daylight date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[6])) MemoWrite("Daylight bias......: " & $aInfo[7] ) MemoWrite() EndFunc PERMANENTLY changes the registry entry [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] "ActiveTimeBias"=dword:ffffffc4 which windows sets at this time of year if automatically adjust for daylight saving time is selected to: ""ActiveTimeBias"=dword:00000000 which it should NOT do. as the sum appears in that registry entry not the base value quoting from http://www.windowsitpro.com/Article/Articl...4966/14966.html ActiveTimeBias This value is the current time difference from Greenwich Mean Time (GMT) in minutes and is the difference for GMT. For example, if youre 1 hour ahead, GMT is 1 hour behind. The value would be ffffffc4, which is hexadecimal for -60.and in fact they're right because it is at least until after your example script runs! which also has the rather annoying side-effect of resetting my clock wrong by one hour Edited June 18, 2007 by BeardedBlunder
PaulIA Posted June 18, 2007 Posted June 18, 2007 Well here's MY point: Runninhg your example script quoted below: expandcollapse popup#include <A3LTime.au3> ; Global variables Global $hGUI, $iMemo, $aOld, $aNew ; Create GUI $hGUI = GUICreate("Time", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Show current time zone information $aOld = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aOld) ; Set new time zone information _Time_SetTimeZoneInformation($aOld[1], "A3L CST", $aOld[3], $aOld[4], "A3L CDT", $aOld[6], $aOld[7]) ; Show new time zone information $aNew = _Time_GetTimeZoneInformation() ShowTimeZoneInformation($aNew) ; Reset original time zone information _Time_SetTimeZoneInformation($aOld[1], $aOld[2], $aOld[3], $aOld[4], $aOld[5], $aOld[6], $aOld[7]) ; Loop until user exits do until GUIGetMsg() = $GUI_EVENT_CLOSE ; Write message to memo Func MemoWrite($sMessage="") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ; Show time zone information Func ShowTimeZoneInformation(ByRef $aInfo) MemoWrite("Result ............: " & $aInfo[0] ) MemoWrite("Current bias ......: " & $aInfo[1] ) MemoWrite("Standard name .....: " & $aInfo[2] ) MemoWrite("Standard date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[3])) MemoWrite("Standard bias......: " & $aInfo[4] ) MemoWrite("Daylight name .....: " & $aInfo[5] ) MemoWrite("Daylight date/time : " & _Time_SystemTimeToDateTimeStr($aInfo[6])) MemoWrite("Daylight bias......: " & $aInfo[7] ) MemoWrite() EndFunc PERMANENTLY changes the registry entry [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] "ActiveTimeBias"=dword:ffffffc4 which windows sets at this time of year if automatically adjust for daylight saving time is selected to: ""ActiveTimeBias"=dword:00000000 which it should NOT do. as the sum appears in that registry entry not the base value quoting from http://www.windowsitpro.com/Article/Articl...4966/14966.html and in fact they're right because it is at least until after your example script runs! which also has the rather annoying side-effect of resetting my clock wrong by one hour Look, if you open the A3LTime.au3 file and look at the code in _Time_GetTimeZoneInformation you'll see that I'm doing nothing but returning the values supplied by the API function. No smoke, no mirrors, no manipulation to the bias values. Same thing with _Time_SetTimeInformation. In neither function am I'm not doing ANYTHING to the registry. The registy is updated by the API calls themselves, not Auto3Lib. As for the code not working, it's working fine on the three machines I've tested here. You probably need to open you clock, switch to the "Internet Time" tab and resync you system clock to start with. Also, if you read the MSDN information, you'll see that you need to send the WM_SETTINGCHANGE message so that Explorer will update it's time setting. I don't force that in the calls so that you have the option of doing it yourself, or switching the time back and forth without Explorer knowing. I'm trying to help you out, so you need to lighten up a bit on the attitude. You're not grasping the basic difference between the time zone your computer is in and the settings for DST. The time zone you set your computer to determines the "Bias" value that is returned by GetTimeZoneInformation. This is the difference between your locale and GMT, regardless of DST. For you, this value will be 0. For me, it's 360. Those values will never change unless you change your time zone setting. I'm in daylight savings time too, so when I run GetTimeZoneInformation, it returns 2 as the result, but my bias is still 360. However, because the result is 2, I know that I need to add the DaylightBias value to the Bias to get my true local bias, which in my case would be 300. This is also the value that gets set in "ActiveTimeBias" in the registry. If GetTimeZoneInformation returned 0 instead of 2, I'd add the StandardBias value to Bias to get my true local bias. Now, armed with this information, let's go back to your WindowsItPro web site and read the description for "Bias". It says: This value is the normal time difference from GMT, excluding daylight saving in minutesPretty plain, isn't it. The Bias value is the GMT delta excluding DST adjustment just like I've been telling you. Next, look at the description for DaylightBias: This value is the time difference used for daylight saving for GMT. If you're 1 hour ahead, the value is ffffffc4, which is hex for -60. Notice that the ActiveTimeBias is the sum of Bias and DaylightBias in daylight saving months, which is the same as Bias for standard months.Again, same thing I've been telling you all along. So from here, it's up to you. You can argue with me, MSDN, Micorosft and WindowsItPro or you can take a deep breath, do a little bit of research and learn. Your choice. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 18, 2007 Author Posted June 18, 2007 (edited) what "internet time" tab would that be? i've never seen such a tab on any machine i've run.. which includes all windows versions from 3.1 to 2000 look i'm not being funny, i don't know why it's setting my clock wrong either, but the fact remains that it does.... Edited June 18, 2007 by BeardedBlunder
PaulIA Posted June 18, 2007 Posted June 18, 2007 what "internet time" tab would that be? i've never seen such a tab on any machine i've run.. which includes all windows versions from 3.1 to 2000look i'm not being funny, i don't know why it's setting my clock wrong either, but the fact remains that it does....I guess you don't know about Windows XP? I can see there is not much more that I can help you with here. I hope you solve the problem with your machine. Auto3Lib: A library of over 1200 functions for AutoIt
BeardedBlunder Posted June 18, 2007 Author Posted June 18, 2007 lol, i've seen XP just not used it more than an odd hour here & there, i don't like the Fischer-Price interface & a few other details, rather put me off "Upgrading" if indeed i'd gain much from 2000pro....Look i never intended to get your back up in this, it's been a bit frustrating, i have an uncanny knack at having computers do weird-shit they shouldn't, i could type reams of examples... never simple weird shit either, where experts look & go "Oh yes it's <insert fix/thing i did wron>" but always stuff that takes younks to identify the root of.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now