# [Tutor] Re: time calc

Andrei project5 at redrival.net
Mon Jun 21 14:36:25 EDT 2004

```kevin parks wrote on Fri, 18 Jun 2004 13:36:10 -0400:

Hi,

<snip>
> What i want to do is append the duration to the end of this list by
> subtracting the start of the item from the start time of the next so
> that the first line would look like:
>
> 1    1    1    00:23    08:00
> 1    2    2    8:23      01:18
> So the task is really two part : reading in a list of numbers and
> adding one more piece of data and (2) doing time (base 60) math. It is
> the time math part i simply can't get my head around. Anyone know if
> there is a module that does time math? or a method for doing this by
> hand?

Here's a simple solution: convert the time to the base unit (I assume
that's minutes:seconds). This means that you take the part before the
colon, multiply with 60 and add it to the part at the right of the colon (a
split() combined with int() will do the trick). Then you calculate in
seconds whatever you like and convert it back to minutes.
Converting back is done using integer division, for example 92 seconds:

minutes = 92 // 60 # integer division
seconds = 92 % 60 # remainder
print "%s:%s" % (minutes, seconds)

gives:
1:32

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.

```