From cecc7971d799a96ff39bc161a67b00261391ff30 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 5 Sep 2016 17:18:10 -0700 Subject: [PATCH] editproj.cgi: localize succeeded/failed timestamp If the browser supports JavaScript, use that to send the current local timezone offset back to editproj.cgi so it can format the timestamp in local time. If JavaScript is not available, the offset will continue to be "0" meaning the time will be displayed as UTC. This makes reading the returned timestamp so much more pleasant. Signed-off-by: Kyle J. McKay --- cgi/editproj.cgi | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/cgi/editproj.cgi b/cgi/editproj.cgi index 0468d7e..ed559b1 100755 --- a/cgi/editproj.cgi +++ b/cgi/editproj.cgi @@ -57,11 +57,32 @@ if (!$proj) { my $escname = $name; $escname =~ s/[+]/%2B/g; +my $tzoffset = $cgi->param('tzoffset') || 0; +$tzoffset =~ /^[-+]?\d{1,5}$/ or $tzoffset = 0; +$tzoffset = 0 + $tzoffset; +$tzoffset >= -43200 && $tzoffset <= 43200 or $tzoffset = 0; + +sub format_epoch_ts { + my $es = shift; + defined($es) or $es = time(); + $es += $tzoffset; + my $str = strftime("%Y-%m-%d %H:%M:%S ", (gmtime($es))[0..5], -1, -1, -1); + if ($tzoffset) { + my $moff = int(abs($tzoffset) / 60); + $str .= sprintf("%s%02d%02d", + ($tzoffset >= 0 ? "+" : "-"), + int($moff / 60), + $moff - 60 * int($moff / 60)); + } else { + $str .= "UTC"; + } + return $str; +} + my $y0 = $cgi->param('y0') || ''; if (($y0 eq 'Update' || $y0 eq 'Restart Mirroring') && $cgi->request_method eq 'POST') { # submitted, let's see - my $utc = strftime('%Y-%m-%d %H:%M:%S UTC', (gmtime(time()))[0..5], -1, -1, -1); - my $ts = "$utc"; + my $ts = "" . format_epoch_ts() . ""; $gcgi->err_prelude("

Project update failed at $ts.

\n"); if ($proj->cgi_fill($gcgi) and $proj->authenticate($gcgi) and $proj->update) { print "

Project successfully updated at $ts.

\n"; @@ -112,6 +133,7 @@ my $statuschecked = $proj->{statusupdates} ? 'checked="checked"' : ''; print < +
Project name:$h{name}.git @@ -198,4 +220,15 @@ print <
+ EOT -- 2.11.4.GIT