Author: John Keeping <john@keeping.me.uk>
ui: show ages in the originator's timezone This affects the tooltip showing the full time and the case when a date is sufficiently old to be shown in full rather than as an offset. Signed-off-by: John Keeping <john@keeping.me.uk>
ui-log.c | 4 ++-- ui-refs.c | 6 +++--- ui-repolist.c | 2 +- ui-shared.c | 22 +++++++++++----------- ui-shared.h | 2 +-
diff --git a/ui-log.c b/ui-log.c index 5f6a69ced50a34e1734179bbb89fcddb08890075..0a3938bf97c581b92e5ba0576d8232fd78c32a3a 100644 --- a/ui-log.c +++ b/ui-log.c @@ -204,7 +204,7 @@ strbuf_setlen(&graphbuf, 0); } else { html("<td>"); - cgit_print_age(commit->date, TM_WEEK * 2); + cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); html("</td>"); } @@ -244,7 +244,7 @@ cgit_close_filter(ctx.repo->email_filter); if (revs->graph) { html("</td><td>"); - cgit_print_age(commit->date, TM_WEEK * 2); + cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); } if (!lines_counted && (ctx.repo->enable_log_filecount || diff --git a/ui-refs.c b/ui-refs.c index 0652b89edf0783a6a56241b86e38cf4016e727eb..5b4530e5410fd159534e03051ce86471c0992bf3 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -73,7 +73,7 @@ cgit_open_filter(ctx.repo->email_filter, info->author_email, "refs"); html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); html("</td><td colspan='2'>"); - cgit_print_age(info->commit->date, -1); + cgit_print_age(info->committer_date, info->committer_tz, -1); } else { html("</td><td></td><td>"); cgit_object_link(ref->object); @@ -161,9 +161,9 @@ } html("</td><td colspan='2'>"); if (info) { if (info->tagger_date > 0) - cgit_print_age(info->tagger_date, -1); + cgit_print_age(info->tagger_date, info->tagger_tz, -1); } else if (ref->object->type == OBJ_COMMIT) { - cgit_print_age(ref->commit->commit->date, -1); + cgit_print_age(ref->commit->commit->date, 0, -1); } html("</td></tr>\n"); diff --git a/ui-repolist.c b/ui-repolist.c index 60044699d176608913fc65b4622d5182414f4f43..30915df283b7ea1b7ae9800229153e94a84c7d29 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -79,7 +79,7 @@ static void print_modtime(struct cgit_repo *repo) { time_t t; if (get_repo_modtime(repo, &t)) - cgit_print_age(t, -1); + cgit_print_age(t, 0, -1); } static int is_match(struct cgit_repo *repo) diff --git a/ui-shared.c b/ui-shared.c index 923d1025f71f062832a8a7df22b24d2107fa8ad1..3ce86fe7c8a82511adc70d6819605107844dafff 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -636,15 +636,15 @@ mode.local = ctx.cfg.local_time; return &mode; } -static void print_rel_date(time_t t, double value, +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(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time)); + html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE))); htmlf("'>%.0f %s</span>", value, suffix); } -void cgit_print_age(time_t t, time_t max_relative) +void cgit_print_age(time_t t, int tz, time_t max_relative) { time_t now, secs; @@ -657,34 +657,34 @@ secs = 0; if (secs > max_relative && max_relative >= 0) { html("<span title='"); - html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time)); + html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE))); html("'>"); - cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time); + html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); html("</span>"); return; } if (secs < TM_HOUR * 2) { - print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min."); + print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min."); return; } if (secs < TM_DAY * 2) { - print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours"); + print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours"); return; } if (secs < TM_WEEK * 2) { - print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days"); + print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days"); return; } if (secs < TM_MONTH * 2) { - print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); + print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); return; } if (secs < TM_YEAR * 2) { - print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months"); + print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months"); return; } - print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years"); + print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years"); } void cgit_print_http_headers(void) diff --git a/ui-shared.h b/ui-shared.h index 707cec9a132acf43a4d6f8a3f6059a55e016d101..e42f13a4444921e98064bd1e320bafef81f4d034 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -63,7 +63,7 @@ __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 void cgit_print_date(time_t secs, const char *format, int local_time); -extern void cgit_print_age(time_t t, 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_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void);