From: Kevin Cernekee <cernekee@gmail.com>
To: Junio C Hamano <gitster@pobox.com>, Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH v5 2/3] gitweb: introduce localtime feature
Date: Sat, 19 Mar 2011 13:48:26 -0700 [thread overview]
Message-ID: <d0b137d3ad11b997ed0964354bd9017a@localhost> (raw)
In-Reply-To: <4f21902cf5f72b30a96465cf911d13aa@localhost>
With this feature enabled, all timestamps are shown in the local
timezone instead of GMT. The timezone is taken from the appropriate
timezone string stored in the commit object.
This improves usability if the majority of a project's contributors are
based in a single office, all within the same timezone. It also makes
the interface more friendly to non-developers who may need to track
updates, such as program managers and supervisors.
This change does not affect relative timestamps (e.g. "5 hours ago"),
nor does it affect 'patch' and 'patches' views which already use
localtime because they are generated by "git format-patch".
Affected views include:
* 'summary' view, "last change" field (commit time from latest change)
* 'log' view, author time
* 'commit' and 'commitdiff' views, author/committer time
* 'tag' view, tagger time
In the case of 'commit', 'commitdiff' and 'tag' views, gitweb used to
print both GMT time and time in timezone of author/tagger/committer:
Fri, 18 Mar 2011 01:28:57 +0000 (18:28 -0700)
With localtime enabled, the times will be swapped:
Thu, 17 Mar 2011 18:28:57 -0700 (01:28 +0000)
When the local time is between 00:00 and 05:59, inclusive, the entire
date string will be printed in red ("atnight" style) on the commit and
commitdiff views. This is a change from the current behavior, in which
only the parenthesized time/tz is colored red. This simplifies the
code, and makes the special coloring easier to notice.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
v5: Change "$use_localtime" to "$commit_view" for clarity. Apply
"atnight" style to the entire timestamp string, not just the
" (hh:mm -zzzz)" portion. Update commit message to reflect the
latter change.
gitweb/gitweb.perl | 84 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 61 insertions(+), 23 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 57ef08c..aa038bd 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -504,6 +504,19 @@ our %feature = (
'sub' => sub { feature_bool('remote_heads', @_) },
'override' => 0,
'default' => [0]},
+
+ # Use the author/commit localtime rather than GMT for all timestamps.
+ # Disabled by default.
+
+ # To enable system wide have in $GITWEB_CONFIG
+ # $feature{'localtime'}{'default'} = [1];
+ # To have project specific config enable override in $GITWEB_CONFIG
+ # $feature{'localtime'}{'override'} = 1;
+ # and in project config gitweb.localtime = 0|1;
+ 'localtime' => {
+ 'sub' => sub { feature_bool('localtime', @_) },
+ 'override' => 0,
+ 'default' => [0]},
);
sub gitweb_get_feature {
@@ -2919,6 +2932,10 @@ sub format_date {
$date{'hour_local'} = $hour;
$date{'minute_local'} = $min;
$date{'tz_local'} = $tz;
+ $date{'rfc2822_local'} = sprintf "%s, %d %s %4d %02d:%02d:%02d $tz",
+ $days[$wday], $mday, $months[$mon],
+ 1900+$year, $hour ,$min, $sec;
+
$date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1900+$year, $mon+1, $mday,
$hour, $min, $sec, $tz);
@@ -3928,22 +3945,43 @@ sub git_print_section {
print $cgi->end_div;
}
-sub print_local_time {
- print format_local_time(@_);
-}
-
-sub format_local_time {
- my $localtime = '';
- my %date = @_;
- if ($date{'hour_local'} < 6) {
- $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
- $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
+# Returns a timestamp string, which may contain HTML.
+# If $commit_view is 0, the string looks like:
+# Fri, 18 Mar 2011 01:28:57 +0000 [localtime disabled]
+# Thu, 17 Mar 2011 18:28:57 -0700 [localtime enabled]
+# If $commit_view is 1, the string looks like:
+# Fri, 18 Mar 2011 01:28:57 +0000 (18:28 -0700) [localtime disabled]
+# Thu, 17 Mar 2011 18:28:57 -0700 (01:28 +0000) [localtime enabled]
+# If $commit_view is 1, the entire string will use the "atnight" class
+# (red text) if the local time is between 00:00 and 05:59 inclusive.
+# This helps to flag commits made in the wee hours of the morning.
+sub timestamp_html {
+ my ($date, $commit_view) = @_;
+ my $timestamp;
+ my $alt_time;
+
+ if (gitweb_check_feature('localtime')) {
+ $timestamp = $date->{'rfc2822_local'};
+ $alt_time = sprintf(" (%02d:%02d %s)",
+ $date->{'hour'},
+ $date->{'minute'},
+ "+0000");
} else {
- $localtime .= sprintf(" (%02d:%02d %s)",
- $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
+ $timestamp = $date->{'rfc2822'};
+ $alt_time = sprintf(" (%02d:%02d %s)",
+ $date->{'hour_local'},
+ $date->{'minute_local'},
+ $date->{'tz_local'});
}
-
- return $localtime;
+ if ($commit_view) {
+ $timestamp .= $alt_time;
+ if ($date->{'hour_local'} < 6) {
+ $timestamp = "<span class=\"atnight\">" .
+ $timestamp .
+ "</span>";
+ }
+ }
+ return $timestamp;
}
# Outputs the author name and date in long form
@@ -3956,10 +3994,9 @@ sub git_print_authorship {
my %ad = format_date($co->{'author_epoch'}, $co->{'author_tz'});
print "<$tag class=\"author_date\">" .
format_search_author($author, "author", esc_html($author)) .
- " [$ad{'rfc2822'}";
- print_local_time(%ad) if ($opts{-localtime});
- print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
- . "</$tag>\n";
+ " [" . timestamp_html(\%ad, 0) . "] ".
+ git_get_avatar($co->{'author_email'}, -pad_before => 1) .
+ "</$tag>\n";
}
# Outputs table rows containing the full author or committer information,
@@ -3983,9 +4020,9 @@ sub git_print_authorship_rows {
git_get_avatar($co->{"${who}_email"}, -size => 'double') .
"</td></tr>\n" .
"<tr>" .
- "<td></td><td> $wd{'rfc2822'}";
- print_local_time(%wd);
- print "</td>" .
+ "<td></td><td> " .
+ timestamp_html(\%wd, 1) .
+ "</td>" .
"</tr>\n";
}
}
@@ -5395,8 +5432,9 @@ sub git_summary {
print "<table class=\"projects_list\">\n" .
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
- if (defined $cd{'rfc2822'}) {
- print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+ if (keys %cd) {
+ print "<tr id=\"metadata_lchange\"><td>last change</td><td>" .
+ timestamp_html(\%cd, 0) . "</td></tr>\n";
}
# use per project git URL list in $projectroot/$project/cloneurl
--
1.7.4.1
next prev parent reply other threads:[~2011-03-19 20:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-19 20:48 [PATCH v2 1/3] gitweb: rename parse_date() to format_date() Kevin Cernekee
2011-03-19 20:48 ` Kevin Cernekee [this message]
2011-03-19 20:48 ` [PATCH/RFC 3/3] gitweb: change highlighting of "atnight" commits Kevin Cernekee
2011-03-19 22:18 ` [PATCH -1/3] gitweb: Always call parse_date with timezone parameter Jakub Narebski
2011-03-19 22:53 ` [PATCH -1/3 (amend)] " Jakub Narebski
2011-03-19 22:56 ` [PATCH -1/3] " Kevin Cernekee
2011-03-20 0:25 ` Jakub Narebski
2011-03-20 0:27 ` Junio C Hamano
2011-03-20 2:11 ` [PATCH v2 4/3] gitweb: Always call format_date " Kevin Cernekee
2011-03-20 10:37 ` Jakub Narebski
2011-03-20 11:07 ` Jakub Narebski
2011-03-20 20:47 ` Kevin Cernekee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d0b137d3ad11b997ed0964354bd9017a@localhost \
--to=cernekee@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).