]> Lady’s Gitweb - Gitweb/blob - static/js/adjust-timezone.js
5b80fa6818a2a3ac27a5ec503a427b984e1e34eb7fbfb123a8dad077148175fc
[Gitweb] / static / js / adjust-timezone.js
1 // Copyright (C) 2011, John 'Warthog9' Hawley <warthog9@eaglescrag.net>
2 // 2011, Jakub Narebski <jnareb@gmail.com>
3
4 /**
5 * @fileOverview Manipulate dates in gitweb output, adjusting timezone
6 * @license GPLv2 or later
7 */
8
9 /**
10 * Get common timezone and adjust dates to use this common timezone.
11 *
12 * This function is called during onload event (added to window.onload).
13 *
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
17 */
18 function onloadTZSetup(tzDefault, tzCookieName, tzClassName) {
19 var tzCookie = getCookie(tzCookieName);
20 var tz = tzCookie ? tzCookie : tzDefault;
21
22 // server-side of gitweb produces datetime in UTC,
23 // so if tz is 'utc' there is no need for changes
24 if (tz !== 'utc') {
25 fixDatetimeTZ(tz, tzClassName);
26 }
27 }
28
29
30 /**
31 * Replace RFC-2822 dates contained in SPAN elements with tzClassName
32 * CSS class with equivalent dates in given timezone.
33 *
34 * @param {String} tz: numeric timezone in '(-|+)HHMM' format, or 'utc', or 'local'
35 * @param {String} tzClassName: specifies elements to be changed
36 */
37 function fixDatetimeTZ(tz, tzClassName) {
38 // sanity check, method should be ensured by common-lib.js
39 if (!document.getElementsByClassName) {
40 return;
41 }
42
43 // translate to timezone in '(-|+)HHMM' format
44 tz = normalizeTimezoneInfo(tz);
45
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];
50
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);
55
56 curElement.firstChild.data = adjusted;
57 }
58 }
59
60 /* end of adjust-timezone.js */
This page took 0.375279 seconds and 3 git commands to generate.