Networker

[Networker] Help with calculating time value?

2004-10-15 16:50:46
Subject: [Networker] Help with calculating time value?
From: George Sinclair <George.Sinclair AT NOAA DOT GOV>
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Date: Fri, 15 Oct 2004 16:52:34 -0400
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, so
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:

($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 I have to know which user is running this script? So, if it's a user
that always uses EST or EDT then just set to 16; otherwise, make it 20
or 21 depending?

If yesterday or last Friday was daylight savings time and today isn't or
vice versa can I still follow the above script logic to determine time
in seconds since 1970 for 4 pm yesterday or 3 days ago, or will I need
to do something else?

Thanks.

George

--
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>