Networker

Re: [Networker] Help with calculating time value?

2004-10-18 12:07:45
Subject: Re: [Networker] Help with calculating time value?
From: Darren Dunham <ddunham AT TAOS DOT COM>
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Date: Mon, 18 Oct 2004 09:24:44 -0700
>
> I want to write a Perl script that will use mminfo to query the database
> to determine saveset information for savesets that have completed since
> 4 PM yesterday, unless it's Monday, in which case the script goes back
> to 4 PM previous Friday. I would like to use number of seconds since
> 1970 (UTC value or epoch?) rather than MM/DD/YY format since this seems
> easier to manipulate.
>
> I was thinking if I can determine what 4 PM today will be in this UTC or
> EPOCH value then I can determine what 4 PM yesterday was by subtracting
> 60*60*24 seconds or when calculating 4 PM last Friday, 3*60*60*24.
> Problem is that UTC is the default time for some users but others use
> EDT or EST depending on whether it's daylight savings or not

Earlier when you say you want 'completed since 4pm', is that 4pm local
time, possibly including daylight saving time?

> something like 'date' when run by one user would show 16:00 for 4 PM EDT
> but it would show 20:00 for UTC and then when we go off day light
> savings time the UTC user will see 21:00 while the EST user will still
> see 16:00. If this script runs as a user using UTC then seems easiest
> enough to use something like:

Why are you converting to UTC if you want the answer to be based in
local time?

>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime;
> $gmtime_4pm_today = timegm(0,0,20,$mday,$mon,$year,$wday,$yday,$isdst);
>
> if ($wday == 1) # Today is Mon.
> {
>    $gmt_4pm_friday = $gmt_4pm_today - (3*24*60*60);
> }
> else # Today is Tue-Fri.
> {
>    $gmt_4pm_yesterday = $gmt_4pm_today - (24*60*60);
> }
>
> *BUT* once we go off day light savings, the hour value will be 21 for 4
> PM, not 20. I mean, if I run date then it will say 21:00 at 4 PM, not 20
> like it does now. Alternatively, if I use localtime, then I can use 16
> for hour but this will not produce correct value if run by user whose
> localtime is UTC. How do I get around this problem for any user?

Do you want to see 4:00pm completion in a particular timezone (say
wherever the master server is located), or do you want to see it 4:00pm
based on the timezone of the user running the program?

If it's relative to the user, you shouldn't care that the timezone might
be UTC (or something else).  Just use localtime or the networker
savetime routines and be done with it, right?

If it's relative to the server, just set the timezone in the script
prior to running throught the time routines.

--
Darren Dunham                                           ddunham AT taos DOT com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

--
Note: To sign off this list, send a "signoff networker" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

<Prev in Thread] Current Thread [Next in Thread>