diff options
author | John Keeping | 2014-12-20 13:59:39 +0000 |
---|---|---|
committer | Jason A. Donenfeld | 2014-12-23 19:32:24 -0700 |
commit | caed6cb27f1869b0590cab56fc3394762892d049 (patch) | |
tree | 30eb29679ef3095b7917685862c21066af35b701 | |
parent | git: use xz compressed archive for download (diff) | |
download | cgit-caed6cb27f1869b0590cab56fc3394762892d049.tar.gz cgit-caed6cb27f1869b0590cab56fc3394762892d049.zip |
ui-shared: show absolute time in tooltip for relative dates
Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r-- | ui-shared.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/ui-shared.c b/ui-shared.c index cd97ffb..bd74f42 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -587,6 +587,23 @@ void cgit_print_date(time_t secs, const char *format, int local_time) | |||
587 | html_txt(buf); | 587 | html_txt(buf); |
588 | } | 588 | } |
589 | 589 | ||
590 | static void print_rel_date(time_t t, double value, | ||
591 | const char *class, const char *suffix) | ||
592 | { | ||
593 | char buf[64]; | ||
594 | struct tm *time; | ||
595 | |||
596 | if (ctx.cfg.local_time) | ||
597 | time = localtime(&t); | ||
598 | else | ||
599 | time = gmtime(&t); | ||
600 | strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time); | ||
601 | |||
602 | htmlf("<span class='%s' title='", class); | ||
603 | html_attr(buf); | ||
604 | htmlf("'>%.0f %s</span>", value, suffix); | ||
605 | } | ||
606 | |||
590 | void cgit_print_age(time_t t, time_t max_relative, const char *format) | 607 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
591 | { | 608 | { |
592 | time_t now, secs; | 609 | time_t now, secs; |
@@ -604,32 +621,26 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format) | |||
604 | } | 621 | } |
605 | 622 | ||
606 | if (secs < TM_HOUR * 2) { | 623 | if (secs < TM_HOUR * 2) { |
607 | htmlf("<span class='age-mins'>%.0f min.</span>", | 624 | print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min."); |
608 | secs * 1.0 / TM_MIN); | ||
609 | return; | 625 | return; |
610 | } | 626 | } |
611 | if (secs < TM_DAY * 2) { | 627 | if (secs < TM_DAY * 2) { |
612 | htmlf("<span class='age-hours'>%.0f hours</span>", | 628 | print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours"); |
613 | secs * 1.0 / TM_HOUR); | ||
614 | return; | 629 | return; |
615 | } | 630 | } |
616 | if (secs < TM_WEEK * 2) { | 631 | if (secs < TM_WEEK * 2) { |
617 | htmlf("<span class='age-days'>%.0f days</span>", | 632 | print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days"); |
618 | secs * 1.0 / TM_DAY); | ||
619 | return; | 633 | return; |
620 | } | 634 | } |
621 | if (secs < TM_MONTH * 2) { | 635 | if (secs < TM_MONTH * 2) { |
622 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 636 | print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); |
623 | secs * 1.0 / TM_WEEK); | ||
624 | return; | 637 | return; |
625 | } | 638 | } |
626 | if (secs < TM_YEAR * 2) { | 639 | if (secs < TM_YEAR * 2) { |
627 | htmlf("<span class='age-months'>%.0f months</span>", | 640 | print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months"); |
628 | secs * 1.0 / TM_MONTH); | ||
629 | return; | 641 | return; |
630 | } | 642 | } |
631 | htmlf("<span class='age-years'>%.0f years</span>", | 643 | print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years"); |
632 | secs * 1.0 / TM_YEAR); | ||
633 | } | 644 | } |
634 | 645 | ||
635 | void cgit_print_http_headers(void) | 646 | void cgit_print_http_headers(void) |