From: Kevin Cernekee Date: Thu, 24 Mar 2011 05:23:18 GMT Subject: Re: [PATCH 1/1] gitweb: javascript ability to adjust time based on timezone Message-ID: In-Reply-To: <1300925335-3212-2-git-send-email-warthog9@eaglescrag.net> On Wed, Mar 23, 2011 at 5:08 PM, John 'Warthog9' Hawley wrote: > 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 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 --- 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)) . - " [$ad{'rfc2822'}"; + " [$ad{'rfc2822'}"; print_local_time(%ad) if ($opts{-localtime}); print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1) . "\n"; @@ -4040,7 +4041,7 @@ sub git_print_authorship_rows { git_get_avatar($co->{"${who}_email"}, -size => 'double') . "\n" . "" . - " $wd{'rfc2822'}"; + " $wd{'rfc2822'}"; print_local_time(%wd); print "" . "\n"; @@ -5454,7 +5455,7 @@ sub git_summary { "owner" . esc_html($owner) . "\n"; if (defined $cd{'rfc2822'}) { print "last change\n"; - print "$cd{'rfc2822'}\n"; + print "$cd{'rfc2822'}\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 +"
\n"; - for ( x = 0; x < classesFound.length; x++){ - curElement = classesFound[x]; - txtClassesFound += "
\n"+ x +" - "+ curElement.nodeName +" - "+ curElement.title +" - "+ curElement.innerHTML +"
\n"; - var strExtra = " +" - curElement.innerHTML = curElement.innerHTML + strExtra; - } + var txtClassesFound = ""; + var classesFound = findElementsByClassName( "dtcommit" ); + txtClassesFound += "Length: "+ classesFound.length +"
\n"; + for ( x = 0; x < classesFound.length; x++){ + curElement = classesFound[x]; + txtClassesFound += "
\n"+ x +" - "+ curElement.nodeName +" - "+ curElement.title +" - "+ curElement.innerHTML +"
\n"; + var strExtra = " +" + 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