Fix display of relative times
Change "min." to "minutes" and fixes nonsense times such as "2020-01-01 ago"
This commit is contained in:
parent
c262004043
commit
c5548f08e4
@ -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 %}
|
||||
|
@ -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">
|
||||
|
@ -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 }} · Updated {! cgit_print_age(info->committer_date, info->committer_tz, -1); !} ago
|
||||
{{ info->subject }} · 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>
|
||||
|
@ -39,7 +39,7 @@
|
||||
{! short_commit_id(oid_to_hex(&commit->object.oid)); !}
|
||||
</a>
|
||||
·
|
||||
{! 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); !}
|
||||
|
43
ui-shared.c
43
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"))
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user