[PATCH] git-gui: Localize commit/author dates when displaying them

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---

 This is uh, less than ideal because we are parsing the pretty
 dates from git-for-each-ref just so we can repretty them up in Tcl.
 *sigh*

 It fixes the inconsistent date formatting in the branch create
 dialog that was mentioned on #git tonight.  Err this morning.
 Whatever.  I hate time.

 Parked in my pu branch for now but will probably move to master
 if nobody has any better suggestions.

 lib/blame.tcl      |   20 +++---------------
 lib/choose_rev.tcl |    6 ++--
 lib/date.tcl       |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 19 deletions(-)
 create mode 100644 lib/date.tcl

diff --git a/lib/blame.tcl b/lib/blame.tcl
index b5fdad5..352aa19 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 8c78b4d..a6a442a 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 0000000..abe8299
--- /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]]
+}
-- 
1.5.3.1.896.ge3cd6
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux