[issue2706] datetime: define division timedelta/timedelta
STINNER Victor
report at bugs.python.org
Fri Nov 14 22:59:44 CET 2008
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> 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.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2706>
_______________________________________
More information about the Python-bugs-list
mailing list