[erlang-questions] Time zone

Bruce Fitzsimons Bruce@REDACTED
Tue Dec 12 08:44:18 CET 2006


Chandru wrote:
> Hi,
>
> Is there a way to get the time zone configured on a machine without
> resorting to hacks.
>
> It'll be nice to have something like:
>
> calendar:time_zone().
> OR
> erlang:system_info(time_zone).
>
>   
I'm not sure what you would expect as a response? TZ strings are complex
beasties and there are at least 4 forms -- e.g. GMT, GMT-12/x/x/x...,
:file and Europe/Paris. man tzset or man timezone.

You may be asking about finding out your offset from GMT or UTC, but
that is quite a different question. The reason this isn't done once in
yaws is because of daylight savings...the offset changes under your feet
and you're not allowed to know when.

> Example from yaws_log.erl below.
>   
/me attempts to expunge guilt from soul by saying that someone else did
it first :-(

That is one of the least efficient parts of yaws, and it is my fault.

The best way of doing timezones properly is to parse the Olsen timezone
files and create useful functions that actually let human beings
translate one time to another in the same format. The Olsen files are
the master files used by a number of OSs, and I suspect the others just
use a processed version of them. The Olsen C code used to parse it is
worthy of an obfusticated C competition, and I think worthy of an ICFP
one year -- the results would be usable beyond the end of the contest...

The files are tough to parse (it is certainly not CSV, XML, or even
ASN.1 PER :) ) and I think shows the heritage of squeezing as much out
of every byte as possible. To be fair though the lines have a lot of
information encoded into them, and can actually describe a TZ properly
for any moment in time (multiple lines, at least). If anyone would like
to hack some code to parse the Olsen TZ files and build a datastructure
to hold them then they'll deserve their place in the sun. I'll even post
them a chocolate fish from NZ.

More ranting about this by me here:
http://bwooce.livejournal.com/1885.html and
http://bwooce.livejournal.com/2124.html

Regards,
Bruce



More information about the erlang-questions mailing list