Message75892
> def formatTimedelta(delta):
> return "{0}h {1}min {2}sec".format(*str(delta).split(':'))
OMG, this is ugly! Conversion to string and reparse the formatted text :-/
Your code doesn't work with different units than hours, minutes or seconds:
['4 days, 1', '32', '01']
>>> str(timedelta(hours=1, minutes=32, seconds=1, microseconds=2)).split(":")
['1', '32', '01.000002']
> or you can convert delta to time using an arbitrary anchor date
> and extract hms that way:
How? I don't understand your suggestion.
> (depending on your needs you may want to add delta.days*24 to the hours)
The goal of the new operators (timedelta / timedelta, divmod(timedelta,
timedelta), etc.) is to avoid the use of the timedelta "internals" (days,
seconds and microseconds attributes) and give a new "natural" way to process
time deltas. |
|
Date |
User |
Action |
Args |
2008-11-14 21:59:44 | vstinner | set | recipients:
+ vstinner, jribbens, amaury.forgeotdarc, belopolsky, webograph |
2008-11-14 21:59:43 | vstinner | link | issue2706 messages |
2008-11-14 21:59:42 | vstinner | create | |
|