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

Re: [PATCH 1/1] gitweb: javascript ability to adjust time based on timezone

From
Kevin Cernekee <cernekee@gmail.com>
Date
Mar 24, 2011, 05:23 UTC
Message-ID
<AANLkTincAcVQQtH+T9+K7tyBd0P5S=8YxXpsfrQ=68gE@mail.gmail.com>
In-Reply-To
<1300925335-3212-2-git-send-email-warthog9@eaglescrag.net>

On Wed, Mar 23, 2011 at 5:08 PM, John 'Warthog9' Hawley <warthog9@eaglescrag.net> wrote:

Show 5 quoted lines
> This patch takes the same basic goal, display the appropriate times
> in a given timezone, and implements it in Javascript.  This requires
> adding / using a new class, dtcommit, which is based on the
> dtstart/dtend microformats.  Appropriate commit dates are wrapped in
> a span with this class, and a title of the time in ISO8601 format.
John,

Thanks for coding this up. I tested it on a couple of different browsers and wanted to share my observations with you.

First, the easy stuff:
1) "git am" complains about whitespace violations
2) HH:MM:SS times need zero padding; otherwise you see:
Tue, 8 Mar 2011 20:29:9 -0700
3) Some of the Javascript functions are double-indented, others single-indented.
4) IE6 does not seem to like ISO 8601 format:
x = new Date("2011-03-09T03:29:09Z");

This sets all fields to NaN. I suspect that getTime() values (milliseconds since 1970-01-01) are more portable.

I have attached a trivial patch for these four items; it applies on top of your original submission.

Some other things that popped up:
5) Some timezone offsets are not a whole number of hours.  Bangalore
time is GMT +0530, for instance.
6) Most U.S. timezones honor daylight savings, so they could be
something like -0700 for part of the year, and -0800 for the rest of
the year.  Picking the "local" option would automatically adjust for
this, but DST limits the usefulness of permanently storing a fixed TZ
offset in the cookie.
7) Looking at a pre-DST commit after DST (or vice versa) can be a
little confusing:
Tue, 8 Mar 2011 20:29:09 -0700 + (19:29 -0800)

I'm not sure which time to believe. (Although it's likely that a few weeks after a commit, the exact hour doesn't matter.)

8) The " + " popup menu is a little quirky.  On FF 3.6 it partially
collapses after selecting a value from the dropdown.  On IE6 it shows
"Error in parsing value for 'display'" and does not render.  On Opera
11 it seemed to work OK.
Firefox breakage: http://img217.imageshack.us/f/firefoxa.png/

I'm wondering if there might be a better place on the page to put the TZ selection. It isn't immediately obvious to the user what the extra " + " does, and it seems to cause some issues.

If you decide to keep it where it is, you might want to consider absolute or fixed positioning so that other elements do not wrap around it. IOW it would work more like the dropdown menus on many sites.

The timezone fixup javascript seemed to work reasonably well, except for the hiccup with IE6. Maybe it would be worth splitting this into two patches: one to rewrite the timestamps, and a second one to add the TZ selection interface.

From fe8d5ba1d3922cd368691d47bb5f605b9e2bed58 Mon Sep 17 00:00:00 2001
From: Kevin Cernekee <cernekee@gmail.com>
Date: Wed, 23 Mar 2011 22:00:31 -0700
Subject: [PATCH] gitweb: minor fixups to javascript localtime feature
Fix whitespace, indentation, HH:MM:SS zero padding, IE6 compatibility.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 gitweb/gitweb.perl       |   11 ++++---
 gitweb/static/js/date.js |   63 +++++++++++++++++++++++++--------------------
 2 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index dfceaf6..1d5e970 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -262,9 +262,9 @@ our %highlight_ext = (
 );
 
 
-# Enable / Disable the ability for gitweb to use a small amount of 
+# Enable / Disable the ability for gitweb to use a small amount of
 # javascript, along with a javascript cookie, to display commit
-# times in the preffered timezone.  Time zones can be pre-set 
+# times in the preferred timezone.  Time zones can be pre-set
 # by specifying it in $jslocaltime with one of the following:
 #
 #	utc
