-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gitweb: JavaScript ability to adjust time based on timezone
This patch is based on Kevin Cernekee's <cernekee@gmail.com> patch series entitled "gitweb: introduce localtime feature". While Kevin's patch changed the server side output so that the timezone was output from gitweb itself, this has a number of drawbacks, in particular with respect to gitweb-caching. This patch takes the same basic goal, display the appropriate times in a given common timezone, and implements it in JavaScript. This requires adding / using a new class, "datetime", to be able to find elements to be adjusted from JavaScript. Appropriate dates are wrapped in a span with this class. Timezone to be used can be retrieved from "gitweb_tz" cookie, though currently there is no way to set / manipulate this cookie from gitweb; this is left for later commit. Valid timezones, currently, are: "utc", "local" (which means that timezone is taken from browser), and "+/-ZZZZ" numeric timezone as in RFC-2822. Default timezone is "local" (currently not configurable, left for later commit). Fallback (should JavaScript not be enabled) is to treat dates as they have been and display them, only, in UTC. Pages affected: * 'summary' view, "last change" field (commit time from latest change) * 'log' view, author time * 'commit' and 'commitdiff' views, author/committer time * 'tag' view, tagger time Based-on-code-from: Kevin Cernekee <cernekee@gmail.com> Signed-off-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
John 'Warthog9' Hawley
authored and
Junio C Hamano
committed
May 24, 2011
1 parent
ce71b07
commit 291e52b
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2011, John 'Warthog9' Hawley <warthog9@eaglescrag.net> | ||
// 2011, Jakub Narebski <jnareb@gmail.com> | ||
|
||
/** | ||
* @fileOverview Manipulate dates in gitweb output, adjusting timezone | ||
* @license GPLv2 or later | ||
*/ | ||
|
||
/** | ||
* Get common timezone and adjust dates to use this common timezone. | ||
* | ||
* This function is called during onload event (added to window.onload). | ||
* | ||
* @param {String} tzDefault: default timezone, if there is no cookie | ||
* @param {String} tzCookieName: name of cookie to store timezone | ||
* @param {String} tzClassName: denotes elements with date to be adjusted | ||
*/ | ||
function onloadTZSetup(tzDefault, tzCookieName, tzClassName) { | ||
var tzCookie = getCookie(tzCookieName); | ||
var tz = tzCookie ? tzCookie : tzDefault; | ||
|
||
// server-side of gitweb produces datetime in UTC, | ||
// so if tz is 'utc' there is no need for changes | ||
if (tz !== 'utc') { | ||
fixDatetimeTZ(tz, tzClassName); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Replace RFC-2822 dates contained in SPAN elements with tzClassName | ||
* CSS class with equivalent dates in given timezone. | ||
* | ||
* @param {String} tz: numeric timezone in '(-|+)HHMM' format, or 'utc', or 'local' | ||
* @param {String} tzClassName: specifies elements to be changed | ||
*/ | ||
function fixDatetimeTZ(tz, tzClassName) { | ||
// sanity check, method should be ensured by common-lib.js | ||
if (!document.getElementsByClassName) { | ||
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++) { | ||
var curElement = classesFound[i]; | ||
|
||
// we use *.firstChild.data (W3C DOM) instead of *.innerHTML | ||
// as the latter doesn't always work everywhere in every browser | ||
var epoch = parseRFC2822Date(curElement.firstChild.data); | ||
var adjusted = formatDateRFC2882(epoch, tz); | ||
|
||
curElement.firstChild.data = adjusted; | ||
} | ||
} | ||
|
||
/* end of adjust-timezone.js */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters