YADTR (Yet Another DateTime Rant)

Marko Rauhamaa marko at pacujo.net
Wed Mar 26 11:58:30 EDT 2014


Skip Montanaro <skip at pobox.com>:

> Note though, that the ISO8601 representation isn't without its own
> flaws (which might explain why Tim avoided it BITD):
>
> * It doesn't appear to provide a way to represent fractions of a
> second (though perhaps all the fields can be fractional)
> * How many days are in a month or a year? (It has format codes for
> both. Writing a useful strptime is probably impossible.)
> * It has other ambiguities ("M" represents both months and minutes -
> what were they thinking?)


I don't have the (nonfree) ISO 8601 at hand, but

   <URL: http://www.schemacentral.com/sc/xsd/t-xsd_duration.html>

contains the practical answers -- xsd is one important use case for
str(timedelta), after all.

Fractions of seconds are supported -- the other fields can't be
fractional. The letter "T" separates months and minutes so there's no
ambiguity there.

str(timedelta()), unfortunately probably can't use anything but seconds
since PT1M can be 61 seconds and P1D can be 23 or 25 hours (DST). As you
say, P1M really means one month and P1Y means one year. The ambiguity is
intentional; if you mean to pay your employees monthly, the interval is
one month.


Marko



More information about the Python-list mailing list