YADTR (Yet Another DateTime Rant)

Chris Angelico rosuav at gmail.com
Thu Mar 27 12:33:55 CET 2014


On Thu, Mar 27, 2014 at 10:05 PM, Johannes Bauer <dfnsonfsduifb at gmx.de> wrote:
> On 27.03.2014 11:44, Chris Angelico wrote:
>> On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer <dfnsonfsduifb at gmx.de> wrote:
>>> Besides, there's an infinite amount of (braindead) timedelta string
>>> representations. For your -30 hours, it is perfectly legal to say
>>>
>>> 123 days, -2982 hours
>>>
>>> Yet Python doesn't (but chooses an equally braindead representation).
>>
>> It's not "equally braindead", it follows a simple and logical rule:
>> Only the day portion is negative. That might not be perfectly suited
>> to all situations, but it does mean that adding and subtracting whole
>> days will never change the representation of the time. That's a
>> reasonable promise.
>
> Why would the stability of the *string* output of the time
> representation be of any interest whatsoever? Do you have any even
> halfways reasonable usecase for that?
>
>> What you propose is completely arbitrary,
>
> No. What I propose is that for t > 0 this holds:
>
> "-" + str(t) == str(-t)
>
> Which is far from arbitrary.

When you said "equally braindead", I took that as indicating that the
current representation is as braindead as "123 days, -2982 hours". My
point is that it's not as arbitrary as that. Your "real proposal", if
you like, is arguably better; but I'm just saying that the current one
isn't arbitrary.

> It follows "natural" rules of inverting
> something (-abs(x) == -x), and it yields a (truly) human-readable form
> of showing a timedelta.
>
> Please don't mix this up with the very apparent braindead proposal of
> mine. In case you didn't notice, this was irony at work. The word
> "braindead" I chose to describe the format should have tipped you off to
> that.

Yes, I knew that that was irony. I was taking argument with your
declaration that the current form is just as bad. Taking it to a
different type: The repr() of a string tries to be short, where
possible, by using either single or double quotes, but won't use a raw
representation, nor triple-quoted:

>>> ' \' '
" ' "
>>> " \" "
' " '
>>> ' \"\'\"\'\"\'\"\' '
' "\'"\'"\'"\' '
>>> " \"\'\"\'\"\'\"\' "
' "\'"\'"\'"\' '
>>> ''' "'"'"'"' '''
' "\'"\'"\'"\' '
>>> r' \\\\\\\\\\\\\\ '
' \\\\\\\\\\\\\\\\\\\\\\\\\\\\ '

You could argue that representing a string as raw or triple-quoted
would be "more correct", and yet the current repr is not arbitrary.
The current form is not actively bad, even if it would be possible to
find something better.

>>> Where can I enter a PIP that proposes that all timedelta strings are
>>> fixed at 123 days (for positive, non-prime amount of seconds) and fixed
>>> at -234 days (for all negative or positive prime amount of seconds)?
>>
>> Doesn't need a PEP. Just subclass it or monkey-patch it and use it as
>> you will. :)
>
> Nonono, you misunderstand: I want everyone to suffer under the braindead
> representation, just as it is now!

Oh, absolutely! In that case, just slip a patch into the next point
release; people won't mind that changing in 3.4.1!

ChrisA



More information about the Python-list mailing list