[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] ISO 8601 durations and datetime.timedelta

Andrew wrote:

> I meant ISO 8601 syntax for "durations" [1].

That's exactly what I was referring to. Consider this session:

>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2014, 3, 28, 12, 4, 38, 517110)
>>> then = now - datetime.timedelta(days=57, hours=12, minutes=12, seconds=12)
>>> now
datetime.datetime(2014, 3, 28, 12, 4, 38, 517110)
>>> then
datetime.datetime(2014, 1, 29, 23, 52, 26, 517110)

so, the difference is:

>>> now - then
datetime.timedelta(57, 43932)

Given that the timedelta has more than "a month's" worth of days, how
would you describe it using the ISO8601 duration notation without
referencing a specific point in time? Conversely, given your example,
"P3Y6M4DT12H30M5S", how would you convert that into a timedelta
without knowing which exact years and months this duration refers to?
Timedelta objects are very precise beasts, which is almost certainly
why they don't support "years" and "months" args in their

This is why I said this deserved a separate topic. Probably on python-ideas.