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

[PATCH 2/2] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm

From
Marcus Comstedt <marcus@mc.pp.se>
Date
May 17, 2010, 19:07 UTC
Message-ID
<1274123231-18482-3-git-send-email-marcus@mc.pp.se>
In-Reply-To
<1274123231-18482-1-git-send-email-marcus@mc.pp.se>

ISO 8601 specifies three syntaxes for timezones other than "Z". git already supports the +-hhmm syntax. This patch adds support for the other two: +-hh:mm and +-hh.

Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
---
:100644 100644 6bae49c... f83e46e... M	date.c
 date.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/date.c b/date.c
index 6bae49c..f83e46e 100644
--- a/date.c
+++ b/date.c
@@ -555,6 +555,18 @@ static int match_tz(const char *date, int *offp)
 	int min, hour;
 	int n = end - date - 1;
 
+	/* Check for HH:MM format, allowed by ISO 8601 */
+	if (n == 2 && date[3] == ':') {
+		char *end2;
+		min = strtoul(date+4, &end2, 10);
+		/* If we have two digits after the colon too, assume HH:MM */
+		if (end2 == date+6) {
+			offset = offset*100 + min;
+			end = end2;
+			n = end - date - 1;
+		}
+	}
+
 	min = offset % 100;
 	hour = offset / 100;
 
@@ -570,6 +582,17 @@ static int match_tz(const char *date, int *offp)
 
 		*offp = offset;
 	}
+	/*
+	 * Also accept just the hour, allowed by ISO 8601
+	 */
+	else if (n == 2 && hour == 0 && min < 24) {
+		offset = min*60;
+		if (*date == '-')
+			offset = -offset;
+
+		*offp = offset;
+	}
+
 	return end - date;
 }
 
-- 
1.7.0.4
Previous: Jay SoffianNext: Junio C Hamano
Message 4 of 6 in “PATCH: Improved support for ISO 8601 timezones”
  1. Marcus ComstedtMay 17, 2010
  2. 1/2 Added "Z" as an alias for the timezone "UTC"Marcus Comstedt, May 17, 2010
  3. Jay SoffianMay 17, 2010
  4. 2/2 Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmmMarcus Comstedt, May 17, 2010
  5. Junio C HamanoMay 19, 2010
  6. Marcus ComstedtMay 19, 2010

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.