[rrd-users] Re: Different timezones

Owen DeLong owen at dixon.delong.sj.ca.us
Wed Jan 24 10:48:41 CET 2007


Tobi,
	That's a completely accurate and relatively useuless answer.

	The problem comes in how do you KNOW what to set the TZ to if
you are running a web server.  The only mechanism I've found is to use
Javascript.  Currently, I'm using the following code in one of my non-
rrd pages to deal with times displayed in a table:

In the <HEAD> portion of the document:

<SCRIPT>
function showDate(what,gmsecs) {
        var days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
        var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
        var gmMsecs=gmsecs*1000;
        var myDate=new Date(gmMsecs);
 
        var myDow = days[myDate.getDay()];
        var myMon = months[myDate.getMonth()];
        var myDay = myDate.getDate();
        var myYear = myDate.getFullYear();

        var myHour = myDate.getHours();
        var myMin = myDate.getMinutes();
        var mySec = myDate.getSeconds();

        if (myDay < 10)
        {
                myDay=" "+myDay;
        }

        if (myHour < 10)
        {
                myHour="0"+myHour;
        }

        if (myMin < 10)
        {
                myMin="0"+myMin;
        }

        if (mySec < 10)
        {
                mySec="0"+mySec;
        }

        var myString = myDow+" "+myMon+" "+myDay+" "+myYear+" ";
        myString = myString+" "+myHour+":"+myMin+":"+mySec;

        what.document.open();
        what.document.write(myString);
        what.document.close();
}

function setOffset(where) {
	var myDate = new Date();
	where.document.submission.offset=myDate.getTimezoneOffset()*60;
	window.status="Initialization Complete.";

}
</HEAD>

Then, I use:
<BODY onLoad="setOffset(this)">

Then, in the body, where dates/times need to appear, I use a construct
like:
<SCRIPT>showDate(this, nnnnnnn)</SCRIPT>
<NOSCRIPT>UTC TIME SPELLED OUT</NOSCRIPT>

And, in a <FORM name=submission> block, there's a <INPUT TYPE=hidden name=offset>.

nnnnnnn is replaced with a time_t value (seconds since epoch UTC)
UTC TIME SPELLED OUT is replaced with a date/time string.

There are a couple of problems with this solution:

	1.	DST is not well accounted for in the offset returned
		to the browser.  For the most part, this isn't a factor
		in the application I developed this code for.  This only
		affects dates/times supplied by the user in the form
		being translated by the CGI.  Dates/times supplied
		in the HTML via the showDate() function are correctly
		interpreted WRT DST where applicable (assuming the
		browsers JavaScript Date() object does the right thing).

	2.	If the browser doesn't support javascript, you're stuck
		with UTC.

If anyone has a better solution, I'd love to have it.  This is the
best I've been able to come up with.  For use with RRD, it should
be possible to take the technique I've used above (the onLoad
function specifically) and modify it to return the TZ variable
to the CGI script.  You could even rig it so that if there was
no TZ for variable, a form was sent back with all of the fields
hidden which would submit itself and include the offset or
TZ name (also available from the Date() object (sort of).

Owen

> 
> Yesterday you sent me mail regarding [rrd-users] Different timezones:
> 
> *> Hi all,
> *>    I have a question on data coming from different 
> *> timezones.  What would be the easiest way to get the
> *> times on the graphs to be the remotes time and not the
> *> time on the machine doing the graphing??
> 
> set the TZ environemnt variable apropriately before generating the graph ...
> 
> cheers
> tobi
> *> 
> *> thanks
> *> jdt
> *> 
> *> --
> *> Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
> *> Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
> *> Archive     http://www.ee.ethz.ch/~slist/rrd-users
> *> 
> 
> -- 
>  ______    __   _
> /_  __/_  / /  (_) Oetiker, Timelord & SysMgr @ EE-Dept ETH-Zurich
>  / // _ \/ _ \/ / TEL: +41(0)1-6325286  FAX:...1517  ICQ: 10419518 
> /_/ \.__/_.__/_/ oetiker at ee.ethz.ch http://ee-staff.ethz.ch/~oetiker
> 
> --
> Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
> Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
> Archive     http://www.ee.ethz.ch/~slist/rrd-users
> 
> 


--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users



More information about the rrd-users mailing list