Author: Stefan Naewe <stefan.naewe@atlas-elektronik.com>
Added `local-time` option to cgitrc When `local-time` is set, commit, tag and patch timestamps will be printed in the servers timezone. Also, regardless of the value of `local-time`, these timestamps will now always show the timezone. Signed-off-by: Stefan Naewe <stefan.naewe@atlas-elektronik.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c | 3 +++ cgit.h | 3 ++- ui-commit.c | 4 ++-- ui-patch.c | 2 +- ui-shared.c | 11 +++++++---- ui-shared.h | 2 +- ui-tag.c | 2 +-
diff --git a/cgit.c b/cgit.c index e2d5edb629f98e05f9003e5921661de69a907a95..f49fffadf6191f904b07a3267597a0846f952433 100644 --- a/cgit.c +++ b/cgit.c @@ -87,6 +87,8 @@ else if (!strcmp(name, "robots")) ctx.cfg.robots = xstrdup(value); else if (!strcmp(name, "clone-prefix")) ctx.cfg.clone_prefix = xstrdup(value); + else if (!strcmp(name, "local-time")) + ctx.cfg.local_time = atoi(value); else if (!strcmp(name, "repo.group")) ctx.cfg.repo_group = xstrdup(value); else if (!strcmp(name, "repo.url")) @@ -167,6 +169,7 @@ ctx->cfg.cache_root_ttl = 5; ctx->cfg.cache_static_ttl = -1; ctx->cfg.css = "/cgit.css"; ctx->cfg.logo = "/git-logo.png"; + ctx->cfg.local_time = 0; ctx->cfg.max_repo_count = 50; ctx->cfg.max_commit_count = 50; ctx->cfg.max_lock_attempts = 5; diff --git a/cgit.h b/cgit.h index 7881acaf065902a392bc1b513fb4d87a4aabec88..b01fa314fbfc850108bfe012e0e6ad0cfa821466 100644 --- a/cgit.h +++ b/cgit.h @@ -22,7 +22,7 @@ /* * Dateformats used on misc. pages */ -#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" +#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" #define FMT_SHORTDATE "%Y-%m-%d" @@ -148,6 +148,7 @@ int cache_static_ttl; int enable_index_links; int enable_log_filecount; int enable_log_linecount; + int local_time; int max_repo_count; int max_commit_count; int max_lock_attempts; diff --git a/ui-commit.c b/ui-commit.c index 4bbb391602771810eca26cbb00ef148b593f2893..a6a85a4af2dd916fd4f7fa47fcf371fb352a2715 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -40,14 +40,14 @@ html_txt(info->author); html(" "); html_txt(info->author_email); html("</td><td class='right'>"); - cgit_print_date(info->author_date, FMT_LONGDATE); + cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); html("</td></tr>\n"); html("<tr><th>committer</th><td>"); html_txt(info->committer); html(" "); html_txt(info->committer_email); html("</td><td class='right'>"); - cgit_print_date(info->committer_date, FMT_LONGDATE); + cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); html("</td></tr>\n"); html("<tr><th>commit</th><td colspan='2' class='sha1'>"); tmp = sha1_to_hex(commit->object.sha1); diff --git a/ui-patch.c b/ui-patch.c index c1c4ce30368d668b954d460a4df3b836da58db4f..e60877d8ed2fcf2a6a76dab90d08b5eadcc9ea6f 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -103,7 +103,7 @@ cgit_print_http_headers(&ctx); htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); htmlf("From: %s%s\n", info->author, info->author_email); html("Date: "); - cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n"); + cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); htmlf("Subject: %s\n\n", info->subject); if (info->msg && *info->msg) { htmlf("%s", info->msg); diff --git a/ui-shared.c b/ui-shared.c index 4280a70432b0a3f7869f0a6ddfa132df0af829c7..197ee37409b7497d27c1ea766ebd6d4405d843bc 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -353,14 +353,17 @@ sha1_to_hex(obj->sha1)); html_link_close(); } -void cgit_print_date(time_t secs, char *format) +void cgit_print_date(time_t secs, char *format, int local_time) { char buf[64]; struct tm *time; if (!secs) return; - time = gmtime(&secs); + if(local_time) + time = localtime(&secs); + else + time = gmtime(&secs); strftime(buf, sizeof(buf)-1, format, time); html_txt(buf); } @@ -375,7 +378,7 @@ time(&now); secs = now - t; if (secs > max_relative && max_relative >= 0) { - cgit_print_date(t, format); + cgit_print_date(t, format, ctx.cfg.local_time); return; } @@ -453,7 +456,7 @@ if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { html("<div class='footer'>generated "); - cgit_print_date(time(NULL), FMT_LONGDATE); + cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); htmlf(" by cgit %s", cgit_version); html("</div>\n"); } diff --git a/ui-shared.h b/ui-shared.h index 3005d305d41a3bf916e63093a61d4589a8399c10..07da4b40577e402095a01813310d93a776fdd344 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -27,7 +27,7 @@ char *new_rev, char *old_rev, char *path); extern void cgit_object_link(struct object *obj); extern void cgit_print_error(char *msg); -extern void cgit_print_date(time_t secs, char *format); +extern void cgit_print_date(time_t secs, char *format, int local_time); extern void cgit_print_age(time_t t, time_t max_relative, char *format); extern void cgit_print_http_headers(struct cgit_context *ctx); extern void cgit_print_docstart(struct cgit_context *ctx); diff --git a/ui-tag.c b/ui-tag.c index ab2c66d76eefada3f9655d3ba1689ac84445b711..b4db32e396dc18b3761bfd2a049c8a9b6bee4fd8 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -57,7 +57,7 @@ htmlf("\n", revname, sha1_to_hex(sha1)); if (info->tagger_date > 0) { html("<tr><td>Tag date</td><td>"); - cgit_print_date(info->tagger_date, FMT_LONGDATE); + cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); html("</td></tr>\n"); } if (info->tagger) { Tag name %s (%s)