[New-bugs-announce] [issue42094] isoformat() / fromisoformat() for datetime.timedelta

Erik Cederstrand report at bugs.python.org
Tue Oct 20 03:13:53 EDT 2020


New submission from Erik Cederstrand <erik at cederstrand.dk>:

Python 3.7 gained support for parsing ISO 8601 formatted time, date and datetime strings via the fromisoformat() methods. Python has seen improved support for ISO 8601 in general; ISO calendar format codes were added in Python 3.6, and fromisocalendar() was added in Python 3.8.

ISO 8601 also has a standard for durations: https://en.wikipedia.org/wiki/ISO_8601#Durations

For consistency with the other objects in the datetime module, I suggest adding isoformat()/fromisoformat() methods for datetime.timedelta that implement ISO 8601 durations.

ISO 8601 durations support years and months that are not valid timedelta arguments because they are non-precise durations. I suggest throwing an exception if the conversion to or from timedelta cannot be done safely.

https://pypi.org/project/isodate/ implements a parse_duration() method that could be used for inspiration.

----------
components: Library (Lib)
messages: 379091
nosy: Erik Cederstrand
priority: normal
severity: normal
status: open
title: isoformat() / fromisoformat() for datetime.timedelta
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42094>
_______________________________________


More information about the New-bugs-announce mailing list