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

Re: [PATCH] Support output ISO 8601 format dates

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Jul 15, 2007, 23:19 UTC
Message-ID
<200707160119.34509.robin.rosenberg@dewire.com>
In-Reply-To
<20070715212359.GB18293@efreet.light.src>
From 59eafc201aec3be121b33c2ecf16c70cc3521e92 Mon Sep 17 00:00:00 2001
From: Robin Rosenberg <robin.rosenberg@dewire.com>
Date: Mon, 16 Jul 2007 01:05:19 +0200
Subject: [PATCH] Support output ISO 8601 format dates

Support output of full ISO 8601 style dates in e.g. git log and other places that use interpolation for formatting.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 Documentation/pretty-formats.txt |    2 ++
 cache.h                          |    2 +-
 commit.c                         |    6 +++++-
 date.c                           |    9 +++++++++
 4 files changed, 17 insertions(+), 2 deletions(-)
söndag 15 juli 2007 skrev Jan Hudec:
Show 16 quoted lines
> Hello,
> 
> On Fri, Jul 13, 2007 at 22:22:58 +0200, Robin Rosenberg wrote:
> > +	else if (mode == DATE_ISO8601)
> > +		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
> > +				tm->tm_year + 1900,
> > +				tm->tm_mon + 1,
> > +				tm->tm_mday,
> > +				tm->tm_hour, tm->tm_min, tm->tm_sec,
> > +				tz);
> 
> I apologise for nitpicking, but ISO 8601 (and RFC 3339) says separator between
> date and time is 'T' and there is no separator between time and timezone. So
> this should be
> 
> +		sprintf(timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%+05d",

Note that my reference is to ISO 8601, not RFC 3339. Hower I interpret "NOTE By mutual agreement of the partners in information interchange, the character [T] may be omitted in applications where there is no risk of confusing a date and time of day representation with others defined in this International Standard" (ISO 8601:2004 4.3.2) as space being allowed here instead of 'T'.

By "mutual agreement" I mean that I tell you what it looks like and you agree :)
I agree with you about the space before timezone though. I'll go.
Show 15 quoted lines
> for 100% conformance to the standard. RFC 3339 explicitely mentions using
> space instead of 'T' as separator as allowed, but does not seem to mention
> space before time zone. There may be applications that would stop at such
> space and assume no timezone information.
> 
> Furthermore RFC 3339 seems to require colon in the timezone, so it would be:
> 
> +		sprintf(timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%+03d:%02d",
> +				tm->tm_year + 1900,
> +				tm->tm_mon + 1,
> +				tm->tm_mday,
> +				tm->tm_hour, tm->tm_min, tm->tm_sec,
> +				tz / 100, abs(tz % 100));
> 
> ISO 8601 makes separators optional, so simple 4-digit timezone is OK.

For the sake of consequence I should use the extended format for all parts and not mix basic and extended formats.

Updated patch follows that formats dates as "2006-08-17 20:59:46+05:30"
-- robin
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index d922e8e..1296b31 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -106,12 +106,14 @@ The placeholders are:
 - '%aD': author date, RFC2822 style
 - '%ar': author date, relative
 - '%at': author date, UNIX timestamp
+- '%ai': author date, ISO 8601 format
 - '%cn': committer name
 - '%ce': committer email
 - '%cd': committer date
 - '%cD': committer date, RFC2822 style
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
+- '%ci': committer date, ISO 8601 format
 - '%e': encoding
 - '%s': subject
 - '%b': body
diff --git a/cache.h b/cache.h
index 5dff2f1..3dc0def 100644
--- a/cache.h
+++ b/cache.h
@@ -389,7 +389,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,
 					unsigned long *size,
 					unsigned char *sha1_ret);
 
-enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL };
+enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL, DATE_ISO8601 };
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
 const char *show_rfc2822_date(unsigned long time, int timezone);
 int parse_date(const char *date, char *buf, int bufsize);
