* [PATCH] ui-shared: show absolute time in tooltip for relative dates
@ 2014-12-20 13:59 john
2014-12-24 2:33 ` Jason
0 siblings, 1 reply; 2+ messages in thread
From: john @ 2014-12-20 13:59 UTC (permalink / raw)
Signed-off-by: John Keeping <john at keeping.me.uk>
---
ui-shared.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/ui-shared.c b/ui-shared.c
index 9dde0a3..07e21bf 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -588,6 +588,23 @@ void cgit_print_date(time_t secs, const char *format, int local_time)
html_txt(buf);
}
+static void print_rel_date(time_t t, double value,
+ const char *class, const char *suffix)
+{
+ char buf[64];
+ struct tm *time;
+
+ if (ctx.cfg.local_time)
+ time = localtime(&t);
+ else
+ time = gmtime(&t);
+ strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time);
+
+ htmlf("<span class='%s' title='", class);
+ html_attr(buf);
+ htmlf("'>%.0f %s</span>", value, suffix);
+}
+
void cgit_print_age(time_t t, time_t max_relative, const char *format)
{
time_t now, secs;
@@ -605,32 +622,26 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
}
if (secs < TM_HOUR * 2) {
- htmlf("<span class='age-mins'>%.0f min.</span>",
- secs * 1.0 / TM_MIN);
+ print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min.");
return;
}
if (secs < TM_DAY * 2) {
- htmlf("<span class='age-hours'>%.0f hours</span>",
- secs * 1.0 / TM_HOUR);
+ print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours");
return;
}
if (secs < TM_WEEK * 2) {
- htmlf("<span class='age-days'>%.0f days</span>",
- secs * 1.0 / TM_DAY);
+ print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days");
return;
}
if (secs < TM_MONTH * 2) {
- htmlf("<span class='age-weeks'>%.0f weeks</span>",
- secs * 1.0 / TM_WEEK);
+ print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
return;
}
if (secs < TM_YEAR * 2) {
- htmlf("<span class='age-months'>%.0f months</span>",
- secs * 1.0 / TM_MONTH);
+ print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months");
return;
}
- htmlf("<span class='age-years'>%.0f years</span>",
- secs * 1.0 / TM_YEAR);
+ print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years");
}
void cgit_print_http_headers(void)
--
2.2.1.286.gdf3164c
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] ui-shared: show absolute time in tooltip for relative dates
2014-12-20 13:59 [PATCH] ui-shared: show absolute time in tooltip for relative dates john
@ 2014-12-24 2:33 ` Jason
0 siblings, 0 replies; 2+ messages in thread
From: Jason @ 2014-12-24 2:33 UTC (permalink / raw)
Very nice, thanks. Merged!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141223/a3ee65cf/attachment-0001.html>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-24 2:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-20 13:59 [PATCH] ui-shared: show absolute time in tooltip for relative dates john
2014-12-24 2:33 ` Jason
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).