@matheusbsbs / matheus-bagliano / commits / 9029ebbe11
Fork 0

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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Apr 1, 2011 at 21:06 UTC 9029ebbe118dddfccae0dcbb921722257aef2ecd
1 file changed +19 -5
gitweb/static/gitweb.js
+19 -5
@@ -399,7 +399,24 @@ function fixColorsAndGroups() {
399 * used to extract hours and minutes from timezone info, e.g '-0900'
400 * @constant
401 */
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 +}
420
421 /**
422 * 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])$/;
425 * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
426 * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
427 * @returns {String} date in local time in iso-8601 like format
411 - *
412 - * @globals tzRe
428 */
429 function formatDateISOLocal(epoch, timezoneInfo) {
415 - var match = tzRe.exec(timezoneInfo);
430 // date corrected by timezone
431 var localDate = new Date(1000 * (epoch +
418 - (parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
432 + timezoneOffset(timezoneInfo)));
433 var localDateStr = // e.g. '2005-08-07'
434 localDate.getUTCFullYear() + '-' +
435 padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +