the repository which powers this website
Fix display of relative times
Change "min." to "minutes" and fixes nonsense times such as "2020-01-01 ago"
RunasSudo 9 months ago
parent c262004 · commit c5548f0
-rw-r--r--themed/commit.html2
-rw-r--r--themed/log.html2
-rw-r--r--themed/refs.html6
-rw-r--r--themed/summary.html2
-rw-r--r--ui-shared.c43
-rw-r--r--ui-shared.h1
6 files changed, 50 insertions, 6 deletions
diff --git a/themed/commit.html b/themed/commit.html
index 9f5ec474..b7f9f59f 100644
--- a/themed/commit.html
+++ b/themed/commit.html
@@ -36,7 +36,7 @@
<div class="px-3 py-2 rounded-b-md bg-gray-50 flex gap-x-1 items-center">
<img src="{! gravatar_url(info->author_email); !}?s=24">
<span class="font-semibold text-sm">{{ info->author }}</span>
- <span class="font-gray-500 text-sm">{! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago</span>
+ <span class="text-gray-500 text-sm">{! cgit_print_age_themed(info->committer_date, info->committer_tz, TM_MONTH * 12); !}</span>
<div class="flex-1"></div>
<span class="font-gray-500 text-sm">
{% for struct commit_list *p = commit->parents; p; p = p->next %}
diff --git a/themed/log.html b/themed/log.html
index d47436bf..850e11d4 100644
--- a/themed/log.html
+++ b/themed/log.html
@@ -32,7 +32,7 @@
<div><a href="{! cgit_shared_reporevlink_url("commit", ctx.qry.head, oid_to_hex(&commit->object.oid), ctx.qry.vpath); !}" class="hover:text-blue-600 hover:underline">{{ info->subject }}</a></div>
<div class="mt-2 text-sm text-gray-500 flex gap-x-1 items-center">
<img src="{! gravatar_url(info->author_email); !}?s=16">
- {{ info->author }} committed {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
+ {{ info->author }} committed {! cgit_print_age_themed(info->committer_date, info->committer_tz, TM_MONTH * 12); !}
</div>
</div>
<div class="px-3 py-2 border-t border-gray-300 flex items-center">
diff --git a/themed/refs.html b/themed/refs.html
index 80b4e527..18d7d2da 100644
--- a/themed/refs.html
+++ b/themed/refs.html
@@ -35,7 +35,7 @@
<div><a href="{! cgit_shared_repolink_url(NULL, name, NULL); !}" class="text-blue-500 hover:text-blue-600 hover:underline">{{ name }}</a></div>
{% if ref->object->type == OBJ_COMMIT %}
<div class="text-sm text-gray-500 flex gap-x-1">
- {{ info->subject }} &middot; Updated {! cgit_print_age(info->committer_date, info->committer_tz, -1); !} ago
+ {{ info->subject }} &middot; Updated {! cgit_print_age_themed(info->committer_date, info->committer_tz, TM_MONTH * 12); !}
<img src="{! gravatar_url(info->author_email); !}?s=24" class="mt-[-0.2rem]">
{{ info->author }}
</div>
@@ -86,7 +86,7 @@
{% if info && (info->tagger_date > 0 || info->tagger) %}
<div class="text-sm text-gray-500 flex gap-x-1">
{% if info->tagger_date > 0 %}
- Updated {! cgit_print_age(info->tagger_date, info->tagger_tz, -1); !} ago
+ Updated {! cgit_print_age_themed(info->tagger_date, info->tagger_tz, TM_MONTH * 12); !}
{% endif %}
{% if info->tagger %}
<img src="{! gravatar_url(info->tagger_email); !}?s=24" class="mt-[-0.2rem]">
@@ -95,7 +95,7 @@
</div>
{% elif ref->object->type == OBJ_COMMIT %}
<div class="text-sm text-gray-500 flex gap-x-1">
- Updated {! cgit_print_age(ref->commit->commit->date, 0, -1); !} ago
+ Updated {! cgit_print_age_themed(ref->commit->commit->date, 0, TM_MONTH * 12); !}
<img src="{! gravatar_url(ref->commit->author_email); !}?s=24" class="mt-[-0.2rem]">
{{ ref->commit->author }}
</div>
diff --git a/themed/summary.html b/themed/summary.html
index bcf855c5..be88b54a 100644
--- a/themed/summary.html
+++ b/themed/summary.html
@@ -39,7 +39,7 @@
{! short_commit_id(oid_to_hex(&commit->object.oid)); !}
</a>
&middot;
- {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
+ {! cgit_print_age_themed(info->committer_date, info->committer_tz, TM_MONTH * 12); !}
</span>
</div>
{! cgit_free_commitinfo(info); !}
diff --git a/ui-shared.c b/ui-shared.c
index 92d399f1..d28d9037 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -784,6 +784,49 @@ void cgit_print_age(time_t t, int tz, time_t max_relative)
print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years");
}
+void cgit_print_age_themed(time_t t, int tz, time_t max_relative)
+{
+ time_t now, secs;
+
+ if (!t)
+ return;
+ time(&now);
+ secs = now - t;
+ if (secs < 0)
+ secs = 0;
+
+ if (secs > max_relative && max_relative >= 0) {
+ html("<span title='");
+ html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
+ html("'>");
+ html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
+ html("</span>");
+ return;
+ }
+
+ if (secs < TM_HOUR * 2) {
+ print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "minutes ago");
+ return;
+ }
+ if (secs < TM_DAY * 2) {
+ print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours ago");
+ return;
+ }
+ if (secs < TM_WEEK * 2) {
+ print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days ago");
+ return;
+ }
+ if (secs < TM_MONTH * 2) {
+ print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks ago");
+ return;
+ }
+ if (secs < TM_YEAR * 2) {
+ print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months ago");
+ return;
+ }
+ print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years ago");
+}
+
void cgit_print_http_headers(void)
{
if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1"))
diff --git a/ui-shared.h b/ui-shared.h
index 5152030a..8e3833e2 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -73,6 +73,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(enum date_mode_type type);
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
+extern void cgit_print_age_themed(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);