From: Jakub Narebski Date: Sat, 09 Apr 2011 22:49:26 GMT Subject: [PATCH/RFC 11/11] gitweb: Make JavaScript ability to adjust timezones configurable Message-ID: <1302389366-21515-12-git-send-email-jnareb@gmail.com> In-Reply-To: <1302389366-21515-1-git-send-email-jnareb@gmail.com> Configure JavaScript-based ability to select common timezone for git dates via %feature mechanism, namely 'javascript-timezone' feature. The following settings are configurable: * default timezone (defaults to 'local' i.e. browser timezone); this also can function as a way to disable this ability, by setting it to false-ish value (undef or '') * name of cookie to store user's choice of timezone * class name to mark dates NOTE: This is a bit of abuse of %feature system, which can store only sequence of values, rather than dictionary (hash); usually but not always only a single value is used. Based-on-code-by: John 'Warthog9' Hawley Signed-off-by: Jakub Narebski --- Original patch by J.H. had strictly speaking only $jslocaltime (default timezone) configurable, though cookie name was stored in global variable (set in gitweb/static/js/common-defs.js). But do we really need full flexibility...? gitweb/gitweb.perl | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6651946..b80f2e0 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -480,6 +480,18 @@ our %feature = ( 'override' => 0, 'default' => [0]}, + # Enable and configure ability to change common timezone for dates + # in gitweb output via JavaScript. Enabled by default. + # Project specific override is not supported. + 'javascript-timezone' => { + 'override' => 0, + 'default' => [ + 'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format, + # or undef to turn off this feature + 'gitweb_tz', # name of cookie where to store selected timezone + 'datetime', # CSS class used to mark up dates for manipulation + ]}, + # Syntax highlighting support. This is based on Daniel Svensson's # and Sham Chukoury's work in gitweb-xmms2.git. # It requires the 'highlight' program present in $PATH, @@ -3733,13 +3745,18 @@ sub git_footer_html { qq! "!. href() .qq!");\n!. qq!\n!; } else { + my ($jstimezone, $tz_cookie, $datetime_class) = + gitweb_get_feature('javascript-timezone'); + print qq!\n!; } @@ -3945,7 +3962,13 @@ sub git_print_section { sub format_timestamp_html { my $date = shift; - my $strtime = ''.$date->{'rfc2822'}.''; + my $strtime = $date->{'rfc2822'}; + + my (undef, undef, $datetime_class) = + gitweb_get_feature('javascript-timezone'); + if ($datetime_class) { + $strtime = qq!$strtime!; + } my $localtime_format = '(%02d:%02d %s)'; if ($date->{'hour_local'} < 6) { -- 1.7.3