git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] blame and annotate: show localtime with timezone.

From
Junio C Hamano <junkio@cox.net>
Date
Mar 5, 2006, 22:48 UTC
Message-ID
<7vbqwkecf2.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<20060305123800.GD23448@c165.ib.student.liu.se>

Earlier they showed gmtime and timezone, which was inconsistent with the way our commits and tags are pretty-printed.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 blame.c           |   15 ++++++++++++---
 git-annotate.perl |    8 +++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)
e29f298a17ee898fd0d191d448ba4fc202175896
diff --git a/blame.c b/blame.c
index 59146fa..a3a8ddc 100644
--- a/blame.c
+++ b/blame.c
@@ -550,13 +550,22 @@ static void get_commit_info(struct commi
 	*tmp = 0;
 }
 
-char* format_time(unsigned long time, const char* tz)
+static const char* format_time(unsigned long time, const char* tz_str)
 {
 	static char time_buf[128];
 	time_t t = time;
+	int minutes, tz;
+	struct tm *tm;
 
-	strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S ", gmtime(&t));
-	strcat(time_buf, tz);
+	tz = atoi(tz_str);
+	minutes = tz < 0 ? -tz : tz;
+	minutes = (minutes / 100)*60 + (minutes % 100);
+	minutes = tz < 0 ? -minutes : minutes;
+	t = time + minutes * 60;
+	tm = gmtime(&t);
+
+	strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S ", tm);
+	strcat(time_buf, tz_str);
 	return time_buf;
 }
 
diff --git a/git-annotate.perl b/git-annotate.perl
index d93ee19..b113def 100755
--- a/git-annotate.perl
+++ b/git-annotate.perl
@@ -418,7 +418,13 @@ sub format_date {
 		return $_[0];
 	}
 	my ($timestamp, $timezone) = split(' ', $_[0]);
-	return strftime("%Y-%m-%d %H:%M:%S " . $timezone, gmtime($timestamp));
+	my $minutes = abs($timezone);
+	$minutes = int($minutes / 100) * 60 + ($minutes % 100);
+	if ($timezone < 0) {
+	    $minutes = -$minutes;
+	}
+	my $t = $timestamp + $minutes * 60;
+	return strftime("%Y-%m-%d %H:%M:%S " . $timezone, gmtime($t));
 }
 
 # Copied from git-send-email.perl - We need a Git.pm module..
-- 
1.2.4.gee5c7
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 9 of 10 in “git-blame: Make the output human readable”
  1. git-blame: Make the output human readableFredrik Kuivinen, Mar 5, 2006
  2. Junio C HamanoMar 5, 2006
  3. Fredrik KuivinenMar 5, 2006
  4. Johannes SchindelinMar 5, 2006
  5. Junio C HamanoMar 5, 2006
  6. Fredrik KuivinenMar 7, 2006
  7. blame: avoid -lm by not using log().Junio C Hamano, Mar 5, 2006
  8. Johannes SchindelinMar 5, 2006
  9. blame and annotate: show localtime with timezone.Junio C Hamano, Mar 5, 2006
  10. Johannes SchindelinMar 5, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.