time calculation
dolavoie
created: 2006-02-03 14:30:07
Hi, I need to add the following minutes: 01:45 60:00 45:25 How should I do this ? I am currently turning the minutes in seconds but I seem to be loosing some minutes
Re: time calculation
created: 2006-02-03 14:48:41
What have you tried sofar?

Converting to seconds seems like a sensible approach. You could do it like this:

   use List::Util qw/ sum /;

   # calculate total number of seconds
   $seconds = sum map {
         my ($m,$s) = split /:/;
         $m*60 + $s
     }
     qw/ 01:45 60:00 45:25 /;     # or your array with times

   $minutes = int($seconds / 60); # integral number of minutes
   $seconds = $seconds % 60;      # remaining seconds

   $new_time = sprintf "%02d:%02d", $minutes, $seconds;
Re: time calculation
created: 2006-02-03 22:39:57
perl -e '($sec, $min)=localtime time; printf "%.2d:%.2d", $min, $sec'
or
perl -e '$,=":";print reverse @ms=(localtime)[0, 1];'
Re: time calculation
created: 2006-02-04 00:54:41
Is "01:45" one minute and 45 seconds, or one hour and 45 minutes? I wonder because "60:00", if it were minutes and seconds, should probably have been "1:00:00".

Apart from that, the next time you post a question like this, show us some code that you have tried. If all you give us is "I am currently losing some minutes", all we can say is "well, where were they when you last saw them? Have you checked all your pockets?"

(For that matter, if you're still having trouble with this problem, you can post some code so we can help you look for those missing minutes.)

Re: time calculation
created: 2006-02-04 13:08:20
Sounds like homework... Well than put your a* on a comfortable chair and try out...

perlmonks.org content © perlmonks.org and Anonymous Monk, dolavoie, graff, rhesa, smokemachine

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03