]> Pileus Git - ~andy/git/commitdiff
git-gui: Localize commit/author dates when displaying them
authorShawn O. Pearce <spearce@spearce.org>
Mon, 10 Sep 2007 05:54:16 +0000 (01:54 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 10 Sep 2007 05:54:16 +0000 (01:54 -0400)
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 <spearce@spearce.org>
lib/blame.tcl
lib/choose_rev.tcl
lib/date.tcl [new file with mode: 0644]

index b5fdad5643e46b09a23ea880f57bbd66af6e6923..352aa19421034033968f6a311b1e8948ac01e25f 100644 (file)
@@ -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"
index 8c78b4dd7beac5d244d0eba058ea19bcc0782c3d..a6a442ae1dcbad90b1509121e25fd9f02739f71a 100644 (file)
@@ -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 (file)
index 0000000..abe8299
--- /dev/null
@@ -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]]
+}