From: Anders Kaseorg Date: Mon, 12 May 2014 11:25:58 +0000 (-0400) Subject: gitk: Allow displaying time zones from author and commit dates timestamps X-Git-Tag: v2.1.0-rc0~74^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=019e1630ac16f82fa6322869c8dfc3dee029e7ae;p=git gitk: Allow displaying time zones from author and commit dates timestamps Now gitk can be configured to display author and commit dates in their original timezone, by putting %z into datetimeformat in ~/.gitk. Signed-off-by: Anders Kaseorg Signed-off-by: Paul Mackerras --- diff --git a/gitk b/gitk index a4a8bd30ae..a40de31ce0 100755 --- a/gitk +++ b/gitk @@ -11580,7 +11580,29 @@ proc prefsok {} { proc formatdate {d} { global datetimeformat if {$d ne {}} { - set d [clock format [lindex $d 0] -format $datetimeformat] + # If $datetimeformat includes a timezone, display in the + # timezone of the argument. Otherwise, display in local time. + if {[string match {*%[zZ]*} $datetimeformat]} { + if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} { + # Tcl < 8.5 does not support -timezone. Emulate it by + # setting TZ (e.g. TZ=<-0430>+04:30). + global env + if {[info exists env(TZ)]} { + set savedTZ $env(TZ) + } + set zone [lindex $d 1] + set sign [string map {+ - - +} [string index $zone 0]] + set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4] + set d [clock format [lindex $d 0] -format $datetimeformat] + if {[info exists savedTZ]} { + set env(TZ) $savedTZ + } else { + unset env(TZ) + } + } + } else { + set d [clock format [lindex $d 0] -format $datetimeformat] + } } return $d }