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 */ 18functiononloadTZSetup(tzDefault, tzCookieName, tzClassName) { 19var tzCookie =getCookie(tzCookieName); 20var 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 24if(tz !=='utc') { 25fixDatetimeTZ(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 */ 37functionfixDatetimeTZ(tz, tzClassName) { 38// sanity check, method should be ensured by common-lib.js 39if(!document.getElementsByClassName) { 40return; 41} 42 43// translate to timezone in '(-|+)HHMM' format 44 tz =normalizeTimezoneInfo(tz); 45 46// NOTE: result of getElementsByClassName should probably be cached 47var classesFound = document.getElementsByClassName(tzClassName,"span"); 48for(var i =0, len = classesFound.length; i < len; i++) { 49var 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 53var epoch =parseRFC2822Date(curElement.firstChild.data); 54var adjusted =formatDateRFC2882(epoch, tz); 55 56 curElement.firstChild.data = adjusted; 57} 58} 59 60/* end of adjust-timezone.js */