commit - bf26a633636ba2058b6bb747b0dd4ab17cb185a8
commit + 7781b9910fcbba579c2e112bbfdea73a64ccad70
blob - 31ec1b7671fbb5d5b67b5d5ef6f6ac7742ca1782
blob + 5d1283460327c8a36e76c5f8ed29b5fd573a5ce8
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
}
int
-gotweb_render_age(struct template *tp, time_t committer_time, int ref_tm)
+gotweb_render_age(struct template *tp, time_t committer_time)
{
struct request *c = tp->tp_arg;
- struct tm tm;
long long diff_time;
const char *years = "years ago", *months = "months ago";
const char *weeks = "weeks ago", *days = "days ago";
const char *hours = "hours ago", *minutes = "minutes ago";
const char *seconds = "seconds ago", *now = "right now";
- char *s;
- char datebuf[64];
- size_t r;
- switch (ref_tm) {
- case TM_DIFF:
- diff_time = time(NULL) - committer_time;
- if (diff_time > 60 * 60 * 24 * 365 * 2) {
- if (tp_writef(c->tp, "%lld %s",
- (diff_time / 60 / 60 / 24 / 365), years) == -1)
- return -1;
- } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
- if (tp_writef(c->tp, "%lld %s",
- (diff_time / 60 / 60 / 24 / (365 / 12)),
- months) == -1)
- return -1;
- } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
- if (tp_writef(c->tp, "%lld %s",
- (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
- return -1;
- } else if (diff_time > 60 * 60 * 24 * 2) {
- if (tp_writef(c->tp, "%lld %s",
- (diff_time / 60 / 60 / 24), days) == -1)
- return -1;
- } else if (diff_time > 60 * 60 * 2) {
- if (tp_writef(c->tp, "%lld %s",
- (diff_time / 60 / 60), hours) == -1)
- return -1;
- } else if (diff_time > 60 * 2) {
- if (tp_writef(c->tp, "%lld %s", (diff_time / 60),
- minutes) == -1)
- return -1;
- } else if (diff_time > 2) {
- if (tp_writef(c->tp, "%lld %s", diff_time,
- seconds) == -1)
- return -1;
- } else {
- if (tp_writes(tp, now) == -1)
- return -1;
- }
- break;
- case TM_LONG:
- if (gmtime_r(&committer_time, &tm) == NULL)
+ diff_time = time(NULL) - committer_time;
+ if (diff_time > 60 * 60 * 24 * 365 * 2) {
+ if (tp_writef(c->tp, "%lld %s",
+ (diff_time / 60 / 60 / 24 / 365), years) == -1)
return -1;
-
- s = asctime_r(&tm, datebuf);
- if (s == NULL)
+ } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
+ if (tp_writef(c->tp, "%lld %s",
+ (diff_time / 60 / 60 / 24 / (365 / 12)),
+ months) == -1)
return -1;
-
- if (tp_writes(tp, datebuf) == -1 ||
- tp_writes(tp, " UTC") == -1)
+ } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
+ if (tp_writef(c->tp, "%lld %s",
+ (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
return -1;
- break;
+ } else if (diff_time > 60 * 60 * 24 * 2) {
+ if (tp_writef(c->tp, "%lld %s",
+ (diff_time / 60 / 60 / 24), days) == -1)
+ return -1;
+ } else if (diff_time > 60 * 60 * 2) {
+ if (tp_writef(c->tp, "%lld %s",
+ (diff_time / 60 / 60), hours) == -1)
+ return -1;
+ } else if (diff_time > 60 * 2) {
+ if (tp_writef(c->tp, "%lld %s", (diff_time / 60),
+ minutes) == -1)
+ return -1;
+ } else if (diff_time > 2) {
+ if (tp_writef(c->tp, "%lld %s", diff_time,
+ seconds) == -1)
+ return -1;
+ } else {
+ if (tp_writes(tp, now) == -1)
+ return -1;
}
return 0;
}
blob - 908f76ea062a793a125040df6011a8852db3b00a
blob + 1ea7f7b6e6083db17472436ab39cbdb63fb3dc1f
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
ACTIONS__MAX,
};
-enum gotweb_ref_tm {
- TM_DIFF,
- TM_LONG,
-};
-
extern struct gotwebd *gotwebd_env;
typedef int (*got_render_blame_line_cb)(struct template *, const char *,
/* gotweb.c */
void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
struct gotweb_url *, int *);
-int gotweb_render_age(struct template *, time_t, int);
+int gotweb_render_age(struct template *, time_t);
const struct got_error *gotweb_init_transport(struct transport **);
const char *gotweb_action_name(int);
int gotweb_render_url(struct request *, struct gotweb_url *);
blob - 675bb083cd6fc3a41a5fcd288e910040a637d289
blob + a51f74abb8dfc67479ed3558a8c7efd83400e068
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
#include "gotwebd.h"
#include "tmpl.h"
+enum gotweb_ref_tm {
+ TM_DIFF,
+ TM_LONG,
+};
+
+static int datetime(struct template *, time_t, int);
static int gotweb_render_blob_line(struct template *, const char *, size_t);
static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
static int blame_line(struct template *, const char *, struct blame_line *,
static inline int rss_author(struct template *, char *);
!}
+
+{{ define datetime(struct template *tp, time_t t, int fmt) }}
+{!
+ struct tm tm;
+ char rfc3339[64];
+ char datebuf[64];
+
+ if (gmtime_r(&t, &tm) == NULL)
+ return -1;
+
+ if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
+ return -1;
+
+ if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
+ return -1;
+!}
+<time datetime="{{ rfc3339 }}">
+ {{ if fmt == TM_DIFF }}
+ {{ render gotweb_render_age(tp, t) }}
+ {{ else }}
+ {{ datebuf }} {{ " UTC" }}
+ {{ end }}
+</time>
+{{ end }}
{{ define gotweb_render_page(struct template *tp,
int (*body)(struct template *)) }}
{{ end }}
{{ if srv->show_repo_age }}
<div class="index_project_age">
- {{ render gotweb_render_age(tp, repo_dir->age, TM_DIFF) }}
+ {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
</div>
{{ end }}
<div class="navs_wrapper">
<div class='brief'>
<p class='brief_meta'>
<span class='briefs_age'>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
+ {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
</span>
{{" "}}
<span class="briefs_author">
{{ end }}
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
+ {{ render datetime(tp, rc->committer_time, TM_LONG) }}
</dd>
</dl>
</div>
<dl id="blob_header">
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
+ {{ render datetime(tp, rc->committer_time, TM_LONG) }}
</dd>
<dt>Message:</dt>
<dd class="commit-msg">{{ rc->commit_msg }}</dd>
<dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
+ {{ render datetime(tp, rc->committer_time, TM_LONG) }}
</dd>
<dt>Message:</dt>
<dd class="commit-msg">{{ rc->commit_msg }}</dd>
}
!}
<div class="tag_age">
- {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
+ {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
</div>
<div class="tag_name">{{ tag_name }}</div>
<div class="tag_log">
<dd>{{ rt->tagger }}</dd>
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
+ {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
</dd>
<dt>Message:</dt>
<dd class="commit-msg">{{ rt->commit_msg }}</dd>
{{ end }}
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
+ {{ render datetime(tp, rc->committer_time, TM_LONG) }}
</dd>
<dt>Message:</dt>
<dd class="commit-msg">{{ rc->commit_msg }}</dd>
!}
<section class="branches_wrapper">
<div class="branches_age">
- {{ render gotweb_render_age(tp, age, TM_DIFF) }}
+ {{ render datetime(tp, age, TM_DIFF) }}
</div>
<div class="branch">
<a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
{{ if srv->show_repo_age }}
<dt>Last Change:</dt>
<dd>
- {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
+ {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
</dd>
{{ end }}
{{ if srv->show_repo_cloneurl }}
<dl id="blame_header">
<dt>Date:</dt>
<dd>
- {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
+ {{ render datetime(tp, rc->committer_time, TM_LONG) }}
</dd>
<dt>Message:</dt>
<dd class="commit-msg">{{ rc->commit_msg }}</dd>