[PATCH 2/2] ui-atom: avoid DATE_STRFTIME

John Keeping john at keeping.me.uk
Mon Feb 8 16:06:27 CET 2016


Git's DATE_STRFTIME ignores the timezone argument and just uses the
local timezone regardless of whether the "local" flag is set.

Since Atom accepts ISO8601 dates [1], we can use Git's
DATE_ISO8601_STRICT instead, which does get this right.  Additionally,
we never use the local timezone here so we can use the
date_mode_from_type() wrapper to simplify the code a bit.

[1] https://tools.ietf.org/html/rfc4287#section-3.3

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h    |  5 -----
 ui-atom.c | 11 ++++-------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/cgit.h b/cgit.h
index 5adef4d..d10c799 100644
--- a/cgit.h
+++ b/cgit.h
@@ -29,11 +29,6 @@
 #undef isgraph
 #define isgraph(x) (isprint((x)) && !isspace((x)))
 
-/*
- * Dateformats used on misc. pages
- */
-#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
-
 
 /*
  * Limits used for relative dates
diff --git a/ui-atom.c b/ui-atom.c
index 0bf2cf2..41838d3 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -17,11 +17,6 @@ static void add_entry(struct commit *commit, const char *host)
 	char *hex;
 	char *mail, *t, *t2;
 	struct commitinfo *info;
-	struct date_mode mode = {
-		.type = DATE_STRFTIME,
-		.strftime_fmt = FMT_ATOMDATE,
-		.local = 0,
-	};
 
 	info = cgit_parse_commit(commit);
 	hex = oid_to_hex(&commit->object.oid);
@@ -30,7 +25,8 @@ static void add_entry(struct commit *commit, const char *host)
 	html_txt(info->subject);
 	html("</title>\n");
 	html("<updated>");
-	html_txt(show_date(info->committer_date, 0, &mode));
+	html_txt(show_date(info->committer_date, 0,
+                    date_mode_from_type(DATE_ISO8601_STRICT)));
 	html("</updated>\n");
 	html("<author>\n");
 	if (info->author) {
@@ -55,7 +51,8 @@ static void add_entry(struct commit *commit, const char *host)
 	}
 	html("</author>\n");
 	html("<published>");
-	html_txt(show_date(info->author_date, 0, &mode));
+	html_txt(show_date(info->author_date, 0,
+                    date_mode_from_type(DATE_ISO8601_STRICT)));
 	html("</published>\n");
 	if (host) {
 		char *pageurl;
-- 
2.7.0.389.ga73dcac



More information about the CGit mailing list