From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 1/2] Avoid DATE_STRFTIME for long/short dates
Date: Mon, 8 Feb 2016 15:05:54 +0000 [thread overview]
Message-ID: <20160208150554.GO29880@serenity.lan> (raw)
In-Reply-To: <CAHmME9ohPw3pR8XMVBCR9eZS-yFOVThTCKU=X+oMXvrVCr7Dag@mail.gmail.com>
Git's DATE_STRFTIME ignores the timezone argument and just uses the
local timezone regardless of whether the "local" flag is set.
Since our existing FMT_LONGDATE and FMT_SHORTDATE are pretty-much
perfect matches to DATE_ISO8601 and DATE_SHORT, switch to taking a
date_mode_type directly in cgit_date_mode().
Signed-off-by: John Keeping <john at keeping.me.uk>
---
cgit.h | 2 --
ui-commit.c | 4 ++--
ui-shared.c | 13 ++++++-------
ui-shared.h | 2 +-
ui-tag.c | 2 +-
5 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/cgit.h b/cgit.h
index 501cb48..5adef4d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -32,8 +32,6 @@
/*
* Dateformats used on misc. pages
*/
-#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
-#define FMT_SHORTDATE "%Y-%m-%d"
#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
diff --git a/ui-commit.c b/ui-commit.c
index e697571..099d294 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -56,7 +56,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_close_filter(ctx.repo->email_filter);
html("</td><td class='right'>");
html_txt(show_date(info->author_date, info->author_tz,
- cgit_date_mode(FMT_LONGDATE)));
+ cgit_date_mode(DATE_ISO8601)));
html("</td></tr>\n");
html("<tr><th>committer</th><td>");
cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
@@ -68,7 +68,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_close_filter(ctx.repo->email_filter);
html("</td><td class='right'>");
html_txt(show_date(info->committer_date, info->committer_tz,
- cgit_date_mode(FMT_LONGDATE)));
+ cgit_date_mode(DATE_ISO8601)));
html("</td></tr>\n");
html("<tr><th>commit</th><td colspan='2' class='sha1'>");
tmp = oid_to_hex(&commit->object.oid);
diff --git a/ui-shared.c b/ui-shared.c
index d1f9249..03dcc08 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -607,11 +607,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
path[len - 1] = tail;
}
-const struct date_mode *cgit_date_mode(const char *format)
+const struct date_mode *cgit_date_mode(enum date_mode_type type)
{
static struct date_mode mode;
- mode.type = DATE_STRFTIME;
- mode.strftime_fmt = format;
+ mode.type = type;
mode.local = ctx.cfg.local_time;
return &mode;
}
@@ -620,7 +619,7 @@ static void print_rel_date(time_t t, int tz, double value,
const char *class, const char *suffix)
{
htmlf("<span class='%s' title='", class);
- html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+ html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
htmlf("'>%.0f %s</span>", value, suffix);
}
@@ -637,9 +636,9 @@ void cgit_print_age(time_t t, int tz, time_t max_relative)
if (secs > max_relative && max_relative >= 0) {
html("<span title='");
- html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+ html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
html("'>");
- html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE)));
+ html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
html("</span>");
return;
}
@@ -781,7 +780,7 @@ void cgit_print_docend(void)
else {
htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
cgit_version);
- html_txt(show_date(time(NULL), 0, cgit_date_mode(FMT_LONGDATE)));
+ html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601)));
html("</div>\n");
}
html("</div> <!-- id=cgit -->\n");
diff --git a/ui-shared.h b/ui-shared.h
index 43789de..b457c97 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -61,7 +61,7 @@ __attribute__((format (printf,1,2)))
extern void cgit_print_error(const char *fmt, ...);
__attribute__((format (printf,1,0)))
extern void cgit_vprint_error(const char *fmt, va_list ap);
-extern const struct date_mode *cgit_date_mode(const char *format);
+extern const struct date_mode *cgit_date_mode(enum date_mode_type type);
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
extern void cgit_print_http_headers(void);
extern void cgit_redirect(const char *url, bool permanent);
diff --git a/ui-tag.c b/ui-tag.c
index b011198..6b838cb 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -77,7 +77,7 @@ void cgit_print_tag(char *revname)
if (info->tagger_date > 0) {
html("<tr><td>tag date</td><td>");
html_txt(show_date(info->tagger_date, info->tagger_tz,
- cgit_date_mode(FMT_LONGDATE)));
+ cgit_date_mode(DATE_ISO8601)));
html("</td></tr>\n");
}
if (info->tagger) {
--
2.7.0.389.ga73dcac
next prev parent reply other threads:[~2016-02-08 15:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 19:33 [PATCH 0/8] Show times in the originator's timezone john
2016-01-19 19:33 ` [PATCH 1/8] ui-shared: remove "format" from cgit_print_age() john
2016-01-19 19:33 ` [PATCH 2/8] parsing: add timezone to ident structures john
2016-01-19 19:33 ` [PATCH 3/8] ui-shared: add cgit_date_mode() john
2016-02-08 13:20 ` Jason
2016-02-08 13:23 ` Jason
2016-01-19 19:33 ` [PATCH 4/8] ui-{commit,tag}: show dates in originator's timezone john
2016-01-19 19:33 ` [PATCH 5/8] ui: show ages in the " john
2016-01-19 19:33 ` [PATCH 6/8] ui-shared: use show_date for footer timestamp john
2016-01-19 19:33 ` [PATCH 7/8] ui-atom: use show_date directly for atom dates john
2016-01-19 19:33 ` [PATCH 8/8] ui-shared: remove cgit_print_date() john
2016-02-08 13:23 ` [PATCH 0/8] Show times in the originator's timezone Jason
2016-02-08 13:38 ` Jason
2016-02-08 14:08 ` john
2016-02-08 14:33 ` Jason
2016-02-08 15:05 ` john [this message]
2016-02-08 15:06 ` [PATCH 2/2] ui-atom: avoid DATE_STRFTIME john
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160208150554.GO29880@serenity.lan \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).