From 9f2d9717c69127564d4aad9a9e7910ff2e439c8b Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 14 Jun 2015 00:54:07 -0700 Subject: [PATCH] gitweb: handle local DST properly When the user selects the 'local' time zone for displaying dates in gitweb, the actual time zone offset may vary depending on whether or not DST is in effect for the actual date being used. Handle this properly by calling getTimezoneOffset on the actual date being displayed rather than the current date. Signed-off-by: Kyle J. McKay --- gitweb/static/js/adjust-timezone.js | 3 --- gitweb/static/js/lib/datetime.js | 14 +++++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gitweb/static/js/adjust-timezone.js b/gitweb/static/js/adjust-timezone.js index 0c67779500..cc32df3734 100644 --- a/gitweb/static/js/adjust-timezone.js +++ b/gitweb/static/js/adjust-timezone.js @@ -57,9 +57,6 @@ function fixDatetimeTZ(tz, tzClassName, nochange) { return; } - // translate to timezone in '(-|+)HHMM' format - tz = normalizeTimezoneInfo(tz); - // NOTE: result of getElementsByClassName should probably be cached var classesFound = document.getElementsByClassName(tzClassName, "span"); for (var i = 0, len = classesFound.length; i < len; i++) { diff --git a/gitweb/static/js/lib/datetime.js b/gitweb/static/js/lib/datetime.js index f78c60a912..b77c77c9b2 100644 --- a/gitweb/static/js/lib/datetime.js +++ b/gitweb/static/js/lib/datetime.js @@ -48,10 +48,11 @@ function localTimezoneOffset() { /** * return local (browser) timezone as numeric timezone '(+|-)HHMM' * - * @returns {String} locat timezone as -/+ZZZZ + * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC' + * @returns {String} local timezone as -/+ZZZZ */ -function localTimezoneInfo() { - var tzOffsetMinutes = (new Date()).getTimezoneOffset() * -1; +function localTimezoneInfo(epoch) { + var tzOffsetMinutes = (new Date(1000 * epoch)).getTimezoneOffset() * -1; return formatTimezoneInfo(0, tzOffsetMinutes); } @@ -107,13 +108,14 @@ function formatTimezoneInfo(hours, minutes, sep) { /** * translate 'utc' and 'local' to numerical timezone * @param {String} timezoneInfo: might be 'utc' or 'local' (browser) + * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC' */ -function normalizeTimezoneInfo(timezoneInfo) { +function normalizeTimezoneInfo(timezoneInfo, epoch) { switch (timezoneInfo) { case 'utc': return '+0000'; case 'local': // 'local' is browser timezone - return localTimezoneInfo(); + return localTimezoneInfo(epoch); } return timezoneInfo; } @@ -157,6 +159,8 @@ function formatDateRFC2882(epoch, timezoneInfo, padDay) { var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; // A textual representation of a day, three letters var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + // translate to timezone in '(-|+)HHMM' format + timezoneInfo = normalizeTimezoneInfo(timezoneInfo, epoch); // date corrected by timezone var localDate = new Date(1000 * (epoch + timezoneOffset(timezoneInfo))); -- 2.11.4.GIT