@@ -2956,6 +2956,7 @@ sub parse_date {
 	                     $mday, $months[$mon], $hour ,$min;
 	$date{'iso-8601'}  = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
 	                     1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
+	$date{'getTime'}   = $epoch * 1000;
 
 	$tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
 	my $local = $epoch + ((int $1 + ($2/60)) * 3600);
@@ -4013,7 +4014,7 @@ sub git_print_authorship {
 	my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
 	print "<$tag class=\"author_date\">" .
 	      format_search_author($author, "author", esc_html($author)) .
-	      " [<span class=\"dtcommit\" title=\"$ad{'iso-8601'}\">$ad{'rfc2822'}</span>";
+	      " [<span class=\"dtcommit\" title=\"$ad{'getTime'}\">$ad{'rfc2822'}</span>";
 	print_local_time(%ad) if ($opts{-localtime});
 	print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
 		  . "</$tag>\n";
@@ -4040,7 +4041,7 @@ sub git_print_authorship_rows {
 		      git_get_avatar($co->{"${who}_email"}, -size => 'double') .
 		      "</td></tr>\n" .
 		      "<tr>" .
-		      "<td></td><td> <span class=\"dtcommit\" title=\"$wd{'iso-8601'}\">$wd{'rfc2822'}</span>";
+		      "<td></td><td> <span class=\"dtcommit\" title=\"$wd{'getTime'}\">$wd{'rfc2822'}</span>";
 		print_local_time(%wd);
 		print "</td>" .
 		      "</tr>\n";
@@ -5454,7 +5455,7 @@ sub git_summary {
 	      "<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>\n";
-		print "<td><span class=\"dtcommit\" title=\"$cd{'iso-8601'}\">$cd{'rfc2822'}</span></td></tr>\n";
+		print "<td><span class=\"dtcommit\" title=\"$cd{'getTime'}\">$cd{'rfc2822'}</span></td></tr>\n";
 	}
 
 	# use per project git URL list in $projectroot/$project/cloneurl
diff --git a/gitweb/static/js/date.js b/gitweb/static/js/date.js
index a6d6f81..1728bda 100644
--- a/gitweb/static/js/date.js
+++ b/gitweb/static/js/date.js
@@ -12,15 +12,15 @@ function onloadTZSetup(){
 }
 
 function addChangeTZ() {
-		var txtClassesFound = "";
-		var classesFound = findElementsByClassName( "dtcommit" );
-		txtClassesFound += "Length: "+ classesFound.length +"<br>\n";
-		for ( x = 0; x < classesFound.length; x++){
-			curElement = classesFound[x];
-			txtClassesFound += "<br>\n"+ x +" - "+ curElement.nodeName  +" - "+ curElement.title +" - "+ curElement.innerHTML +"<br>\n";
-			var strExtra = " <span onclick=\"clickDate(event.target);\" title=\"+\">+</span>"
-			curElement.innerHTML = curElement.innerHTML + strExtra;
-		}
+	var txtClassesFound = "";
+	var classesFound = findElementsByClassName( "dtcommit" );
+	txtClassesFound += "Length: "+ classesFound.length +"<br>\n";
+	for ( x = 0; x < classesFound.length; x++){
+		curElement = classesFound[x];
+		txtClassesFound += "<br>\n"+ x +" - "+ curElement.nodeName  +" - "+ curElement.title +" - "+ curElement.innerHTML +"<br>\n";
+		var strExtra = " <span onclick=\"clickDate(event.target);\" title=\"+\">+</span>"
+		curElement.innerHTML = curElement.innerHTML + strExtra;
+	}
 }
 
 function checkTZCookie(){
@@ -35,18 +35,26 @@ function checkTZCookie(){
 }
 
 function formatTZ( tzOffset ) {
-		var posNeg = "+";
-		if( tzOffset < 0 ){
-			posNeg = "-";
-		}
-		tzOffset = Math.sqrt( Math.pow( tzOffset, 2 ) );
-		if( tzOffset < 100 ){
-			tzOffset = tzOffset * 100;
-		}
-		for( y = tzOffset.toString().length + 1; y <= 4; y++ ){
-			tzOffset = "0"+ tzOffset;
-		}
-		return posNeg + tzOffset;
+	var posNeg = "+";
+	if( tzOffset < 0 ){
+		posNeg = "-";
+	}
+	tzOffset = Math.sqrt( Math.pow( tzOffset, 2 ) );
+	if( tzOffset < 100 ){
+		tzOffset = tzOffset * 100;
+	}
+	for( y = tzOffset.toString().length + 1; y <= 4; y++ ){
+		tzOffset = "0"+ tzOffset;
+	}
+	return posNeg + tzOffset;
+}
+
+function padTime( val ) {
+	if( val < 10 ){
+		return "0" + val.toString();
+	} else {
+		return val.toString();
+	}
 }
 
 function dateOutput( objDate ) {
@@ -62,7 +70,7 @@ function dateOutputTZ( objDate, tzOffset ) {
 		tzOffset = 0;
 	}else if( tzOffset == "local" ){
 		var tempDate = new Date();
-		tzOffset = tempDate.getTimezoneOffset() * -1 / 60 * 100; 
+		tzOffset = tempDate.getTimezoneOffset() * -1 / 60 * 100;
 		tzOffset = formatTZ( tzOffset );
 	}
 
@@ -76,9 +84,9 @@ function dateOutputTZ( objDate, tzOffset ) {
 	strDate += toDateTime.getUTCDate() +" ";
 	strDate += monthsOfYr[ toDateTime.getUTCMonth() ] +" ";
 	strDate += toDateTime.getUTCFullYear() +" ";
-	strDate += toDateTime.getUTCHours() +":";
-	strDate += toDateTime.getUTCMinutes() +":";
-	strDate += toDateTime.getUTCSeconds() +" ";
+	strDate += padTime(toDateTime.getUTCHours()) +":";
+	strDate += padTime(toDateTime.getUTCMinutes()) +":";
+	strDate += padTime(toDateTime.getUTCSeconds()) +" ";
 
 	strDate += tzOffset;
 
@@ -98,7 +106,7 @@ function tzChangeSNS( tzOffset, set ){
 	var classesFound = findElementsByClassName( "dtcommit" );
 	for ( x = 0; x < classesFound.length; x++){
 		curElement = classesFound[x];
-		var origDateTime = new Date( curElement.title );
+		var origDateTime = new Date( parseInt(curElement.title) );
 		curElement.innerHTML = dateOutputTZ(origDateTime, tzOffset);
 	}
 	var tzExpDate = new Date();
@@ -114,7 +122,7 @@ function clickDate( clkEvent ) {
 		clkEvent.title="-";
 
 		var preSetTZ = getCookie( getwebCookieTZOffset );
-		
+
 		var arrSelected = new Array();
 		var offsetArr = 14;
 		arrSelected[0] = " ";
@@ -157,4 +165,3 @@ function clickDate( clkEvent ) {
 		clkEvent.parentNode.innerHTML = "+";
 	}
 }
-
-- 
1.7.4.1
Previous: John 'Warthog9' HawleyNext: J.H.
Message 19 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.