Jump to content
Sign in to follow this  
Rogue5099

World Clock(s) - (by cities)

Recommended Posts

Rogue5099

The main goal for me is to show the time in different locations to be able to know when to call my kids while out of their time zone.
 v20d.png
0rfl.png
The screenshots above are 2 separate images showing either 2 or 4 clocks.
This is something I wrote awhile ago and had to reuse.  It's very simple in design so if anyone wants to spruce it up a bit be my guest and please share as well.
 

Time Zone Clocks.au3
Time Zone Clocks.au3
-Added a check to make sure InputBox's are numbers
-Decreased size of GUI to get rid of last line label
-Changed GUICtrlSetData to ControlSetText (increased speed of Data Function)
-Changed only to update Label's if different to avoid flickering
-Changed AdlibRegister from 900ms to 60ms*Number of Clocks (Maybe a little more CPU usage)
 
Time Zone Clocks.au3
-Added city code list to program
-Replace InputBox's with GUI to enter city codes
-Can search cities by typing in city name
-Now you can input all city codes in 1 input with a comma separating them i.e. 100,200,300
-Now just double click the city in the list to add to input
-Disabled editing of Input Box on starting GUI
-Added Error check for no cities selected
-Added AdlibUnRegister to prevent errors while closing

Edited by Rogue5099
  • Like 2

Share this post


Link to post
Share on other sites
czardas

Interesting idea. I don't get why there is a discrepancy of minutes. I was under the impression that all major cities had synchronized minutes at different hours.

Share this post


Link to post
Share on other sites
czardas

I'm not sure why but I'm getting a half hour discrepancy. I included cities 1,2,3,4,5 and ATM I have 24 mins past the hour for the first four and 54 mins for location #5.

Share this post


Link to post
Share on other sites
trancexx

^^ Uhm, why would that be weird?

I believe there are some time zones that are on 45(15) minutes.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
czardas

Interesting! I always look at New York, Greenwich, Moscow and Tokyo; so maybe that's why I never noticed before.

Share this post


Link to post
Share on other sites
Rogue5099

Even after making this I didn't realize that there where time zones with +:30.  I was always under the impression that it was hourly difference.
But #5 is Standard time zone:UTC/GMT +9:30 hours.

The screen shots was 2 different screenshots. one showing 2 clocks other showing 4 clocks displayed.

Share this post


Link to post
Share on other sites
Woongjinn

I think you will find that the descrepency is with the SECONDS not the minutes, which is definitely weird.

Toyko is out by one second or did you manage to take the screen shot at the exact nano second between the previous label being updated and the Tokyo second label update?

Share this post


Link to post
Share on other sites
czardas

I think you will find that the descrepency is with the SECONDS not the minutes, which is definitely weird.

 

To quote trancexx:

^^ Uhm, why would that be weird?

 

Data taken from the internet is updated every 900 ms.

Edited by czardas

Share this post


Link to post
Share on other sites
Rogue5099

I think you will find that the descrepency is with the SECONDS not the minutes, which is definitely weird.

Toyko is out by one second or did you manage to take the screen shot at the exact nano second between the previous label being updated and the Tokyo second label update?

If you would like to make it more exact you can change AdlibRegister("Data", 900) to AdlibRegister("Data", 1) but this will cause issues with running a function within a function. I gave it 900ms so it would refresh faster than 1 sec but not to refresh when not needed.  As they are updated, the more you have to update could cause slower updating in the loop.  As with each clock that you have up and being checked there is a IE window created and hidden so that the GUI label is just refreshed from the information on the IE window (internet is needed).

With that said the more clocks you have and the less time you have in AdlibRegister could cause issues with trying to call the same function within the function.  These may not be atomic correct times but for the purpose of what I used it for I didn't need it to be 100% accurate in seconds for each clock.

The best course of action then to produce the best results would be to get the TimeDiff from the start and end of function Data with only 1 clock then multiply that number by the number of clocks you want to display and have that time in AdlibRegister.

With testing 1 clock these are the times in milliseconds I got from Func Data on my PC:

43.058
83.43464
47.38076
50.15828
52.25076
48.30376
50.14248
52.64456
48.62912
48.8666
50.00072
93.71848
110.1198
50.57468
48.40488
47.58964
45.25168
67.81452
50.54272
53.72544
45.7398
50.44452
71.61796
51.50776
53.79732
53.28008
52.90824
62.01012
68.1924
54.64068
68.96068

When I ran 4 clocks this is the times I got:

193.9596
213.60644
181.65668
249.9956
199.44112
234.69924
239.09508
204.8738
193.12848
206.90724
224.4944
204.79032
231.15596
222.28516
215.65376
276.06464
233.51004
195.14132
248.34272
215.23612
337.27056
260.39708
269.62832
226.61864

So with that data I would say >= 80ms would be a good time for 1 clock.  So 4 clocks >= 240ms.

 

Edit:

After a few more tests I came up with an approximate 60ms would be enough time for each clock which should update the GUI more approximately. made the following changes and updated original post.

-Added a check to make sure InputBox's are numbers

-Decreased size of GUI to get rid of last line label

