Normally, the meaningful information is *run length* of a program. Using that information, you can predict the end time of a program given it's start time. (The average amount of time elapsed since epoch is not very useful.)

Your problem definition is so vague, it's very hard to understand what you want. For starters, what are $time1, $time2 and $time3? Am I correct in the following restatment of your problem:

You have a series program that runs sequentially every night. You wish to know at what time the second program in the series is likely to start on a particular night.

(Update: The silent update to the OP confirms this. )

If so, the calculation is:

my $day1_prog1_start = Date_to_Time(2007, 8, 8, 17, 0, 0); my $day1_prog2_start = Date_to_Time(2007, 8, 8, 23, 0, 0); my $day2_prog1_start = Date_to_Time(2007, 8, 9, 17, 0, 0); my $day2_prog2_start = Date_to_Time(2007, 8, 10, 3, 0, 0); my $day3_prog1_start = Date_to_Time(2007, 8, 10, 17, 0, 0); my $day3_prog2_start = Date_to_Time(2007, 8, 11, 1, 0, 0); my $day1_prog1_len = $day1_prog2_start - $day1_prog1_start; my $day2_prog1_len = $day2_prog2_start - $day2_prog1_start; my $day3_prog1_len = $day3_prog2_start - $day3_prog1_start; my $avg_prog1_len = $day1_prog1_len / 3 + $day2_prog1_len / 3 + $day3_prog1_len / 3; print("Prog2 usually starts $avg_prog1_len seconds after Prog1 start.\ +n"); my ($year, $mon, $day) = Today(1); my ($hour, $min, $sec) = (Gmtime($day1_prog1_start))[3,4,5]; my $next_prog1_start = Date_to_Time($year,$mon,$day,$hour,$min,$sec); my $next_prog2_start = $next_prog1_start + $avg_prog1_len; my $next_prog1_start_str = strftime('%Y/%m/%d %H:%M:%S', gmtime($next_prog1_start)); my $next_prog2_start_str = strftime('%Y/%m/%d %H:%M:%S', gmtime($next_prog2_start)); print("If Prog1 starts at $next_prog1_start_str,\n"); print("Prog2 will likely start at $next_prog2_start_str.\n");
Prog2 usually starts 10800 seconds after Prog1 start. If Prog1 starts at 2007/08/09 22:00:00, Prog2 will likely start at 2007/08/10 01:00:00.

Arrays and loops can and should be used, of course.

Update: Added example times and resulting output.


In reply to Re: Getting avg start time by ikegami
in thread Getting avg start time by Earindil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.