Digging into the internals of Tcl's clock

Purpose: to attempt to decypher how Tcl 8.5's clock command works, internally, so as to get information not available via the public interfaces.

Initial problem - I need to be able to determine, for a specific date, time and timezone, whether it is:

  • within DST (aka Daylight Savings Time)
  • outside DST
  • in the nether area of the transition between the two.

The first two are obvious if you understand what DST is. The third point, however, works like this.

Assume that someone wants to know whether US Eastern Standard Timezoe, March 11, 2007, 2:01 AM is in DST or not.

Here's the rub - the second after 01:59:59 am, DST kicks in in US Eastern timezone and the next second becomes 03:00:00 am. So, technically, the time being requested doesn't exist.

Even worse, of course, is Eastern timezone (Ohio), 01:59:59 AM, Nov. 3, 2007. Why? Because there are TWO of those - one that IS in DST and one that is not!

Information regarding DST is inside ::tcl::clock - but there is no obvious public interface to access it.

Initially, I thought about making use of

 clock format $time -format {%Z} -timezone $tz

but, alas, the values returned by %Z are not guaranteed to be distinctive (Melbourne Australia, for instance, returns EST for both daylight savings and non-daylight savings times).

So, how can we make use of the internal variables and functions of clock to deduce whether a particular timezone/date/time combination is of 3 (or perhaps 5) states?