Author belopolsky
Recipients amaury.forgeotdarc, belopolsky, jribbens, vstinner, webograph
Date 2008-11-14.18:35:53
SpamBayes Score 1.66782e-06
Marked as misclassified No
Message-id <d38f5330811141035g14d54942ied933c737b057138@mail.gmail.com>
In-reply-to <1226685090.07.0.981211056922.issue2706@psf.upfronthosting.co.za>
Content
While I agree that divmod may be useful, your particular use case is
not convincing. The same can be done easier without divmod:

def formatTimedelta(delta):
   return "{0}h {1}min {2}sec".format(*str(delta).split(':'))

or you can convert delta to time using an arbitrary anchor date and
extract hms that way:

(1, 24, 19)

(depending on your needs you may want to add delta.days*24 to the hours)

On Fri, Nov 14, 2008 at 12:51 PM, STINNER Victor <report@bugs.python.org> wrote:
>
> STINNER Victor <victor.stinner@haypocalc.com> added the comment:
>
> Why not also implementing divmod()? It's useful to split a timedelta
> into, for example, (hours, minutes, seconds):
>
> def formatTimedelta(delta):
>    """
>    >>> formatTimedelta(timedelta(hours=1, minutes=24, seconds=19))
>    '1h 24min 19sec'
>    """
>    hours, minutes = divmodTimedelta(delta, timedelta(hours=1))
>    minutes, seconds = divmodTimedelta(minutes, timedelta(minutes=1))
>    seconds, fraction = divmodTimedelta(seconds, timedelta(seconds=1))
>    return "{0}h {1}min {2}sec".format(hours, minutes, seconds)
>
History
Date User Action Args
2008-11-14 18:35:54belopolskysetrecipients: + belopolsky, jribbens, amaury.forgeotdarc, vstinner, webograph
2008-11-14 18:35:53belopolskylinkissue2706 messages
2008-11-14 18:35:53belopolskycreate