From: Shawn O. Pearce Date: Mon, 10 Sep 2007 05:54:16 +0000 (-0400) Subject: git-gui: Localize commit/author dates when displaying them X-Git-Tag: gitgui-0.9.0~78 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=66c75a5c9f7434d857d836440dc1c3046c59b5f3;p=git.git git-gui: Localize commit/author dates when displaying them Currently the Git plumbing is not localized so it does not know how to output weekday and month names that conform to the user's locale preferences. This doesn't fit with the rest of git-gui's UI as some of our dates are formatted in Tcl and some are just read from the Git plumbing so dates aren't consistently presented. Since git-for-each-ref is presenting us formatted dates and it offers no way to change that setting even in git 1.5.3.1 we need to first do a parse of the text strings it produces, correct for timezones, then reformat the timestamp using Tcl's formatting routines. Not exactly what I wanted to do but it gets us consistently presented date strings in areas like the blame viewer and the revision picker mega-widget's tooltips. Signed-off-by: Shawn O. Pearce --- diff --git a/lib/blame.tcl b/lib/blame.tcl index b5fdad564..352aa1942 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -743,20 +743,14 @@ method _showcommit {cur_w lno} { set author_time {} catch {set author_name $header($cmit,author)} catch {set author_email $header($cmit,author-mail)} - catch {set author_time [clock format \ - $header($cmit,author-time) \ - -format {%Y-%m-%d %H:%M:%S} - ]} + catch {set author_time [format_date $header($cmit,author-time)]} set committer_name {} set committer_email {} set committer_time {} catch {set committer_name $header($cmit,committer)} catch {set committer_email $header($cmit,committer-mail)} - catch {set committer_time [clock format \ - $header($cmit,committer-time) \ - -format {%Y-%m-%d %H:%M:%S} - ]} + catch {set committer_time [format_date $header($cmit,committer-time)]} if {[catch {set msg $header($cmit,message)}]} { set msg {} @@ -892,10 +886,7 @@ method _open_tooltip {cur_w} { set author_time {} catch {set author_name $header($cmit,author)} catch {set summary $header($cmit,summary)} - catch {set author_time [clock format \ - $header($cmit,author-time) \ - -format {%Y-%m-%d %H:%M:%S} - ]} + catch {set author_time [format_date $header($cmit,author-time)]} $tooltip_t insert end "commit $cmit\n" $tooltip_t insert end "$author_name $author_time\n" @@ -914,10 +905,7 @@ method _open_tooltip {cur_w} { set author_time {} catch {set author_name $header($cmit,author)} catch {set summary $header($cmit,summary)} - catch {set author_time [clock format \ - $header($cmit,author-time) \ - -format {%Y-%m-%d %H:%M:%S} - ]} + catch {set author_time [foramt_date $header($cmit,author-time)]} $tooltip_t insert end "Originally By:\n" section_header $tooltip_t insert end "commit $cmit\n" diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index 8c78b4dd7..a6a442ae1 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -133,13 +133,13 @@ constructor _new {path unmerged_only title} { append fmt { %(objecttype)} append fmt { %(objectname)} append fmt { [concat %(taggername) %(authorname)]} - append fmt { [concat %(taggerdate) %(authordate)]} + append fmt { [reformat_date [concat %(taggerdate) %(authordate)]]} append fmt { %(subject)} append fmt {] [list} append fmt { %(*objecttype)} append fmt { %(*objectname)} append fmt { %(*authorname)} - append fmt { %(*authordate)} + append fmt { [reformat_date %(*authordate)]} append fmt { %(*subject)} append fmt {]} set all_refn [list] @@ -583,7 +583,7 @@ method _reflog_last {name} { } if {$last ne {}} { - set last [clock format $last -format {%a %b %e %H:%M:%S %Y}] + set last [format_date $last] } set reflog_last($name) $last return $last diff --git a/lib/date.tcl b/lib/date.tcl new file mode 100644 index 000000000..abe82992b --- /dev/null +++ b/lib/date.tcl @@ -0,0 +1,53 @@ +# git-gui date processing support +# Copyright (C) 2007 Shawn Pearce + +set git_month(Jan) 1 +set git_month(Feb) 2 +set git_month(Mar) 3 +set git_month(Apr) 4 +set git_month(May) 5 +set git_month(Jun) 6 +set git_month(Jul) 7 +set git_month(Aug) 8 +set git_month(Sep) 9 +set git_month(Oct) 10 +set git_month(Nov) 11 +set git_month(Dec) 12 + +proc parse_git_date {s} { + if {$s eq {}} { + return {} + } + + if {![regexp \ + {^... (...) (\d{1,2}) (\d\d):(\d\d):(\d\d) (\d{4}) ([+-]?)(\d\d)(\d\d)$} $s s \ + month day hr mm ss yr ew tz_h tz_m]} { + error [mc "Invalid date from Git: %s" $s] + } + + set s [clock scan [format {%4.4i%2.2i%2.2iT%2s%2s%2s} \ + $yr $::git_month($month) $day \ + $hr $mm $ss] \ + -gmt 1] + + regsub ^0 $tz_h {} tz_h + regsub ^0 $tz_m {} tz_m + switch -- $ew { + - {set ew +} + + {set ew -} + {} {set ew -} + } + + return [expr "$s $ew ($tz_h * 3600 + $tz_m * 60)"] +} + +proc format_date {s} { + if {$s eq {}} { + return {} + } + return [clock format $s -format {%a %b %e %H:%M:%S %Y}] +} + +proc reformat_date {s} { + return [format_date [parse_git_date $s]] +}