All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@eaglescrag.net>,
	Kevin Cernekee <cernekee@gmail.com>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript
Date: Fri, 25 Mar 2011 22:46:26 +0100	[thread overview]
Message-ID: <1301089586-8534-4-git-send-email-jnareb@gmail.com> (raw)
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

  parent reply	other threads:[~2011-03-25 21:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 2/3] gitweb: Update and improve comments in JavaScript files Jakub Narebski
2011-03-25 21:46 ` Jakub Narebski [this message]
2011-03-25 22:03 ` [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript J.H.
2011-03-26 11:08   ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1301089586-8534-4-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=cernekee@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=warthog9@eaglescrag.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.