Version 7 of clock's valid year : a catch example

Updated 2010-01-28 11:17:51 by LGT
 proc isValidYear { year } {
     set valid 1
     if [catch {clock scan "1/1/$year" }] {
         set valid 0
     } 
     return $valid
 }

 proc limitvalidyear { year direction} {
     set stillvalid [isValidYear $year]
     if {! $stillvalid} {
         return -1
     }  
     while {$stillvalid} {
         if {[isValidYear $year]} {
             incr year $direction
         } else {
             set stillvalid 0
         } 
     }
     return $year
 }

 proc systeminfo {} {
     global tcl_platform 
     global tcl_patchLevel
     puts "(machine:$tcl_platform(machine), platform:$tcl_platform(platform), os version:$tcl_platform(osVersion), tcl version:$tcl_patchLevel)"
 }

 systeminfo 
 puts [limitvalidyear 2010 1]
 puts [limitvalidyear 2010 -1]

 (machine:intel, platform:windows, os version:5.1, tcl version:8.4.19)
 minimum year is 2038
 maximum year is 1901

 (machine:intel, platform:windows, os version:5.1, tcl version:8.5.2)
 minimum year is 100000
 maximum year is -1