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

2014-03-28 Thread Alexander Belopolsky
On Fri, Mar 28, 2014 at 1:13 PM, Skip Montanaro  wrote:

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

So why would they need to support them in str()?  We could make
str(timedelta(days=369, hours=12, minutes=30, seconds=5)) return
"P369DT12H30M5S", but that would hardly be an improvement over

>>> print timedelta(days=369, hours=12, minutes=30, seconds=5)
369 days, 12:30:05

and I don't think ISO 8601 allows for negative durations, so it gives
us little guidance for the other issue either.

My preference would be to leave strict  ISO 8601 compliance to 3rd party
libraries.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


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

2014-03-28 Thread Skip Montanaro
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
constructors.

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

Skip
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com