summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorPaul Ganssle <pganssle@users.noreply.github.com>2017-12-21 05:33:49 (GMT)
committerAlexander Belopolsky <abalkin@users.noreply.github.com>2017-12-21 05:33:49 (GMT)
commit09dc2f508c8513e0466a759cc27a09108c1e55c2 (patch)
tree53877208455125e97549e90f3995929ad9768ca4 /Doc/library
parent507434fd504f3ebc1da72aa77544edc0d73f136e (diff)
downloadcpython-09dc2f508c8513e0466a759cc27a09108c1e55c2.zip
cpython-09dc2f508c8513e0466a759cc27a09108c1e55c2.tar.gz
cpython-09dc2f508c8513e0466a759cc27a09108c1e55c2.tar.bz2
bpo-15873: Implement [date][time].fromisoformat (#4699)
Closes bpo-15873.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/datetime.rst48
1 files changed, 47 insertions, 1 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index dce51a1..c1b164e 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -436,6 +436,21 @@ Other constructors, all class methods:
d``.
+.. classmethod:: date.fromisoformat(date_string)
+
+ 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::
+
+ This does not support parsing arbitrary ISO 8601 strings - it is only intended
+ as the inverse operation of :meth:`date.isoformat`.
+
+ .. versionadded:: 3.7
+
+
+
Class attributes:
.. attribute:: date.min
@@ -819,6 +834,21 @@ Other constructors, all class methods:
Added the *tzinfo* argument.
+.. classmethod:: datetime.fromisoformat(date_string)
+
+ Return a :class:`datetime` corresponding to a *date_string* in one of the
+ 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.
+
+ .. caution::
+
+ This does not support parsing arbitrary ISO 8601 strings - it is only intended
+ as the inverse operation of :meth:`datetime.isoformat`.
+
+ .. versionadded:: 3.7
+
.. classmethod:: datetime.strptime(date_string, format)
Return a :class:`.datetime` corresponding to *date_string*, parsed according to
@@ -1486,6 +1516,23 @@ In boolean contexts, a :class:`.time` object is always considered to be true.
error-prone and has been removed in Python 3.5. See :issue:`13936` for full
details.
+
+Other constructor:
+
+.. classmethod:: time.fromisoformat(time_string)
+
+ 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]]]``.
+
+ .. caution::
+
+ This does not support parsing arbitrary ISO 8601 strings - it is only intended
+ as the inverse operation of :meth:`time.isoformat`.
+
+ .. versionadded:: 3.7
+
+
Instance methods:
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
@@ -1587,7 +1634,6 @@ Instance methods:
``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't
return ``None`` or a string object.
-
Example:
>>> from datetime import time, tzinfo, timedelta