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

[PATCH] date.c: Parse timezone with colon as separator

From
Haitao Li <lihaitao@gmail.com>
Date
Sep 6, 2011, 14:56 UTC
Message-ID
<1315320996-1997-1-git-send-email-lihaitao@gmail.com>
Timezone designators including additional separator (`:`) are ignored.
Actually zone designators in below formats are all valid according to
ISO8601:2004, section 4.3.2:
    [+-]hh, [+-]hhmm, [+-]hh:mm
Steps to reproduce the issue this patch fixes:
    $ mkdir /tmp/test
    $ cd /tmp/test
    $ git init
    $ echo 'timezone' > file.txt
    $ git add .
    $ git update-index
    $ git write-tree
    3e168d57e1c32a4598af134430384f0587581503
    # Commit the tree returned above. Give a date with colon separated
    # timezone
    $ echo "Test commit" | \
      TZ=UTC GIT_AUTHOR_DATE='2011-09-03T12:34:56+08:00' \
      git commit-tree 3e168d57e1c32a4598af134430384f0587581503 | \
      xargs git show  | grep Date
    Date:   Sat Sep 3 12:34:56 2011 +0000
while the expected result is:
    Date:   Sat Sep 3 12:34:56 2011 +0800
                                      ^---

This patch teaches git recognizing zone designators with hours and minutes separated by colon, or minutes are empty.

Signed-off-by: Haitao Li <lihaitao@gmail.com>
---
 date.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/date.c b/date.c
index 896fbb4..8a94944 100644
--- a/date.c
+++ b/date.c
@@ -556,15 +556,21 @@ static int match_tz(const char *date, int *offp)
 	int min, hour;
 	int n = end - date - 1;
 
-	min = offset % 100;
-	hour = offset / 100;
+	if (n == 2 && *end == ':') {
+		hour = offset;
+		offset = strtoul(date+4, &end, 10);
+		min = offset % 100;
+	} else {
+		hour = offset / 100;
+		min = offset % 100;
+	}
 
 	/*
-	 * Don't accept any random crap.. At least 3 digits, and
+	 * Don't accept any random crap.. At least 2 digits, and
 	 * a valid minute. We might want to check that the minutes
 	 * are divisible by 30 or something too.
 	 */
-	if (min < 60 && n > 2) {
+	if (min < 60 && n > 1) {
 		offset = hour*60+min;
 		if (*date == '-')
 			offset = -offset;
-- 
1.7.5.4
Next: Jeff King
Message 1 of 12 in “date.c: Parse timezone with colon as separator”
  1. date.c: Parse timezone with colon as separatorHaitao Li, Sep 6, 2011
  2. Jeff KingSep 6, 2011
  3. Haitao LiSep 7, 2011
  4. date.c: Support iso8601 timezone formatsHaitao Li, Sep 7, 2011
  5. Junio C HamanoSep 7, 2011
  6. Haitao LiSep 8, 2011
  7. date.c: Support iso8601 timezone formatsHaitao Li, Sep 9, 2011
  8. Junio C HamanoSep 9, 2011
  9. Junio C HamanoSep 9, 2011
  10. Junio C HamanoSep 9, 2011
  11. Haitao LiSep 10, 2011
  12. Haitao LiSep 10, 2011

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.