1 // Copyright (C) 2011, John 'Warthog9' Hawley <warthog9@eaglescrag.net>
2 // 2011, Jakub Narebski <jnareb@gmail.com>
5 * @fileOverview Manipulate dates in gitweb output, adjusting timezone
6 * @license GPLv2 or later
10 * Get common timezone and adjust dates to use this common timezone.
12 * This function is called during onload event (added to window.onload).
14 * @param {String} tzDefault: default timezone, if there is no cookie
15 * @param {String} tzCookieName: name of cookie to store timezone
16 * @param {String} tzClassName: denotes elements with date to be adjusted
18 function onloadTZSetup(tzDefault, tzCookieName, tzClassName) {
19 var tzCookie = getCookie(tzCookieName);
20 var tz = tzCookie ? tzCookie : tzDefault;
22 // server-side of gitweb produces datetime in UTC,
23 // so if tz is 'utc' there is no need for changes
25 fixDatetimeTZ(tz, tzClassName);
31 * Replace RFC-2822 dates contained in SPAN elements with tzClassName
32 * CSS class with equivalent dates in given timezone.
34 * @param {String} tz: numeric timezone in '(-|+)HHMM' format, or 'utc', or 'local'
35 * @param {String} tzClassName: specifies elements to be changed
37 function fixDatetimeTZ(tz, tzClassName) {
38 // sanity check, method should be ensured by common-lib.js
39 if (!document.getElementsByClassName) {
43 // translate to timezone in '(-|+)HHMM' format
44 tz = normalizeTimezoneInfo(tz);
46 // NOTE: result of getElementsByClassName should probably be cached
47 var classesFound = document.getElementsByClassName(tzClassName, "span");
48 for (var i = 0, len = classesFound.length; i < len; i++) {
49 var curElement = classesFound[i];
51 // we use *.firstChild.data (W3C DOM) instead of *.innerHTML
52 // as the latter doesn't always work everywhere in every browser
53 var epoch = parseRFC2822Date(curElement.firstChild.data);
54 var adjusted = formatDateRFC2882(epoch, tz);
56 curElement.firstChild.data = adjusted;
60 /* end of adjust-timezone.js */