classification
Title: datetime: add method to parse isoformat() output
Type: enhancement Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: datetime: add ability to parse RFC 3339 dates and times
View: 15873
Assigned To: Nosy List: belopolsky, orent, p-ganssle
Priority: normal Keywords:

Created on 2017-10-22 04:56 by orent, last changed 2018-07-07 01:01 by martin.panter. This issue is now closed.

Messages (2)
msg304728 - (view) Author: Oren Tirosh (orent) Date: 2017-10-22 04:56
The object types in the datetime module can produce a standard string representation (rfc3339, a subset of iso8601) but they do not provide a method to parse it.

Proposed method names: isoparse or fromisoformat.

In addition, a constructor call with a single string argument may also be supported. This would make the behavior of datetime/date/time more similar to other value types such as int, str or float and maintain the same invariant of x == type(x)(str(x))

Requirements: support lossless round-tripping of all valid datetime object values to str and back, with the exception of objects having a custom tzinfo (not None or an instance of datetime.timezone).

The _strptime format of '%Y-%m-%d %H:%M:S.%f%z' comes close, but fails to meet these requirements in the following ways:

1. %z matches +HHMM, not +HH:MM (addressed by issue 31800, currently discussed on datetime-sig)
2. %z does not match the empty string, indicating a naive datetime object (tzinfo=None)
3. .%f requires a fraction part, while isoformat drops it when the timestamp is an exact second (microsecond=0).
msg321109 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2018-07-05 15:44
This is a duplicate of #15873 and #24954 and can be closed, as `fromisoformat()` was added in Python 3.7.
History
Date User Action Args
2018-07-07 01:01:09martin.pantersetstatus: open -> closed
superseder: datetime: add ability to parse RFC 3339 dates and times
resolution: duplicate
stage: resolved
2018-07-05 15:44:40p-gansslesetnosy: + p-ganssle
messages: + msg321109
2017-10-22 12:20:02SilentGhostsetnosy: + belopolsky

versions: + Python 3.7
2017-10-22 04:56:08orentcreate