Skip to content

Commit 9029ebb

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix parsing of negative fractional timezones in JavaScript
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8e84886 commit 9029ebb

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gitweb/static/gitweb.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,24 @@ function fixColorsAndGroups() {
399399
* used to extract hours and minutes from timezone info, e.g '-0900'
400400
* @constant
401401
*/
402-
var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
402+
var tzRe = /^([+-])([0-9][0-9])([0-9][0-9])$/;
403+
404+
/**
405+
* convert numeric timezone +/-ZZZZ to offset from UTC in seconds
406+
*
407+
* @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
408+
* @returns {Number} offset from UTC in seconds for timezone
409+
*
410+
* @globals tzRe
411+
*/
412+
function timezoneOffset(timezoneInfo) {
413+
var match = tzRe.exec(timezoneInfo);
414+
var tz_sign = (match[1] === '-' ? -1 : +1);
415+
var tz_hour = parseInt(match[2],10);
416+
var tz_min = parseInt(match[3],10);
417+
418+
return tz_sign*(((tz_hour*60) + tz_min)*60);
419+
}
403420

404421
/**
405422
* 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])$/;
408425
* @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
409426
* @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
410427
* @returns {String} date in local time in iso-8601 like format
411-
*
412-
* @globals tzRe
413428
*/
414429
function formatDateISOLocal(epoch, timezoneInfo) {
415-
var match = tzRe.exec(timezoneInfo);
416430
// date corrected by timezone
417431
var localDate = new Date(1000 * (epoch +
418-
(parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
432+
timezoneOffset(timezoneInfo)));
419433
var localDateStr = // e.g. '2005-08-07'
420434
localDate.getUTCFullYear() + '-' +
421435
padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +

0 commit comments

Comments
 (0)