YADTR (Yet Another DateTime Rant)
dfnsonfsduifb at gmx.de
Thu Mar 27 12:25:56 CET 2014
On 27.03.2014 11:44, Chris Angelico wrote:
> It's not "equally braindead", it follows a simple and logical rule:
> Only the day portion is negative.
The more I think about it, the sillier this rule seems to me.
A timedelta is a *whole* object. Either the whole delta is negative or
it is not. It doesn't make sense to split it up in two parts and
arbitrarily define one to be always nonnegative and the other to have no
The only locical reasoning behind this could be to argue that "-2 days"
makes more sense than "-15 minutes". Which it doesn't.
Worse: Negating a timedelta (which I would argue is a fairly common
operation) makes the whole thing unstable representation-wise:
>>> str(datetime.timedelta(2, 30))
'2 days, 0:00:30'
>>> str(-datetime.timedelta(2, 30))
'-3 days, 23:59:30'
And it makes it extremely error-prone to the reader:
>>> str(datetime.timedelta(0, -1))
'-1 day, 23:59:59'
This looks MUCH more like "almost two days ago" than
In any case, the str() function is *only* about the representation that
can be read by humans. Therefore its highest priority should be to
output something that can, in fact, be easily parsed by humans. The
current format is nothing of the sort.
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1 at speranza.aioe.org>
More information about the Python-list