worldtime.tcl
Sometimes you need to know the time somewhere else in the world. I find it useful to get my eggdrop to return the time of another timezone…
> .tz london <Bot> HM2K, The time for the london timezone is Fri Feb 13 23:31:30 2009
However, much like my old weather.tcl, I realised that my worldtime.tcl had passed it’s sell by date and had now expired.
My old worldtime.tcl which was based on a script by Murf which used worldtimeserver.com to gather it’s data had stopped working.
It would seem that worldtimeserver.com had changed their markup which meant that it was no longer possible to parse the correct data from the HTML.
Never mind, I thought, there must be a better way, that doesn’t need to use a third party website, that won’t stop working.
After all operating systems have worldtime build in without using a website, so how do they do it?
So, I did some investigation…
I discovered that on Linux based systems (including FreeBSD) the time zone information was stored locally.
/usr/share/zoneinfo/
Using a bit of Google magic, I managed to locate a few pre-made procedures to help me read the time zone information.
- load-timezones.tcl
- get_tz_names
- get_tz_rules
Using these functions I was able to find the right timezone and get the GMT offset which allowed me to work out the time in that timezone using the unix ticks.
At the moment, because it reads the time zone files that are only available on Linux based systems, it will not work on windrops.
However, what I may do next time is build a function that saves the timezone information into a database file which can be used on windows systems and will also give the Linux systems a cache file to make it respond quicker.
Update: I decided to stop using the tz database method and replace it with a Google lookup method, which is far more accurate and portable.
So now you’ll probably want to download it…
Hope it works for you.
Enjoy!
Note: If you find this useful, or have an issue with the script, please add a comment below. Thanks.
Warning: Declaration of Social_Walker_Comment::start_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::start_lvl(&$output, $depth = 0, $args = Array) in /Users/wade/Sites/hm2k.org/wp-content/plugins/social/lib/social/walker/comment.php on line 18
Warning: Declaration of Social_Walker_Comment::end_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::end_lvl(&$output, $depth = 0, $args = Array) in /Users/wade/Sites/hm2k.org/wp-content/plugins/social/lib/social/walker/comment.php on line 42
This script was updated as per this thread:
http://forum.egghelp.org/viewtopic.php?p=91935#91935
i am able to user worldtime.tcl,
Error Messge:
[root@willet bkp_03-05-2010]# .tz worldtime.tcl
-bash: .tz: command not found
This is an eggdrop tcl script, not a shell script.
See: http://www.egghelp.org/enhance.htm#tclscripts
Hi, what is the htmlparse package?
I don’t get this very well.
@Exedore
I’ve since improved the script to make it more obvious what is required.
Get htmlparse via http://tcllib.sf.net
You can get the standard tcl library, including htmlparse, from
apt-get install tcllib