Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting avg start time

by grep (Monsignor)
on Aug 09, 2007 at 16:02 UTC ( #631603=note: print w/ replies, xml ) Need Help??


in reply to Getting avg start time

Get the time - but set the date to the same date every time to get a comparison.

Remember you want to compare times not dates and times so yoiu need to take the date out of the equation.

#!/bin/perl ## UNTESTED use strict; use warnings; use Date::Calc qw(Date_to_Time); use POSIX; my $time1 = Date_to_Time(2007,1,1,23,00,0); my $time2 = Date_to_Time(2007,1,1,03,00,0); my $time3 = Date_to_Time(2007,1,1,01,00,0); print "$time1\t$time2\t$time3\n"; my $avg = sprintf "%0.0f", (($time1+$time2+$time3)/3); print "$avg\n"; print strftime "%H:%M:%S\n", gmtime($avg);

Comment on Re: Getting avg start time
Download Code
Re^2: Getting avg start time
by Earindil (Beadle) on Aug 09, 2007 at 16:15 UTC
    That was actually my first attempt, but it doesn't work.
    $time1 = Date_to_Time(2007,1,1,23,00,0); $time2 = Date_to_Time(2007,1,1,03,00,0); $time3 = Date_to_Time(2007,1,1,01,00,0);
    1167692400      1167620400      1167613200
    1167642000
    09:00:00
    
    Actually came up with a way to do this, but, would love to hear other/better suggestions. All of my jobs start at 5pm. So, what I can do is check and see if the start time of a particular job is < 5pm. If so, I know it started the next day, then I would do this:
    $time = Date_to_Time(2007,1,2,02,00,0);
    If it is after 5pm, then it's the same day so:
    $time = Date_to_Time(2007,1,1,23,00,0);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://631603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-02 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (31 votes), past polls