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

[PATCH 13/13] gitweb: Make JavaScript ability to adjust timezones configurable

From
Jakub Narebski <jnareb@gmail.com>
Date
Apr 28, 2011, 19:04 UTC
Message-ID
<1304017451-12283-14-git-send-email-jnareb@gmail.com>
In-Reply-To
<1304017451-12283-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 <warthog9@eaglescrag.net>
Helped-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch is unchanged from v2 version (from previous version of
series).

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).

This patch uses standard %feature, and is a bit more configurable.
 gitweb/gitweb.perl |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b1e80ef..ac335b6 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,14 +3745,19 @@ sub git_footer_html {
 		      qq!           "!. href() .qq!");\n!.
 		      qq!</script>\n!;
 	} else {
+		my ($jstimezone, $tz_cookie, $datetime_class) =
+			gitweb_get_feature('javascript-timezone');
+
 		print qq!<script type="text/javascript">\n!.
-		      qq!window.onload = function () {\n!.
-		      (gitweb_check_feature('javascript-actions') ?
-		      qq!	fixLinks();\n! : '').
-		      # last parameter to onloadTZSetup must be CSS class used by format_timestamp_html
-		      qq!	var tz_cookie = { name: 'gitweb_tz', expires: 14, path: '/' };\n!. # in days
-		      qq!	onloadTZSetup('local', tz_cookie, 'datetime');\n!.
-		      qq!};\n!.
+		      qq!window.onload = function () {\n!;
+		if (gitweb_check_feature('javascript-actions')) {
+			print qq!	fixLinks();\n!;
+		}
+		if ($jstimezone && $tz_cookie && $datetime_class) {
+			print qq!	var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
+			      qq!	onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
+		}
+		print qq!};\n!.
 		      qq!</script>\n!;
 	}
 
@@ -3946,7 +3963,13 @@ sub git_print_section {
 
 sub format_timestamp_html {
 	my $date = shift;
-	my $strtime = '<span class="datetime">'.$date->{'rfc2822'}.'</span>';
+	my $strtime = $date->{'rfc2822'};
+
+	my (undef, undef, $datetime_class) =
+		gitweb_get_feature('javascript-timezone');
+	if ($datetime_class) {
+		$strtime = qq!<span class="$datetime_class">$strtime</span>!;
+	}
 
 	my $localtime_format = '(%02d:%02d %s)';
 	if ($date->{'hour_local'} < 6) {
-- 
1.7.3
Previous: Jakub Narebski
Message 14 of 14 in “[PATCHv3 00/13] gitweb: Change timezone in dates using JavaScript”
  1. Jakub NarebskiApr 28, 2011
  2. 01/13 git-instaweb: Simplify build dependency on gitwebJakub Narebski, Apr 28, 2011
  3. 02/13 Remove gitweb/gitweb.cgi and other legacy targets from main MakefileJakub Narebski, Apr 28, 2011
  4. 03/13 gitweb: Split JavaScript for maintability, combining on buildJakub Narebski, Apr 28, 2011
  5. 04/13 gitweb.js: Update and improve comments in JavaScript filesJakub Narebski, Apr 28, 2011
  6. 05/13 gitweb.js: Provide default values for padding in padLeftStr and padLeftJakub Narebski, Apr 28, 2011
  7. 06/13 gitweb.js: Extract and improve datetime handlingJakub Narebski, Apr 28, 2011
  8. 07/13 gitweb.js: Introduce code to handle cookies from JavaScriptJakub Narebski, Apr 28, 2011
  9. 08/13 gitweb.js: Provide getElementsByClassName method (if it not exists)Jakub Narebski, Apr 28, 2011
  10. 09/13 gitweb: Refactor generating of long dates into format_timestamp_htmlJakub Narebski, Apr 28, 2011
  11. 10/13 gitweb: Unify the way long timestamp is displayedJakub Narebski, Apr 28, 2011
  12. 11/13 gitweb: JavaScript ability to adjust time based on timezoneJakub Narebski, Apr 28, 2011
  13. 12/13 gitweb.js: Add UI for selecting common timezone to display datesJakub Narebski, Apr 28, 2011
  14. 13/13 gitweb: Make JavaScript ability to adjust timezones configurableJakub Narebski, Apr 28, 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.