1 minute read

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> User, 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.

The 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.

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.

Comments