-Changed GUICtrlSetData to ControlSetText (increased speed of Data Function)

-Changed only to update Label's if different to avoid flickering

-Changed AdlibRegister from 900ms to 60ms*Number of Clocks (Maybe a little more CPU usage)

Edited by Rogue5099

Share this post


Link to post
Share on other sites
BrewManNH

Instead of using _IECreate, have you tried getting the data with INetRead instead? This reads the page's data directly without having to open a browser window. If it works, you'd be able to shave a lot of processing time off of the script when it gets the data and the data will be more accurate because of this.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Rogue5099

Instead of using _IECreate, have you tried getting the data with INetRead instead? This reads the page's data directly without having to open a browser window. If it works, you'd be able to shave a lot of processing time off of the script when it gets the data and the data will be more accurate because of this.

Wouldn't using something like this actually slow it down because it would constantly be downloading information? I guess it actually is constantly downloading via IE but I'm letting IE do the work of retrieving the info and just reading it from there.

 

I was wondering if you wouldn't mind making a drop down list for the city codes?

I wanted to make a searchable list with the city codes, just creating a GUI to add them and then starting clocks

 

But with both of these suggestions I am limited.  I have tried with the listview and I can't seem to get it to work at all not even loading the data.  I just keep hitting "writers block" I guess you could say.

Edited by Rogue5099

Share this post


Link to post
Share on other sites
Rogue5099

I was wondering if you wouldn't mind making a drop down list for the city codes?

I think I did my best on a GUI that you could search the cities instead of doing an extremely long drop down menu.

Share this post


Link to post
Share on other sites
Rogue5099

How do I select clocks?  I tried double clicking and pressing enter and dragging them.

After a lot of research I got it to read the double click on the list. Now just double click instead of typing the code into the inputbox. Also I added an error check to make sure you don't try to start without any cities selected.

While testing I also kept getting an error while closing the clocks so I UnRegistered the Adlib before closing out the IE windows (Hopefully that fixes error).

Share this post


Link to post
Share on other sites
Rogue5099

Instead of using _IECreate, have you tried getting the data with INetRead instead? This reads the page's data directly without having to open a browser window. If it works, you'd be able to shave a lot of processing time off of the script when it gets the data and the data will be more accurate because of this.

I tried doing this to maybe speed up things and maybe I'm going about it wrong trimming strings but after about 3-4 seconds with 3 clocks (which updates slower) it freezes and stops responding.  I also increased the Data Function Adlib time to 500 and it still froze.

Here is what I did (partial code):

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            AdlibUnRegister("Data")
            Exit
    EndSwitch
WEnd

Func Load()
    Local $source, $string
    For $i = 1 To $clock[0]
        $url = "http://www.timeanddate.com/worldclock/fullscreen.html?n=" & $clock[$i]
        $source = BinaryToString(InetRead($url))
        $string = StringTrimLeft($source, StringInStr($source, "Local time in ")+13)
        GUICtrlSetData($lRegion[$i], StringTrimRight($string, StringLen($string) - StringInStr($string, "<")+1))
        $string = StringTrimLeft($source, StringInStr($source, "i_date")+6)
        $LastDate[$i] = StringTrimRight($string, StringLen($string) - StringInStr($string, "<")+1)
        ControlSetText("Time Zone Clocks", "", $lDate[$i], $LastDate[$i])
        $string = StringTrimLeft($source, StringInStr($source, "i_time")+6)
        $LastTime[$i] = StringTrimRight($string, StringLen($string) - StringInStr($string, "<")+1)
        ControlSetText("Time Zone Clocks", "", $lTime[$i], $LastTime[$i])
    Next
EndFunc

Func Data()
    Local $source, $string
    For $i = 1 to $clock[0]
        $url = "http://www.timeanddate.com/worldclock/fullscreen.html?n=" & $clock[$i]
        $source = BinaryToString(InetRead($url))
        $string = StringTrimLeft($source, StringInStr($source, "i_date")+6)
        $NowDate[$i] = StringTrimRight($string, StringLen($string) - StringInStr($string, "<")+1)
        If $NowDate[$i] <> $LastDate[$i] Then
            ControlSetText("Time Zone Clocks", "", $lDate[$i], $NowDate[$i])
            $LastDate[$i] = $NowDate[$i]
        EndIf
        $string = StringTrimLeft($source, StringInStr($source, "i_time")+6)
        $NowTime[$i] = StringTrimRight($string, StringLen($string) - StringInStr($string, "<")+1)
        If $NowTime[$i] <> $LastTime[$i] Then
            ControlSetText("Time Zone Clocks", "", $lTime[$i], $NowTime[$i])
            $LastTime[$i] = $NowTime[$i]
        EndIf
    Next
EndFunc

Results from For Loop are much higher:

131.34124
110.6708
137.69644
126.71208
110.8096
109.84908
120.48992
117.0642
139.73032
308.22616
146.70876
142.31468
109.09884
179.2478
144.46088
134.70548
137.32684
140.49252
136.28304
132.43988
155.08944
118.719
116.2222
137.75136
134.03476
Edited by Rogue5099

Share this post


Link to post
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
Sign in to follow this  

×