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

[PATCH (BUGFIX)] gitweb: Fix parsing of negative fractional timezones in JavaScript

From
Jakub Narebski <jnareb@gmail.com>
Date
Apr 1, 2011, 19:06 UTC
Message-ID
<20110401190239.9686.12000.stgit@localhost.localdomain>

Extract converting numerical timezone in the form of '(+|-)HHMM' to timezoneOffset function, and fix parsing of negative fractional timezones.

This is used to format timestamps in 'blame_incremental' view; this complements commit 2b1e172 (gitweb: Fix handling of fractional timezones in parse_date, 2011-03-25).

Now
  gitweb.cgi/git.git/blame_incremental/3fe5489:/contrib/gitview/gitview#l853
and
  gitweb.cgi/git.git/blame/3fe5489:/contrib/gitview/gitview#l853

show the same correct time in author's local timezone in title (on mouseover) [Aneesh Kumar K.V, 2006-02-24 00:59:42 +0530].

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This was send earlier as part 3/3 of 
  "[PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript"
  Message-Id: <1301089586-8534-1-git-send-email-jnareb@gmail.com>
  http://thread.gmane.org/gmane.comp.version-control.git/170021/focus=170024

It is now send separately as standalone patch, and is not held hostage to accepting series that splits gitweb JavaScript file.

 gitweb/static/gitweb.js |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gitweb/static/gitweb.js b/gitweb/static/gitweb.js
index 9c66928..40ec084 100644
--- a/gitweb/static/gitweb.js
+++ b/gitweb/static/gitweb.js
@@ -399,7 +399,24 @@ function fixColorsAndGroups() {
  * used to extract hours and minutes from timezone info, e.g '-0900'
  * @constant
  */
-var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
+var tzRe = /^([+-])([0-9][0-9])([0-9][0-9])$/;
+
+/**
+ * convert numeric timezone +/-ZZZZ to offset from UTC in seconds
+ *
+ * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
+ * @returns {Number} offset from UTC in seconds for timezone
+ *
+ * @globals tzRe
+ */
+function timezoneOffset(timezoneInfo) {
+	var match = tzRe.exec(timezoneInfo);
+	var tz_sign = (match[1] === '-' ? -1 : +1);
+	var tz_hour = parseInt(match[2],10);
+	var tz_min  = parseInt(match[3],10);
+
+	return tz_sign*(((tz_hour*60) + tz_min)*60);
+}
 
 /**
  * return date in local time formatted in iso-8601 like format
@@ -408,14 +425,11 @@ var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
  * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
  * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
  * @returns {String} date in local time in iso-8601 like format
- *
- * @globals tzRe
  */
 function formatDateISOLocal(epoch, timezoneInfo) {
-	var match = tzRe.exec(timezoneInfo);
 	// date corrected by timezone
 	var localDate = new Date(1000 * (epoch +
-		(parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
+		timezoneOffset(timezoneInfo)));
 	var localDateStr = // e.g. '2005-08-07'
 		localDate.getUTCFullYear()                 + '-' +
 		padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +
Next: J.H.
Message 1 of 2 in “gitweb: Fix parsing of negative fractional timezones in JavaScript”
  1. gitweb: Fix parsing of negative fractional timezones in JavaScriptJakub Narebski, Apr 1, 2011
  2. J.H.Apr 4, 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.