in reply to Getting avg start time
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.
|
|---|