robertw has asked for the wisdom of the Perl Monks concerning the following question:
Dear wise perlmonks, I am getting desperate with this subroutine I am writing: It takes an array containing hours minutes seconds, then it compares the current time to that time and calculates how long it still takes in seconds till that time has arrived. Unfortunately I have not been able to calculate hours correctly because that keeps being wrong and my brain has melted away:(. Or does anyone know a module that could do this for me? Cheers and thank you very much:) Rob
sub timeleft { $hour = (localtime(time))[2]; $minutes = (localtime(time))[1]; $seconds = (localtime(time))[0]; #print "$minutes"; print " Time now is $hour:$minutes:$seconds "; print "Time remaining until $_[0]:$_[1]:$_[2] = "; if ($_[2] == $seconds) {$seconds = 0} if ($_[2] > $seconds) {$seconds = $_[2] - $seconds;} #correct if ($_[2] < $seconds) {$seconds = (60- $seconds) + $_[2]; #correct $spareminute = 1;} #minuteklopt $minutes -= $spareminute; #print "$minutes"; if ($_ [1] == $minutes ) {$minutes = 0; } if ($_ [1] > $minutes ) {$minutes = $_[1] - $minutes; } #correct if ($_ [1] < $minutes ) {$minutes = (60 - $minutes) + $_[1]; #correct $sparehour + 1; } $minuteprint = $minutes; $minutes *= 60; $hour -= $sparehour; if ($_[0] == $hour) {$hour =0;} if ($_[0] > $hour) {$hour =$_[0] - $hour;} if ($_[0] < $hour) {$hour = (24 - $hour) + $_[0] ;} $hourprint = $hour; $hour *= 60; $hour *= 60; print "$hourprint: $minuteprint: $seconds "; $baas = $hour + $minute + $seconds; #$baas = ($hour * 60 * 60) + ($minutes * 60) + $seconds; return $baas }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Timeleft subroutine
by kennethk (Abbot) on Aug 29, 2012 at 19:42 UTC | |
|
Re: Timeleft subroutine
by philiprbrenan (Monk) on Aug 29, 2012 at 19:50 UTC | |
|
Re: Timeleft subroutine
by dasgar (Priest) on Aug 29, 2012 at 20:34 UTC | |
by robertw (Sexton) on Aug 29, 2012 at 20:45 UTC | |
by BillKSmith (Monsignor) on Aug 30, 2012 at 03:59 UTC | |
|
Re: Timeleft subroutine
by Kenosis (Priest) on Aug 29, 2012 at 21:10 UTC | |
|
Re: Timeleft subroutine
by Marshall (Canon) on Aug 30, 2012 at 13:01 UTC |