FW: accessing DST rules at runtime

Paul Eggert eggert at twinsun.com
Tue Apr 20 06:22:24 UTC 1999


   From:	Dave Hackenyos [SMTP:hackenyo at roguewave.com]
   Sent:	Friday, April 16, 1999 8:12 PM

       I am attempting to discover a way to query any (most) Operating
   Systems about what it may think the daylight rule is for the Timezone in
   which it thinks it is located.

The problem can't be solved in general, since governments change the
rules periodically, and systems using the Olson implementation can
record these changes.  For example, the system might currently be
configured to use American-style daylight-saving rules for timestamps
before July 1, and European-style rules for timestamps thereafter.
This sort of thing really does happen.

If you want accuracy, the best method I know of is that of zdump.c in
the tzcode distribution.  zdump just probes ahead, one day at a time,
until it discovers a UTC offset change; it then reports this change to
the user.  It makes no attempt to guess what the ``rules'' are, since
there may not be any.  For example, see Israel, where the government
seems to decide the transition times each year separately and arbitrarily.

If you really want a single set of rules, and are willing to give up
some accuracy, then the best code that I know of is the code that
Edward M. Reingold and I contributed to the GNU Emacs distribution;
see the calendar-time-zone-daylight-rules function of
lisp/calendar/cal-dst.el, which intuits the daylight saving rules from
zdump-like probes into the future.  I should warn you that it's pretty
hairy going; among other things, the code works even in Iran, which
determines DST transitions using a method based on the (non-Gregorian)
calendar of Omar Khayyam.



More information about the tz mailing list