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

[PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 25, 2011, 21:46 UTC
Message-ID
<1301089586-8534-4-git-send-email-jnareb@gmail.com>
In-Reply-To
<1301089586-8534-1-git-send-email-jnareb@gmail.com>

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

This was used to format timestamps in 'blame_incremental' view.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/static/js/common-lib.js |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gitweb/static/js/common-lib.js b/gitweb/static/js/common-lib.js
index 33887d7..cc72d1e 100644
--- a/gitweb/static/js/common-lib.js
+++ b/gitweb/static/js/common-lib.js
@@ -87,7 +87,24 @@ function createRequestObject() {
  * 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
@@ -96,14 +113,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') + '-' +
-- 
1.7.3
Previous: Jakub NarebskiNext: J.H.
Message 4 of 6 in “gitweb: Split gitweb.js, improve JavaScript”
  1. 0/3 gitweb: Split gitweb.js, improve JavaScriptJakub Narebski, Mar 25, 2011
  2. 1/3 gitweb: Split JavaScript for maintability; concatenate on buildJakub Narebski, Mar 25, 2011
  3. 2/3 gitweb: Update and improve comments in JavaScript filesJakub Narebski, Mar 25, 2011
  4. 3/3 gitweb: Fix parsing of negative fractional timezones in JavaScriptJakub Narebski, Mar 25, 2011
  5. J.H.Mar 25, 2011
  6. Jakub NarebskiMar 26, 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.