Worldtime-clock

Introduction

HJG 2012-02-02 This is a small and simple program to show the time at some selected places around the world.
With some tweaks to the tcl-console.

Program 1

 # Worldtime-clock - https://wiki.tcl-lang.org/14375
 # HaJo Gurt - 2012-02-02 / 2015-05-05

  catch {console show}
  catch {wm withdraw .}
 #console eval {wm geometry . 56x25}
 # Resize console & position it at top-right corner on screen, for 1024x768:
  console eval {wm geometry . 56x25+550+0}
  console eval {.console config -bg grey -fg blue}

  proc q {} {exit}

  proc w {} {
    set loc_1 { 
       :Pacific/Honolulu  :America/Los_Angeles  :America/Chicago  :America/New_York
       :UTC               :Europe/Berlin        :Africa/Cairo     :Europe/Moscow
       :Asia/Tokyo        :Australia/Canberra }  

    puts "Time around the world:"
    foreach tz $loc_1  {
         set td [clock format [clock seconds] \
            -format "%H:%M:%S  %Y-%m-%d  %a  %z" -timezone $tz]
         puts [format "%-22s %s" $tz $td]
    }
  }

  console title "Worldtime - w to refresh, q to quit"
  w
 #.

Result

Time around the world:
:Pacific/Honolulu      10:25:00  2012-02-13  Mon  -1000
:America/Los_Angeles   12:25:00  2012-02-13  Mon  -0800
:America/Chicago       14:25:00  2012-02-13  Mon  -0600
:America/New_York      15:25:00  2012-02-13  Mon  -0500
:UTC                   20:25:00  2012-02-13  Mon  +0000
:Europe/Berlin         21:25:00  2012-02-13  Mon  +0100
:Africa/Cairo          22:25:00  2012-02-13  Mon  +0200
:Europe/Moscow         23:25:00  2012-02-13  Mon  +0300
:Asia/Tokyo            05:25:00  2012-02-14  Tue  +0900
:Australia/Canberra    07:25:00  2012-02-14  Tue  +1100

BTW, there is a worldtimeclock buried in the tk-demos that come with ActiveTcl,
look for "Paned Windows and Notebooks / Themed nested panes".

Program 2

HJG 2013-09-13 - Here is an extended version Worldtime-clock2 that offers a "running" clock.
It also does a "flash" every 10 seconds.
You can change that to 60, to get a flash at every full minute.

 # Worldtime-clock2 - https://wiki.tcl-lang.org/14375
 # HaJo Gurt 
 # 2012-02-02: worldclock1
 # 2013-09-13: c1,c2, t1,t2, every, r,s : colors, titles, run/stop

  catch {console show}
  catch {wm withdraw .}
 #console eval {wm geometry . 56x25}
 # Resize console & position it at top-right corner on screen, for 1024x768:
  console eval {wm geometry . 56x25+550+0} 

  proc q {} {exit}

  proc every {ms body} {
    if 1 $body
    after $ms [list after idle [namespace code [info level 0]]]
  }

  proc c1 {} { 
    console eval {.console config -bg grey -fg blue}
  }
  proc c2 {} { 
    console eval {.console config -bg grey -fg red}
  }
  proc t1 {} { 
    console title "Worldtime2 - w to refresh, q to quit / r: run, s: stop"
    puts "Worldtime2 - w to refresh, q to quit / r: run, s: stop\n"
  }
  proc t2 {} { 
    console title "Worldtime2 - s to stop, q to quit"
  }
  proc r {} {t2; every 1000 {w}}
  proc s {} {foreach id [after info] {after cancel $id}; t1 }


  proc w {} {
    puts "Time around the world:"
    foreach tz {
       :Pacific/Honolulu
       :America/Los_Angeles        
       :America/Chicago
       :America/New_York
       :UTC
       :Europe/Berlin
       :Africa/Cairo
       :Europe/Moscow
       :Asia/Tokyo
       :Australia/Canberra }  {
         set ::cs [clock seconds]
         if {[expr { $::cs % 10}] == 0} {c2} else {c1}    ;# Flash: 10: every 10s / 60: every full minute
         set ::td [clock format $::cs \
            -format "%H:%M:%S  %Y-%m-%d  %a  %z" -timezone $tz] 

         puts [format "%-22s %s" $tz $::td] 
    }
  }

  c1; t1; w

 #.

I made cs and td global (as in ::cs) for debugging & experimenting only,
to make access to them from the commandline more easy (e.g. enter puts "$cs $td" ).


See also: Wallclock - clock format - timezone - Windows wish console - after - every