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 <andersk@mit.edu> Signed-off-by: Paul Mackerras <paulus@samba.org>
Anders Kaseorg committed
May 12, 2014 at 07:25 UTC
019e1630ac16f82fa6322869c8dfc3dee029e7ae
1 file changed
+23
-1
gitk
+23
-1
@@ -11580,7 +11580,29 @@ proc prefsok {} {
11580
proc formatdate {d} {
11581
global datetimeformat
11582
if {$d ne {}} {
11583
- set d [clock format [lindex $d 0] -format $datetimeformat]
11583
+ # If $datetimeformat includes a timezone, display in the
11584
+ # timezone of the argument. Otherwise, display in local time.
11585
+ if {[string match {*%[zZ]*} $datetimeformat]} {
11586
+ if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11587
+ # Tcl < 8.5 does not support -timezone. Emulate it by
11588
+ # setting TZ (e.g. TZ=<-0430>+04:30).
11589
+ global env
11590
+ if {[info exists env(TZ)]} {
11591
+ set savedTZ $env(TZ)
11592
+ }
11593
+ set zone [lindex $d 1]
11594
+ set sign [string map {+ - - +} [string index $zone 0]]
11595
+ set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11596
+ set d [clock format [lindex $d 0] -format $datetimeformat]
11597
+ if {[info exists savedTZ]} {
11598
+ set env(TZ) $savedTZ
11599
+ } else {
11600
+ unset env(TZ)
11601
+ }
11602
+ }
11603
+ } else {
11604
+ set d [clock format [lindex $d 0] -format $datetimeformat]
11605
+ }
11606
}
11607
return $d
11608
}