Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b451a83
Add C implementation of date.fromisoformat
pganssle Dec 1, 2017
4ccef0a
Add python implementation of date.fromisoformat
pganssle Dec 1, 2017
13e8e48
Add tests for date.fromisoformat
pganssle Dec 1, 2017
6fa5c55
Implement C version of datetime.fromisoformat
pganssle Dec 2, 2017
0d44220
Add initial test suite for C-only datetime.fromisoformat
pganssle Dec 2, 2017
327d0fc
Add C implementation of time.fromisoformat()
pganssle Dec 4, 2017
52b2175
Add tests for time.isoformat()
pganssle Dec 4, 2017
f1b78af
Add pure python implementation of time.fromisoformat()
pganssle Dec 4, 2017
aeaa9ca
Add tests for pure python time.fromisoformat()
pganssle Dec 4, 2017
094ccf4
Add pure python implementation of datetime.fromisoformat
pganssle Dec 4, 2017
2a8120d
Enable tests for pure python datetime.fromisoformat
pganssle Dec 4, 2017
af9e6d0
Add documentation for [date][time].fromisoformat()
pganssle Dec 4, 2017
cf802af
Consolidate helper functions into parse_digits
pganssle Dec 5, 2017
626d239
Refactor datetime.isoformat round trip tests
pganssle Dec 5, 2017
7c771e7
Refactor C code for PEP 7
pganssle Dec 5, 2017
8fbd752
Add support for seconds in fromisoformat offsets
pganssle Dec 6, 2017
4d55e05
Fix pure python implementation of isoformat() for sub-second zones
pganssle Dec 9, 2017
5a233fb
Add support for subsecond offsets to fromisoformat
pganssle Dec 9, 2017
9fa91db
Fix documentation and pure python error catching in fromisoformat
pganssle Dec 18, 2017
ffdb2af
Drop unsupported sep parameter in _tzstr
pganssle Dec 18, 2017
18a5fa8
Add test for ambiguous isoformat strings
pganssle Dec 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix documentation and pure python error catching in fromisoformat
  • Loading branch information
pganssle committed Dec 18, 2017
commit 9fa91db1b718d4a8377eab3afccd16c717b5085b
17 changes: 9 additions & 8 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ Other constructors, all class methods:

.. classmethod:: date.fromisoformat(date_string)

Return a :class:`date` corresponding to a *date_string* in one of the ISO 8601
formats emitted by :meth:`date.isoformat`. Specifically, this function supports
strings in the format(s) ``YYYY-MM-DD``.
Return a :class:`date` corresponding to a *date_string* in the format emitted
by :meth:`date.isoformat`. Specifically, this function supports strings in
the format(s) ``YYYY-MM-DD``.

.. caution::

Expand Down Expand Up @@ -837,8 +837,9 @@ Other constructors, all class methods:
.. classmethod:: datetime.fromisoformat(date_string)

Return a :class:`datetime` corresponding to a *date_string* in one of the
ISO 8601 formats emitted by :meth:`datetime.isoformat`. Specifically, this function
supports strings in the format(s) ``YYYY-MM-DD[*HH[:MM[:SS[.mmm[mmm]]]]][+HH:MM[:SS[.ffffff]]]``,
formats emitted by :meth:`date.isoformat` and :meth:`datetime.isoformat`.
Specifically, this function supports strings in the format(s)
``YYYY-MM-DD[*HH[:MM[:SS[.mmm[mmm]]]][+HH:MM[:SS[.ffffff]]]]``,
where ``*`` can match any single character.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the colon after :MM be optional?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be less ambiguous putting the time zone inside the optional time part. Test case:

datetime(2017, 12, 18, 11, 0).isoformat(sep="+", timespec="minutes") -> "2017-12-18+11:00"
datetime.fromisoformat("2017-12-18+11:00") -> datetime(2017, 12, 18, 11, 0)

@pganssle pganssle Dec 18, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. As much as I dislike the idea of timezone being part of the time component, this is fine I suppose (and in fact that is how it is currently implemented).

That said, another design I considered is one where we take sep as a keyword argument to isoparse, which would relieve this ambiguity for all separators other than - and + if we wanted to eventually allow parsing of strings of the format YYYY-MM-DD+HH:MM. That's one decision we'd have to make in this version because changing it would not be backwards compatible.


.. caution::
Expand Down Expand Up @@ -1518,11 +1519,11 @@ In boolean contexts, a :class:`.time` object is always considered to be true.

Other constructor:

.. classmethod:: time.fromisoformat(date_string)
.. classmethod:: time.fromisoformat(time_string)

Return a :class:`time` corresponding to a *time_string* in one of the ISO 8601
Return a :class:`time` corresponding to a *time_string* in one of the
formats emitted by :meth:`time.isoformat`. Specifically, this function supports
strings in the format(s) ``HH[:MM[:SS[.mmm[mmm]]]]][+HH:MM[:SS[.ffffff]]]``.
strings in the format(s) ``HH[:MM[:SS[.mmm[mmm]]]][+HH:MM[:SS[.ffffff]]]``.

.. caution::

Expand Down
4 changes: 2 additions & 2 deletions Lib/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def fromisoformat(cls, date_string):
try:
assert len(date_string) == 10
return cls(*_parse_isoformat_date(date_string))
except:
except Exception:
raise ValueError('Invalid isoformat string: %s' % date_string)


Expand Down Expand Up @@ -1367,7 +1367,7 @@ def fromisoformat(cls, time_string):

try:
return cls(*_parse_isoformat_time(time_string))
except:
except Exception:
raise ValueError('Invalid isoformat string: %s' % time_string)


Expand Down