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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2011, 17:56 UTC
Message-ID
<7v39mjro38.fsf@alter.siamese.dyndns.org>
In-Reply-To
<dab08d0ff27b0f571a17ed4f1ab0f39b@localhost>
Kevin Cernekee <cernekee@gmail.com> writes:
Show 6 quoted lines
> -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'});
Looks like we used to only paint HH:MM part but... 
Show 37 quoted lines
> +# 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>";
> +		}

... we now paint the whole line, which I personally think is a friendly move for color challenged people (me included---a larger span of text painted in different colors tends to help you still notice it better using value/brightness difference, even if your hue perception is weaker than other people). But it is a change from the old behaviour and might be worth stating in the log message.

> -	return $localtime;
> +	if ($use_localtime) {
> +		$timestamp .= $alt_time;
> +	}

You kept -localtime nobody uses? If you dig the history, you would notice that it is merely a remnant of f88bafa (gitweb: uniform author info for commit and commitdiff, 2009-06-30) that forgot to remove the feature while removing the last callsite, and I don't think anybody even was against such a change.

I'd suggest to remove $alt_time codepath from this function. Nobody will notice.

Show 17 quoted lines
>  # 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) . "] ".
> ...
>  # Outputs table rows containing the full author or committer information,
> @@ -3983,9 +4025,9 @@ sub git_print_authorship_rows {
> -		print "</td>" .
> +		      "<td></td><td> " .
> +		      timestamp_html(\%wd, 1) .
> +		      "</td>" .

While I don't agree with Jakub about the presense / absence of "[]" around it (that is not a part of "timestamp", but is how the caller wants to prepare the space to plug a timestamp string in), I do agree that the second parameter "use-localtime" looks funny, not because it is an unnamed parameter (which I personally think is fine) but because it isn't about the localness of the displayed time anymore. Your 'localtime' feature alone controls in which timezone the timestamp is shown, and this only controls the use of 'atnight' highlighting. The parameter needs to be renamed, and perhaps you may clarify it further by making it a keyword argument as Jakub suggests.

Other than that, I think this round is very nicely done.

This is a complete tangent, but I wonder if it makes sense to keep the output from print_authorship plain (no atnight markings) while painting the output from print_authorship_rows.

I would understand it if the design _were_ to paint late-nite commits differently when we list multiple commits in a row (e.g. summary view) to make them easier to stand out (for amusement purposes), and not to paint the timestamp when we show only one commit to avoid distraction. But that doesn't seem to be the case.

Previous: Jakub NarebskiNext: Kevin Cernekee
Message 4 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.