A script to check the limit of clock scan procedure. It's also an example of catch command.
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 "maximum year is [limitvalidyear 2010 1]" puts "minimum year is [limitvalidyear 2010 -1]"
(machine:intel, platform:windows, os version:5.1, tcl version:8.4.19) maximum year is 2038 minimum year is 1901
(machine:intel, platform:windows, os version:5.1, tcl version:8.5.2) maximum year is 100000 minimum year is -1
(machine:i386, platform:unix, os version:9.8.0, tcl version:8.4.7) maximum year is 2038 minimum year is 1901
(machine:i386, platform:unix, os version:9.8.0, tcl version:8.5.5) maximum year is 100000 minimum year is -1