YADTR (Yet Another DateTime Rant)

Johannes Bauer dfnsonfsduifb at gmx.de
Thu Mar 27 06:22:27 EDT 2014


On 27.03.2014 01:16, Steven D'Aprano wrote:

> py> divmod(30, 24)
> (1, 6)
> 
> That makes perfect intuitive sense: 30 hours is 1 day with 6 hours 
> remaining. In human-speak, we'll say that regardless of whether the 
> timedelta is positive or negative: we'll say "1 day and 6 hours from now" 
> or "1 day and 6 hours ago". But when we specify the sign:
> 
> py> divmod(-30, 24)
> (-2, 18)
> 
> If an event happened 30 hours ago, it is correct to say that it occurred 
> "18 hours after 2 days ago", but who talks that way?

Well, no matter how timedeltas internal representation is and if they
use modular division or (they probably do, I agree) this shouldn't
affect the display at all. Internally they can use any arbitrary
representation, but for the external representation I think a very sane
requirement should be that for a given timedelta t with t > 0 it is its
string representation str(t) would satisfy:

"-" + str(t) == str(-t)

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).

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)?

Cheers,
Johannes

-- 
>> 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 mailing list