[Python-Dev] Negative timedelta strings

Skip Montanaro skip at pobox.com
Fri Mar 28 17:19:52 CET 2014


On Fri, Mar 28, 2014 at 11:07 AM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
>> Is it open to debate or is it now cast in stone?
>
> I think the barrier for changing str() is lower than that for changing
> repr(), but I would be against any changes in this area.  (I may have had a
> different view if ISO 8601 syntax for timedeltas was not so ugly. :-)

I think str() should be left alone. It's clear there is no one best
str representation for timedelta objects. I think it might be
worthwhile to add a method which allows the programmer to format
timedelta objects in whatever way s/he sees fit. That would support
the ISO 8601 syntax (*), and anything else the programmer things is
better than the status quo.

Skip

(*) As an aside (that is, this belongs in a separate thread if you
want to discuss it), in my opinion, attempting to support ISO 8601
formatting is pointless without the presence of an anchor datetime.
Otherwise how would you know how far back "five months" or "seven
years" was? If that's the case, then you might as well add the
timedelta to your anchor datetime and just use datetime.strftime().


More information about the Python-Dev mailing list