git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 2/2] gitweb: introduce localtime feature

From
Kevin Cernekee <cernekee@gmail.com>
Date
Mar 19, 2011, 05:39 UTC
Message-ID
<dab08d0ff27b0f571a17ed4f1ab0f39b@localhost>
In-Reply-To
<ab54ba2199cc7487e383a31e3aa65885@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)

Local times between 00:00 and 05:59, inclusive, will still be printed in red ("atnight" style) in these views.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   87 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 65 insertions(+), 22 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 57ef08c..b3b7f3f 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,48 @@ 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 an RFC 2822 timestamp string, which may contain HTML.
+# If $use_localtime is 0, don't do anything special.
+# If $use_localtime is 1, add an alternate HH:MM timestamp in parentheses at
+# the end.  If $feature{'localtime'} is enabled this looks like:
+#   Thu, 17 Mar 2011 18:28:57 -0700 (01:28 +0000)
+# Otherwise, it looks like:
+#   Fri, 18 Mar 2011 01:28:57 +0000 (18:28 -0700)
+# If $use_localtime is 1, this will also apply the "atnight" style to
+# local times between 00:00 and 05:59.
+sub timestamp_html {
+	my %date = %{$_[0]};
+	my $use_localtime = $_[1];
+	my $timestamp;
+	my $alt_time;
+
+	if (gitweb_check_feature('localtime')) {
+		$timestamp = $date{'rfc2822_local'};
+		if ($use_localtime && $date{'hour_local'} < 6) {
+			$timestamp = "<span class=\"atnight\">" .
+			             $timestamp .
+			             "</span>";
+		}
+		$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'});
+		if ($use_localtime && $date{'hour_local'} < 6) {
+			$alt_time = "<span class=\"atnight\">" .
+			            $alt_time .
+			            "</span>";
+		}
 	}
 
-	return $localtime;
+	if ($use_localtime) {
+		$timestamp .= $alt_time;
+	}
+
+	return $timestamp;
 }
 
 # Outputs the author name and date in long form
@@ -3956,10 +3999,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 +4025,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 +5437,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
Previous: Kevin CernekeeNext: Jakub Narebski
Message 2 of 36 in “gitweb: rename parse_date() to format_date()”
  1. 1/2 gitweb: rename parse_date() to format_date()Kevin Cernekee, Mar 19, 2011
  2. 2/2 gitweb: introduce localtime featureKevin Cernekee, Mar 19, 2011
  3. Jakub NarebskiMar 19, 2011
  4. Junio C HamanoMar 19, 2011
  5. Kevin CernekeeMar 19, 2011
  6. Jakub NarebskiMar 19, 2011
  7. Kevin CernekeeMar 19, 2011
  8. Jakub NarebskiMar 19, 2011
  9. J.H.Mar 20, 2011
  10. Kevin CernekeeMar 20, 2011
  11. Jakub NarebskiMar 21, 2011
  12. J.H.Mar 21, 2011
  13. Jakub NarebskiMar 21, 2011
  14. Piotr KrukowieckiMar 21, 2011
  15. J.H.Mar 21, 2011
  16. Jakub NarebskiMar 21, 2011
  17. 0/1 Gitweb: Change timezoneJohn 'Warthog9' Hawley, Mar 24, 2011
  18. 1/1 gitweb: javascript ability to adjust time based on timezoneJohn 'Warthog9' Hawley, Mar 24, 2011
  19. Kevin CernekeeMar 24, 2011
  20. J.H.Mar 24, 2011
  21. Jakub NarebskiMar 24, 2011
  22. Jakub NarebskiMar 24, 2011
  23. Kevin CernekeeMar 24, 2011
  24. J.H.Mar 24, 2011
  25. J.H.Mar 24, 2011
  26. Jakub NarebskiMar 24, 2011
  27. Jakub NarebskiMar 24, 2011
  28. gitweb: Fix handling of fractional timezones in parse_dateJakub Narebski, Mar 25, 2011
  29. Kevin CernekeeMar 25, 2011
  30. gitweb: Fix handling of fractional timezones in parse_dateJakub Narebski, Mar 25, 2011
  31. Junio C HamanoMar 25, 2011
  32. Jakub NarebskiMar 25, 2011
  33. gitweb: Fix handling of fractional timezones in parse_dateJakub Narebski, Mar 25, 2011
  34. Jakub NarebskiMar 19, 2011
  35. Jon SeymourMar 19, 2011
  36. Junio C HamanoMar 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.