YADTR (Yet Another DateTime Rant)

Skip Montanaro skip at pobox.com
Wed Mar 26 17:34:37 CET 2014


On Wed, Mar 26, 2014 at 10:58 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Fractions of seconds are supported -- the other fields can't be
> fractional.

Actually, it appears that whatever the last value you give can be
fractionated.  From the Wikipedia page you referenced:

"The smallest value used may also have a decimal fraction, as in
"P0.5Y" to indicate half a year."

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

True.  Your comment about monthly intervals makes me realize that you
probably can't map timedelta objects onto this ISO8601 duration
stuff. It seems like if you want to specify "pay my employees on the
first of every month", then timedelta objects are the wrong thing. You
want a recurrence relation, which is a more complex beast. For that,
you want something like dateutil.rrule. There is a good reason that
the internal units of timedelta objects are days, seconds, and
microseconds. They are well-defined outside of a calendar context.

So, I guess Roy is back to square one. He can always roll his own
timedelta subclass and give it a __str__ implementation...

S



More information about the Python-list mailing list