How do you generate POSIX time zone strings?
Paul Eggert
eggert at twinsun.com
Thu Mar 20 02:28:41 UTC 1997
Date: Wed, 19 Mar 1997 13:19:11 -0800 (PST)
From: Tony Glenning <tony at hape.Eng.Sun.COM>
For example, if this function were run on machine which has TZ set
to US/Pacific in 1997 it would generate:
PST8PDT7,97/3:00:00,300/1:00:00 [*]
First, perhaps you could explain a little why you want to do this,
since you lose information when you generate Posix strings from
Olson-style strings.
Second, assuming you want to do this sort of thing, why would you want
to generate [*]? It's better to generate the following instead:
PST8PDT7,M4.1.0/2:00:00,M10.5.0/2:00:00 [**]
since [**] will work in years other than the current year. [**] isn't
as good as US/Pacific, but it's better than [*].
Here's how to generate [**] without parsing the zoneinfo files. Run
GNU Emacs, load-library cal-dst, and invoke (calendar-current-time-zone).
If TZ is US/Pacific, it should return
(-480 60 "PST" "PDT"
(calendar-nth-named-day 1 0 4 year)
(calendar-nth-named-day -1 0 10 year)
120 120)
and it's easy to generate [**] from this value.
If you can't use GNU Emacs in your application, look at cal-dst's
source code for ideas about how to do it. GNU Emacs doesn't parse the
zoneinfo files; it just uses ANSI C localtime and gmtime like a good
citizen.
More information about the tz
mailing list