YADTR (Yet Another DateTime Rant)

Skip Montanaro skip at pobox.com
Thu Mar 27 07:56:34 EDT 2014


I took a moment to scan the datetime documentation. The behavior of
str() on timedelta objects is very consistent, and matches the
internal representation. From the docs:

str(t) Returns a string in the form [D day[s], ][H]H:MM:SS[.UUUUUU],
where D is negative for negative t. (5)

Note (5) reads: String representations of timedelta objects are
normalized similarly to their internal representation. This leads to
somewhat unusual results for negative timedeltas.

Feel free to submit a patch to improve str(t), where t is negative,
though as Chris suggested, hashing this out on python-ideas would be a
good idea. I suggest you start with some concrete examples. There are,
as I see it, two common cases where t is negative:

  -1 day < t < 0

and

  t <= -1 day

Skip



More information about the Python-list mailing list