[erlang-questions] Timezone calculations

Ulf Wiger (TN/EAB) <>
Fri Sep 19 09:52:27 CEST 2008


Juan Jose Comellas skrev:
> I need to perform time calculations based on arbitrary
> (user-supplied) timezones and I haven't found anything in Erlang/OTP
> that lets me determine the offset (in minutes or seconds) that a
> timezone has against UTC. The calendar module only supports
> converting times from UTC into the local timezone and the other way
> around, but what if what I want is to convert a time to another
> timezone that is not my local one?
> 
> I'd prefer a portable solution, but even if there is an easy way to 
> access the Olson/zoneinfo tz database on Linux that would be
> acceptable.

Back in the good ol' days, when anybody who was anybody ran
their mission-critical systems on Solaris*, and Solaris required
an OS patch to deal with updated timezone rules (and DST is
governed by political decisions in some countries!), we once
decided to set the system clock of our embedded systems to UTC,
and handled local time in Erlang by modifying the TZ environment
variable - initially through a linked-in driver, but later with
os:putenv/2.

It's not a complete solution, nor in some respects an especially
good one, but back then, we considered it the lesser of known
evils.

Of course, it wouldn't solve your particular problem, unless
you'd be willing to consider starting a separate erlang node,
setting its TZ to the zone you're interested in, and then
calculate the diff between universal time and local time. (:

The amount of coding required would be small, but might not
be able to stand the side-effects and ugliness of it all...

BR,
Ulf W


* I'm joking, of course, but at least we did it.



More information about the erlang-questions mailing list