Version 6 of Clock and daylight saving time corrections

Updated 2007-01-19 18:47:15 by LV

Arjen Markus (24 august 2005) The [clock] command is a wonderful instrument, despite all its quirks, if you need to do date/time computations. I ran into one quirk the other day that is not the fault of the implementation, but rather of the complicated calendar we use in today's world: daylight saving time.

Let me explain my problem:

  • I had a starting date in october and I wanted to know the end date after N spring-neap cycles (in my approximation: 15 days and 6 hours).
  • I used the clock command to do the computation and got some date in january, 7 o'clock as the stop date/time.

Then I realised that I had crossed the date where the daylight saving time correction changes. By using the option -gmt 1 you can avoid these complications.

Here is an illustration of the effect:

 # Daylight saving problems
 #
 # No care for daylight saving time corrections ...
 #
 set day1 [clock scan "2005-10-01"]
 set day2 [clock scan "2005-11-01"]
 set number_days [expr {($day2-$day1)/86400.0}]
 puts "Number of days: $number_days"

 # Option: -gmt 1
 #
 set day1 [clock scan "2005-10-01" -gmt 1]
 set day2 [clock scan "2005-11-01" -gmt 1]
 set number_days [expr {($day2-$day1)/86400.0}]
 puts "Number of days: $number_days"

The result (Tcl 8.4):

 Number of days: 31.0416666667
 Number of days: 31.0

Of course, it depends on what you want to achieve, if you need this option or not. Date/time computations are simply very complicated.


LV A friend sent me this pointer [L1 ] which discusses the fact that a number of countries have been, and continue to, make changes in the way DST is calculated. Does anyone know whether Tcl is tracking these kinds of adjustments? MG As far as I know, all Tcl's time functions are platform-dependant, so as long as the underlying OS knows about them, Tcl will too. LV Certainly in Tcl 8.5, there is now a large amount of timezone information. I just don't know enough about those files to know whether Tcl software has to change, given that there seems to be discussion of things like java changes. Just was curious.


Category Date and Time - Category Example