diff --git a/commit.c b/commit.c
index 5632e32..68df3b4 100644
--- a/commit.c
+++ b/commit.c
@@ -773,6 +773,7 @@ static void fill_person(struct interp *table, const char *msg, int len)
 	interp_set_entry(table, 2, show_date(date, tz, 0));
 	interp_set_entry(table, 3, show_rfc2822_date(date, tz));
 	interp_set_entry(table, 4, show_date(date, tz, 1));
+	interp_set_entry(table, 6, show_date(date, tz, DATE_ISO8601));
 }
 
 static long format_commit_message(const struct commit *commit,
@@ -791,12 +792,14 @@ static long format_commit_message(const struct commit *commit,
 		{ "%aD" },	/* author date, RFC2822 style */
 		{ "%ar" },	/* author date, relative */
 		{ "%at" },	/* author date, UNIX timestamp */
+		{ "%ai" },	/* author date, ISO 8601 */
 		{ "%cn" },	/* committer name */
 		{ "%ce" },	/* committer email */
 		{ "%cd" },	/* committer date */
 		{ "%cD" },	/* committer date, RFC2822 style */
 		{ "%cr" },	/* committer date, relative */
 		{ "%ct" },	/* committer date, UNIX timestamp */
+		{ "%ci" },	/* committer date, ISO 8601 */
 		{ "%e" },	/* encoding */
 		{ "%s" },	/* subject */
 		{ "%b" },	/* body */
@@ -813,10 +816,11 @@ static long format_commit_message(const struct commit *commit,
 		IPARENTS, IPARENTS_ABBREV,
 		IAUTHOR_NAME, IAUTHOR_EMAIL,
 		IAUTHOR_DATE, IAUTHOR_DATE_RFC2822, IAUTHOR_DATE_RELATIVE,
-		IAUTHOR_TIMESTAMP,
+		IAUTHOR_TIMESTAMP, IAUTHOR_ISO8601,
 		ICOMMITTER_NAME, ICOMMITTER_EMAIL,
 		ICOMMITTER_DATE, ICOMMITTER_DATE_RFC2822,
 		ICOMMITTER_DATE_RELATIVE, ICOMMITTER_TIMESTAMP,
+		ICOMMITTER_ISO8601,
 		IENCODING,
 		ISUBJECT,
 		IBODY,
diff --git a/date.c b/date.c
index 4690371..c96100e 100644
--- a/date.c
+++ b/date.c
@@ -137,7 +137,15 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 	if (mode == DATE_SHORT)
 		sprintf(timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
 				tm->tm_mon + 1, tm->tm_mday);
+	else if (mode == DATE_ISO8601)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d%+03d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min, tm->tm_sec,
+				tz/100,
+				abs(tz%100)
+				);
 	else
 		sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
 				weekday_names[tm->tm_wday],
-- 
1.5.2.3
Previous: Junio C HamanoNext: Linus Torvalds
Message 12 of 13 in “Support output ISO 8601 format dates”
  1. Support output ISO 8601 format datesRobin Rosenberg, Jul 13, 2007
  2. Junio C HamanoJul 13, 2007
  3. Support output ISO 8601 format datesRobin Rosenberg, Jul 13, 2007
  4. 1/2 Make show_rfc2822_date() just another date output format.Junio C Hamano, Jul 14, 2007
  5. 2/2 Wire new date formats to --date=<format> parser.Junio C Hamano, Jul 14, 2007
  6. Jan-Benedict GlawJul 14, 2007
  7. Junio C HamanoJul 14, 2007
  8. Robin RosenbergJul 14, 2007
  9. Document new --date=<format>Junio C Hamano, Jul 14, 2007
  10. Jan HudecJul 15, 2007
  11. Junio C HamanoJul 15, 2007
  12. Robin RosenbergJul 15, 2007
  13. Linus TorvaldsJul 15, 2007

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.