Tcl Source Code

Artifact [fea6be0ca5]
Login

Artifact fea6be0ca5e361d32921479c0e4d42be8f789192:

Attachment "clock.tcl" to ticket [413397ffff] added by hemanglavana 2001-04-03 19:38:06.
## clock.tcl

proc clkprint {basesec when {mark ""}} {
    set gmtoff [clock format [clock scan $when -base $basesec -gmt 0] \
               -format "%a %b %d %H:%M:%S %Y"]
    set gmton  [clock format [clock scan $when -base $basesec -gmt 1] \
               -format "%a %b %d %H:%M:%S %Y"]
    puts "[format %9s $when] | $gmtoff | $gmton  $mark"
} ;# End of clkprint

# The problem occurs when sec is specified to be before 7:00am 
# in US/Pacific timezone.
# Therefore, force the time zone to be US/Pacific to ensure that
# the problem can be replicated no matter where it is invoked.
# This works only on unix (solaris) boxes, on windows you may
# have to actually change the system's time zone.
if {![string compare $tcl_platform(platform) "unix"]} {
    set env(TZ) "US/Pacific"
} ;# End of if stmt

# On windows, we need to display the stdout in a console
catch {console show}

# Print tcl version
puts "\nTcl_version=[info patch]"

#985183078 now=05:57:58 03/21/2001 PST
set basesec 985183078
puts "base_seconds=$basesec, current_time=[clock format $basesec]"

puts "----------+--------------------------+-------------------------------"
puts "Relative  |         Local Time       |          GMT Time"
puts "----------+--------------------------+-------------------------------"
clkprint $basesec  "today"
clkprint $basesec  "tomorrow"
clkprint $basesec  "week"
clkprint $basesec  "4 weeks"
clkprint $basesec  "month"     *
clkprint $basesec  "5 weeks"
clkprint $basesec  "6 months"  *
clkprint $basesec  "26 weeks"
clkprint $basesec  "12 months" *
clkprint $basesec  "52 weeks"
clkprint $basesec  "365 days"
clkprint $basesec  "year"      *
puts "----------+--------------------------+-------------------------------"
puts "*  Dates for local time and gmt time are skewed by one day"