Avoid DATE_STRFTIME for long/short dates

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@keeping.me.uk>
This commit is contained in:
John Keeping 2016-02-08 15:05:54 +00:00 committed by Jason A. Donenfeld
parent bdcbe0922d
commit 9c15f3c695
5 changed files with 10 additions and 13 deletions

2
cgit.h
View File

@ -32,8 +32,6 @@
/* /*
* Dateformats used on misc. pages * 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" #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"

View File

@ -56,7 +56,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_close_filter(ctx.repo->email_filter); cgit_close_filter(ctx.repo->email_filter);
html("</td><td class='right'>"); html("</td><td class='right'>");
html_txt(show_date(info->author_date, info->author_tz, 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("</td></tr>\n");
html("<tr><th>committer</th><td>"); html("<tr><th>committer</th><td>");
cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit"); 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); cgit_close_filter(ctx.repo->email_filter);
html("</td><td class='right'>"); html("</td><td class='right'>");
html_txt(show_date(info->committer_date, info->committer_tz, 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("</td></tr>\n");
html("<tr><th>commit</th><td colspan='2' class='sha1'>"); html("<tr><th>commit</th><td colspan='2' class='sha1'>");
tmp = oid_to_hex(&commit->object.oid); tmp = oid_to_hex(&commit->object.oid);

View File

@ -607,11 +607,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
path[len - 1] = tail; 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; static struct date_mode mode;
mode.type = DATE_STRFTIME; mode.type = type;
mode.strftime_fmt = format;
mode.local = ctx.cfg.local_time; mode.local = ctx.cfg.local_time;
return &mode; return &mode;
} }
@ -620,7 +619,7 @@ static void print_rel_date(time_t t, int tz, double value,
const char *class, const char *suffix) const char *class, const char *suffix)
{ {
htmlf("<span class='%s' title='", class); 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); 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) { if (secs > max_relative && max_relative >= 0) {
html("<span title='"); 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("'>");
html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
html("</span>"); html("</span>");
return; return;
} }
@ -781,7 +780,7 @@ void cgit_print_docend(void)
else { else {
htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
cgit_version); 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>\n");
} }
html("</div> <!-- id=cgit -->\n"); html("</div> <!-- id=cgit -->\n");

View File

@ -61,7 +61,7 @@ __attribute__((format (printf,1,2)))
extern void cgit_print_error(const char *fmt, ...); extern void cgit_print_error(const char *fmt, ...);
__attribute__((format (printf,1,0))) __attribute__((format (printf,1,0)))
extern void cgit_vprint_error(const char *fmt, va_list ap); 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_age(time_t t, int tz, time_t max_relative);
extern void cgit_print_http_headers(void); extern void cgit_print_http_headers(void);
extern void cgit_redirect(const char *url, bool permanent); extern void cgit_redirect(const char *url, bool permanent);

View File

@ -77,7 +77,7 @@ void cgit_print_tag(char *revname)
if (info->tagger_date > 0) { if (info->tagger_date > 0) {
html("<tr><td>tag date</td><td>"); html("<tr><td>tag date</td><td>");
html_txt(show_date(info->tagger_date, info->tagger_tz, html_txt(show_date(info->tagger_date, info->tagger_tz,
cgit_date_mode(FMT_LONGDATE))); cgit_date_mode(DATE_ISO8601)));
html("</td></tr>\n"); html("</td></tr>\n");
} }
if (info->tagger) { if (info->tagger) {