Skip to content

Commit 2e987f9

Browse files
jnarebgitster
authored andcommitted
gitweb: Make JavaScript ability to adjust timezones configurable
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 <[email protected]> Helped-by: Kevin Cernekee <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ae8da2 commit 2e987f9

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

gitweb/gitweb.perl

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ sub evaluate_uri {
480480
'override' => 0,
481481
'default' => [0]},
482482

483+
# Enable and configure ability to change common timezone for dates
484+
# in gitweb output via JavaScript. Enabled by default.
485+
# Project specific override is not supported.
486+
'javascript-timezone' => {
487+
'override' => 0,
488+
'default' => [
489+
'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
490+
# or undef to turn off this feature
491+
'gitweb_tz', # name of cookie where to store selected timezone
492+
'datetime', # CSS class used to mark up dates for manipulation
493+
]},
494+
483495
# Syntax highlighting support. This is based on Daniel Svensson's
484496
# and Sham Chukoury's work in gitweb-xmms2.git.
485497
# It requires the 'highlight' program present in $PATH,
@@ -3733,14 +3745,19 @@ sub git_footer_html {
37333745
qq! "!. href() .qq!");\n!.
37343746
qq!</script>\n!;
37353747
} else {
3748+
my ($jstimezone, $tz_cookie, $datetime_class) =
3749+
gitweb_get_feature('javascript-timezone');
3750+
37363751
print qq!<script type="text/javascript">\n!.
3737-
qq!window.onload = function () {\n!.
3738-
(gitweb_check_feature('javascript-actions') ?
3739-
qq! fixLinks();\n! : '').
3740-
# last parameter to onloadTZSetup must be CSS class used by format_timestamp_html
3741-
qq! var tz_cookie = { name: 'gitweb_tz', expires: 14, path: '/' };\n!. # in days
3742-
qq! onloadTZSetup('local', tz_cookie, 'datetime');\n!.
3743-
qq!};\n!.
3752+
qq!window.onload = function () {\n!;
3753+
if (gitweb_check_feature('javascript-actions')) {
3754+
print qq! fixLinks();\n!;
3755+
}
3756+
if ($jstimezone && $tz_cookie && $datetime_class) {
3757+
print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
3758+
qq! onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
3759+
}
3760+
print qq!};\n!.
37443761
qq!</script>\n!;
37453762
}
37463763

@@ -3946,7 +3963,13 @@ sub git_print_section {
39463963

39473964
sub format_timestamp_html {
39483965
my $date = shift;
3949-
my $strtime = '<span class="datetime">'.$date->{'rfc2822'}.'</span>';
3966+
my $strtime = $date->{'rfc2822'};
3967+
3968+
my (undef, undef, $datetime_class) =
3969+
gitweb_get_feature('javascript-timezone');
3970+
if ($datetime_class) {
3971+
$strtime = qq!<span class="$datetime_class">$strtime</span>!;
3972+
}
39503973

39513974
my $localtime_format = '(%02d:%02d %s)';
39523975
if ($date->{'hour_local'} < 6) {

0 commit comments

Comments
 (0)