c.haslam Posted September 28 Share Posted September 28 (edited) My PC is in the northern hemisphere. My script needs to know whether another PC running my script is in the northern or southern hemisphere. This is needed to determine if Daylight time is in effect from April to November or from November to April. Edited September 28 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
jchd Posted September 28 Share Posted September 28 This information has nothing to do with hemispheres! _Date_Time_GetTimeZoneInformation() is your friend. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
c.haslam Posted September 29 Author Share Posted September 29 (edited) $ar = _Date_Time_GetTimeZoneInformation($ar) on my PC is returning, today: $ar[0]=2, $ar[1]=300, $ar[2]="Eastern Standard Time", $ar[4]=0, $ar[5] = "Eastern Daylight Time", $ar[7]=-60 . ($ar[3] and $ar[6] are structs.) My PC (and I) are on EDT until 2 AM on first Sunday of November. We are indeed now 5 hours (300 minutes) behind UCT (GMT). I am using TaskScheduler.au3. It requires that the start and end boundaries, for _TS_Wrapper_TriggerLogon(), be in the format YYYY-MM-DDTHH:MM:SS(+-)HH:MM i.e. time in UCT + or - bias. Example: 2024-09-28T14:20:55-05:00 Let's say that the user wants to set a trigger today, in local time, on 2024-12-14 at 14:20:25. My script has to convert it to the required format. In the northern hemisphere while we are on Daylight time now, on 2024-12-14 my PC will be on Standard time, so the bias will then be -04:00 . But a user in the southern hemisphere will be on Daylight time because his Daylight time runs from November to April, so for a user in a country in the southern hemisphere his bias would decrease So the hemisphere matters. A question: when my PC changes to Standard time on November 3, what will $ar[1] , $ar[2] and $ar[7] be ? I find descriptions in the help for return value confusing. A user can enter any date he wishes. Hd enters it in local time, not UCT. Of course, _Date_Time_GetTimeZoneInformation() get the current information, not the information for a future date. Edited September 29 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
argumentum Posted September 29 Share Posted September 29 ..and, what if that country does not follow daylight time ? ( Iran, Jordan, Namibia, Russia, Samoa, Syria, Turkey, Uruguay, Mexico ) What then ? What if that changes after your software is done ? What if a user wants to wake up at 7:00, will UTC have anything to do with local time ? Is always 5 in the afternoon somewhere. I'll go for a drink now Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
c.haslam Posted September 29 Author Share Posted September 29 My script does handle Daylight time not being used. In this case, the 0th element returned by _Date_Time_GetTimeZoneInformation() is zero. BTW TaskScheduler.au3 provides access to Windows' Task Scheduler. Windows has the same format: see https://learn.microsoft.com/en-us/windows/win32/taskschd/trigger-startboundary Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
jchd Posted September 29 Share Posted September 29 DST has nothing to do with North, South, East or West. DST is decided by the rules in force in the country/region/city and the timestamp you consider. 7 hours ago, c.haslam said: ($ar[3] and $ar[6] are structs.) This where DST details are available. 7 hours ago, c.haslam said: time in UCT + or - bias. Example: 2024-09-28T14:20:55-05:00 This timestamp format is not UTC, it is local time. The last part (-05:00) indicates the shift from/to UTC. You must subtract this value to get UTC. This exemple is = 2024-09-28 19:20:55Z 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Somerset Posted September 29 Share Posted September 29 @c.haslamAsking the user a question is out right impossible? gps device? water spin query? celestial observation question? Link to comment Share on other sites More sharing options...
jchd Posted September 29 Share Posted September 29 1 hour ago, Somerset said: water spin query? That is urban legend. Coriolis force is way too weak to impact water in a sink. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
c.haslam Posted September 29 Author Share Posted September 29 (edited) Quoting Microsoft: "For example the date October 11th, 2005 at 1:21:17 in the Pacific Time zone would be written as 2005-10-11T13:21:17-08:00" Assume this is a startBoundary for a trigger. On a PC in Vancouver, the user's task would trigger when the Windows desktop clock shows 1:21 PM, October 11 being in Standard time. But consider 2005-08-11T13:21:17T-08:00. The user' task would trigger on August 11th, 2005 when the Windows desktop clock shows 12:21 PM ! For the task to trigger when the Windows desktop clock 1:21 PM when Daylight time is in effect, the parameter needs to be 2005-08-11T13:21:17T-09:00 So Standard vs. Daylight matters. Edited September 29 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
c.haslam Posted September 29 Author Share Posted September 29 My current northern hemisphere code is below. It has not been tested. expandcollapse popupFunc FormatBoundaryForTS_NorthernHemisphere($LocalDateTime) Local $ar = _Date_Time_GetTimeZoneInformation() Local $biasMins If $ar[0]=0 Then $biasMins = - $ar[1] Else ; The Help is not clear to me: On my PC on 2024-09-25, on daylight time, $ar[0] is 2, $ar[1] is 300, $ar[4] is 0 and $ar[7] is -60 Local $vec = StringSplit($LocalDateTime,"/ :") Local $yr = $vec[1], $mon = $vec[2], $day = $vec[3] Local $bSummer Switch ($mon) ; Summer (DayLight Saving) from 2nd Sunday in Apr to day before 2nd Sunday in Nov Case 3 ; Mar Local $q = 0 For $i = 1 to 30 if _DateToDayOfWeek($yr,3,$i) = 1 Then ; Sunday $q += 1 if $q=2 Then ExitLoop EndIf EndIf Next $bSummer = $day >= $i Case 11 ; Nov For $i = 1 to 30 if _DateToDayOfWeek($yr, 11, $i) = 1 Then ExitLoop EndIf Next $bSummer = $day < $i Case 4 to 10 $bSummer = True Case Else $bSummer = False EndSwitch If $bSummer Then $biasMins = - $ar[1] ; Eastern: $biasMins = -300 (-5 hours) Else $biasMins = -($ar[1] + $ar[7]) ; Eastern: $biasMins = -300 + 50 (-4 hours) EndIf EndIf Local $ret $ret = _DateAdd("n",$biasMins,$LocalDateTime) $ret = StringReplace($ret,"/","-") $ret = StringReplace($ret," ","T") if $biasMins>0 Then $ret &= "-" Else $ret &= "+" EndIf Local $hours = Int($biasMins/60) Local $mins = Mod($ret,60) Local $t = StringRegExp("%02d:%02d",$hours,$mins) $ret &= $t Return $ret EndFunc Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Dan_555 Posted September 29 Share Posted September 29 (edited) deleting this Edited October 1 by Dan_555 deleting Some of my script sourcecode Link to comment Share on other sites More sharing options...
argumentum Posted September 29 Share Posted September 29 1 hour ago, c.haslam said: "For example the date October 11th, 2005 at 1:21:17 in the Pacific Time zone would be written as 2005-10-11T13:21:17-08:00" Then don't. Don't add the "-08:00" From the example "StartBoundary (triggerBaseType) Element" <BootTrigger> <StartBoundary>2005-01-01T08:00:00</StartBoundary> <EndBounadry>2007-01-01T08:00:00</EndBoundary> <Enabled>true</Enabled> <Repetition></Repetition> <ExecutionTimeLimit></ExecutionTimeLimit> <Delay><Delay> </BootTrigger> Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
jchd Posted September 29 Share Posted September 29 I never used the TaskScheduler.au3 UDF but it should store event datetime stamps in UTC, without any offset. The task should trigger when the PC UTC clock matches that of the scheduler, period. Exactly like what @argumentum posted while I was typing. UTC is the same for everyone everywhere on Earth and anytime. Of course if you move your laptop from one timezone + DST rule to another area having another set of rules, without telling your PC that the local rules have changed, then the bell will ring at the wrong time. Contrary to a laptop, a smartphone connected to a local GSM network knows when you change location and hopefully adjusts the local parameters to where you go. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
argumentum Posted September 29 Share Posted September 29 ...reading stuff..., the technical writer will take you to the exquisite scenarios that their code can do !, and that can confuse the reader as if that is the only practical way to get something done. Our own UDFs have the _funcWhatever() and the _funcWhateverEx() where the Ex version is quite impractical but there, as it is more powerful but generally, uselessly cumbersome to use. Hence the non-Ex version. In this case, where the time zone can be included, the technical writer presents a situation to justify it's existence. But does not make a case that is not a necessity Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Somerset Posted September 29 Share Posted September 29 (edited) The OP could go through ip location web site. <-regretting thinking of it. Edited September 29 by Somerset Link to comment Share on other sites More sharing options...
jchd Posted September 29 Share Posted September 29 That's not reliable (VPN or ISP not under exact same rules) nor enough. Even a GPS location doesn't tell you which rules are in force, even less which rules to use elsewhere in some future. Look at how fast all those things change: https://time.is/fr/time_zone_news 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
c.haslam Posted September 30 Author Share Posted September 30 (edited) argumentum's post re (+-)HH;MM is interesting. I wonder, if one omits (+-)HH;MM, whether the startBoundary is in UTC or in local datetime. It is surprising that Microsoft do not state that (+-)HH:MM is optional. jchd wrote: "it should store event datetime stamps in UTC, without any offset". If this is the case, I still have a problem. My script is an appointment reminder. Through a GUI, the user enters a date and time plus a message. The script creates a task. At the datetime, the task runs, running AutoIt code that creates a msgBox. An example for a user on Eastern Daylight time assuming that startBoundary without (+-)HH:MM is in local time: User enters 2024-12-01 09:00 and "It's time to go". The script creates a task with startBoundary 2024-12-01T09:00 At 2024-12-01 09:00 local, the task runs if startBoundary is in local time The user sees a msgBox. But if the startBoundary is UCT the task would run at 05:00, long before he awakes. Experimentation shows that without (+-)HH:MM startBoundary is in UCT. To handle startBoundary being in UCT, the difference between Daylight and UCT is required. There are 2 ways, with $udt = "2024/12/01 09:00" Way 1 $udt = StringReplace($udt, "/", "-") $edt = StrinhReplace($udt," " , "T") $$tartBoundary = $udt & "-04:00" Way 2 $dt = _DateAdd(-4, "h", $udt) $udt = StringReplace($dt,"/", "-") $startBoundary = StringReplace($dt," ", "T") Both should work. Both require the time zone. I accept that my script will only work for users in countries that: do not have Daylight time have Daylight time from the third Sunday in April to the first Sunday in November. Edited September 30 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
argumentum Posted September 30 Share Posted September 30 (edited) I'd guess that if the UTC marker is not there, local time is used. Try it on your PC ( some event 2 minutes in the future ) and let us know. Edit: unless you reside in Greenwich Edited September 30 by argumentum fun Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
jchd Posted September 30 Share Posted September 30 There is no such thing as an UTC marker! The letter Z sometimes found at the end of a timestamp means "Zulu", for Zero. The time before is both UTC and local in timezone +0 (they are equal). BTW, Greenwich is to be forgotten, speaking of time. GMT has no more any reasonable meaning since 1972-01-01. Use UTC instead. argumentum 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Solution c.haslam Posted October 1 Author Solution Share Posted October 1 (edited) Running this script shows that without (+-)HH:MM, $startTime and $endTime are in local time: #include "TaskScheduler.au3" Local $oService = _TS_Open() Local $startTime = _DateAdd("n",3,_NowCalc()) $startTime = StringReplace($startTime,"/","-") $startTime = StringReplace($startTime," ","T") Local $endTime = _DateAdd("n",20,_NowCalc()) $endTime = StringReplace($endTime,"/","-") $endTime = StringReplace($endTime," ","T") Local $oTaskDefinition = _TS_Wrapper_TaskCreate($oService, "", "") _TS_Wrapper_PrincipalSet($oTaskDefinition,$TASK_LOGON_INTERACTIVE_TOKEN) _TS_Wrapper_TriggerDateTime($oTaskDefinition,$TASK_TRIGGER_TIME,0, 0, $startTime,$endTime) _TS_Wrapper_ActionCreate($oTaskDefinition,"Notepad") if _TS_FolderExists($oService,"\Test")=0 Then _TS_FolderCreate($oService,"\Test") EndIf _TS_Wrapper_TaskRegister($oService, "\Test","starttime",$oTaskDefinition, Default, Default,$TASK_LOGON_INTERACTIVE_TOKEN) MsgBox(1,30,"$startTime " & $startTime & " $endTime " & $endTime) _TS_Close($oService) Microsoft should say this. I was confused by $TASK_LOGON_INTERACTIVE_TOKEN. It means when the user is logged on. As MS says: "User must already be logged on. The task will be run only in an existing interactive session" Causing a task to run soon after logging on appears to depend on the Delay parameter being set. Such a task also needs $TASK_LOGON_INTERACTIVE_TOKEN. BTW when the task has run, the task continues to exist but has Next Run Time as N/A in schtasks /query and no value in _TS_TaskList(). When the task has run, call _TS_TaskDelete() to delete it after Notepad opens. Edited October 1 by c.haslam Added "to delete it after Notepad opens" argumentum 1 Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
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