Message75882
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)
> |
|
Date |
User |
Action |
Args |
2008-11-14 18:35:54 | belopolsky | set | recipients:
+ belopolsky, jribbens, amaury.forgeotdarc, vstinner, webograph |
2008-11-14 18:35:53 | belopolsky | link | issue2706 messages |
2008-11-14 18:35:53 | belopolsky | create | |
|