Version 4 of Clock and daylight saving time corrections

Updated 2007-01-19 11:41:17 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?


Category Date and Time - Category Example