author | Stefan Naewe <stefan.naewe@atlas-elektronik.com> | 2008-08-01 12:54:38 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-08-01 20:09:13 (UTC) |
commit | 0f0ab148c6d444316af10e6b4c7a60630fed45d3 (patch) (unidiff) | |
tree | a52c08e648c5d656866cecf78e757f2f85211b19 /ui-shared.c | |
parent | a1266edfe6ec1fd678c8f6b60ffbd21d88ff5a93 (diff) | |
download | cgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.zip cgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.tar.gz cgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.tar.bz2 |
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>
-rw-r--r-- | ui-shared.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ui-shared.c b/ui-shared.c index 4280a70..197ee37 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -332,71 +332,74 @@ void cgit_object_link(struct object *obj) | |||
332 | 332 | ||
333 | if (obj->type == OBJ_COMMIT) { | 333 | if (obj->type == OBJ_COMMIT) { |
334 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 334 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
335 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 335 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
336 | return; | 336 | return; |
337 | } else if (obj->type == OBJ_TREE) { | 337 | } else if (obj->type == OBJ_TREE) { |
338 | page = "tree"; | 338 | page = "tree"; |
339 | arg = "id"; | 339 | arg = "id"; |
340 | } else if (obj->type == OBJ_TAG) { | 340 | } else if (obj->type == OBJ_TAG) { |
341 | page = "tag"; | 341 | page = "tag"; |
342 | arg = "id"; | 342 | arg = "id"; |
343 | } else { | 343 | } else { |
344 | page = "blob"; | 344 | page = "blob"; |
345 | arg = "id"; | 345 | arg = "id"; |
346 | } | 346 | } |
347 | 347 | ||
348 | url = cgit_pageurl(ctx.qry.repo, page, | 348 | url = cgit_pageurl(ctx.qry.repo, page, |
349 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 349 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
350 | html_link_open(url, NULL, NULL); | 350 | html_link_open(url, NULL, NULL); |
351 | htmlf("%s %s", typename(obj->type), | 351 | htmlf("%s %s", typename(obj->type), |
352 | sha1_to_hex(obj->sha1)); | 352 | sha1_to_hex(obj->sha1)); |
353 | html_link_close(); | 353 | html_link_close(); |
354 | } | 354 | } |
355 | 355 | ||
356 | void cgit_print_date(time_t secs, char *format) | 356 | void cgit_print_date(time_t secs, char *format, int local_time) |
357 | { | 357 | { |
358 | char buf[64]; | 358 | char buf[64]; |
359 | struct tm *time; | 359 | struct tm *time; |
360 | 360 | ||
361 | if (!secs) | 361 | if (!secs) |
362 | return; | 362 | return; |
363 | if(local_time) | ||
364 | time = localtime(&secs); | ||
365 | else | ||
363 | time = gmtime(&secs); | 366 | time = gmtime(&secs); |
364 | strftime(buf, sizeof(buf)-1, format, time); | 367 | strftime(buf, sizeof(buf)-1, format, time); |
365 | html_txt(buf); | 368 | html_txt(buf); |
366 | } | 369 | } |
367 | 370 | ||
368 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 371 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
369 | { | 372 | { |
370 | time_t now, secs; | 373 | time_t now, secs; |
371 | 374 | ||
372 | if (!t) | 375 | if (!t) |
373 | return; | 376 | return; |
374 | time(&now); | 377 | time(&now); |
375 | secs = now - t; | 378 | secs = now - t; |
376 | 379 | ||
377 | if (secs > max_relative && max_relative >= 0) { | 380 | if (secs > max_relative && max_relative >= 0) { |
378 | cgit_print_date(t, format); | 381 | cgit_print_date(t, format, ctx.cfg.local_time); |
379 | return; | 382 | return; |
380 | } | 383 | } |
381 | 384 | ||
382 | if (secs < TM_HOUR * 2) { | 385 | if (secs < TM_HOUR * 2) { |
383 | htmlf("<span class='age-mins'>%.0f min.</span>", | 386 | htmlf("<span class='age-mins'>%.0f min.</span>", |
384 | secs * 1.0 / TM_MIN); | 387 | secs * 1.0 / TM_MIN); |
385 | return; | 388 | return; |
386 | } | 389 | } |
387 | if (secs < TM_DAY * 2) { | 390 | if (secs < TM_DAY * 2) { |
388 | htmlf("<span class='age-hours'>%.0f hours</span>", | 391 | htmlf("<span class='age-hours'>%.0f hours</span>", |
389 | secs * 1.0 / TM_HOUR); | 392 | secs * 1.0 / TM_HOUR); |
390 | return; | 393 | return; |
391 | } | 394 | } |
392 | if (secs < TM_WEEK * 2) { | 395 | if (secs < TM_WEEK * 2) { |
393 | htmlf("<span class='age-days'>%.0f days</span>", | 396 | htmlf("<span class='age-days'>%.0f days</span>", |
394 | secs * 1.0 / TM_DAY); | 397 | secs * 1.0 / TM_DAY); |
395 | return; | 398 | return; |
396 | } | 399 | } |
397 | if (secs < TM_MONTH * 2) { | 400 | if (secs < TM_MONTH * 2) { |
398 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 401 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
399 | secs * 1.0 / TM_WEEK); | 402 | secs * 1.0 / TM_WEEK); |
400 | return; | 403 | return; |
401 | } | 404 | } |
402 | if (secs < TM_YEAR * 2) { | 405 | if (secs < TM_YEAR * 2) { |
@@ -432,49 +435,49 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
432 | html_txt(ctx->page.title); | 435 | html_txt(ctx->page.title); |
433 | html("</title>\n"); | 436 | html("</title>\n"); |
434 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 437 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
435 | if (ctx->cfg.robots && *ctx->cfg.robots) | 438 | if (ctx->cfg.robots && *ctx->cfg.robots) |
436 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 439 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
437 | html("<link rel='stylesheet' type='text/css' href='"); | 440 | html("<link rel='stylesheet' type='text/css' href='"); |
438 | html_attr(ctx->cfg.css); | 441 | html_attr(ctx->cfg.css); |
439 | html("'/>\n"); | 442 | html("'/>\n"); |
440 | if (ctx->cfg.favicon) { | 443 | if (ctx->cfg.favicon) { |
441 | html("<link rel='shortcut icon' href='"); | 444 | html("<link rel='shortcut icon' href='"); |
442 | html_attr(ctx->cfg.favicon); | 445 | html_attr(ctx->cfg.favicon); |
443 | html("'/>\n"); | 446 | html("'/>\n"); |
444 | } | 447 | } |
445 | html("</head>\n"); | 448 | html("</head>\n"); |
446 | html("<body>\n"); | 449 | html("<body>\n"); |
447 | } | 450 | } |
448 | 451 | ||
449 | void cgit_print_docend() | 452 | void cgit_print_docend() |
450 | { | 453 | { |
451 | html("</div>"); | 454 | html("</div>"); |
452 | if (ctx.cfg.footer) | 455 | if (ctx.cfg.footer) |
453 | html_include(ctx.cfg.footer); | 456 | html_include(ctx.cfg.footer); |
454 | else { | 457 | else { |
455 | html("<div class='footer'>generated "); | 458 | html("<div class='footer'>generated "); |
456 | cgit_print_date(time(NULL), FMT_LONGDATE); | 459 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
457 | htmlf(" by cgit %s", cgit_version); | 460 | htmlf(" by cgit %s", cgit_version); |
458 | html("</div>\n"); | 461 | html("</div>\n"); |
459 | } | 462 | } |
460 | html("</body>\n</html>\n"); | 463 | html("</body>\n</html>\n"); |
461 | } | 464 | } |
462 | 465 | ||
463 | int print_branch_option(const char *refname, const unsigned char *sha1, | 466 | int print_branch_option(const char *refname, const unsigned char *sha1, |
464 | int flags, void *cb_data) | 467 | int flags, void *cb_data) |
465 | { | 468 | { |
466 | char *name = (char *)refname; | 469 | char *name = (char *)refname; |
467 | html_option(name, name, ctx.qry.head); | 470 | html_option(name, name, ctx.qry.head); |
468 | return 0; | 471 | return 0; |
469 | } | 472 | } |
470 | 473 | ||
471 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 474 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
472 | int flags, void *cb_data) | 475 | int flags, void *cb_data) |
473 | { | 476 | { |
474 | struct tag *tag; | 477 | struct tag *tag; |
475 | struct taginfo *info; | 478 | struct taginfo *info; |
476 | struct object *obj; | 479 | struct object *obj; |
477 | char buf[256], *url; | 480 | char buf[256], *url; |
478 | unsigned char fileid[20]; | 481 | unsigned char fileid[20]; |
479 | int *header = (int *)cb_data; | 482 | int *header = (int *)cb_data; |
480 | 483 | ||