summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-10-06 17:29:56 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-10-06 17:29:56 (GMT)
commit68713e41a5df7228e6971e894d8fc2fda720b5ce (patch)
treec2f235e8355031860e47853bd74bcc84f310b2b9 /Doc
parentfc632e3912ba9bb6ec20359148f05ca3ec231663 (diff)
downloadcpython-68713e41a5df7228e6971e894d8fc2fda720b5ce.zip
cpython-68713e41a5df7228e6971e894d8fc2fda720b5ce.tar.gz
cpython-68713e41a5df7228e6971e894d8fc2fda720b5ce.tar.bz2
Closes issue #12006: Add ISO 8601 year, week, and day directives to strptime.
This commit adds %G, %V, and %u directives to strptime. Thanks Ashley Anderson for the implementation.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/datetime.rst37
-rw-r--r--Doc/whatsnew/3.6.rst8
2 files changed, 44 insertions, 1 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 5c659e7..cf5d5b8 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -1909,6 +1909,34 @@ format codes.
| ``%%`` | A literal ``'%'`` character. | % | |
+-----------+--------------------------------+------------------------+-------+
+Several additional directives not required by the C89 standard are included for
+convenience. These parameters all correspond to ISO 8601 date values. These
+may not be available on all platforms when used with the :meth:`strftime`
+method. The ISO 8601 year and ISO 8601 week directives are not interchangeable
+with the year and week number directives above. Calling :meth:`strptime` with
+incomplete or ambiguous ISO 8601 directives will raise a :exc:`ValueError`.
+
++-----------+--------------------------------+------------------------+-------+
+| Directive | Meaning | Example | Notes |
++===========+================================+========================+=======+
+| ``%G`` | ISO 8601 year with century | 0001, 0002, ..., 2013, | \(8) |
+| | representing the year that | 2014, ..., 9998, 9999 | |
+| | contains the greater part of | | |
+| | the ISO week (``%V``). | | |
++-----------+--------------------------------+------------------------+-------+
+| ``%u`` | ISO 8601 weekday as a decimal | 1, 2, ..., 7 | |
+| | number where 1 is Monday. | | |
++-----------+--------------------------------+------------------------+-------+
+| ``%V`` | ISO 8601 week as a decimal | 01, 02, ..., 53 | \(8) |
+| | number with Monday as | | |
+| | the first day of the week. | | |
+| | Week 01 is the week containing | | |
+| | Jan 4. | | |
++-----------+--------------------------------+------------------------+-------+
+
+.. versionadded:: 3.6
+ ``%G``, ``%u`` and ``%V`` were added.
+
Notes:
(1)
@@ -1973,7 +2001,14 @@ Notes:
(7)
When used with the :meth:`strptime` method, ``%U`` and ``%W`` are only used
- in calculations when the day of the week and the year are specified.
+ in calculations when the day of the week and the calendar year (``%Y``)
+ are specified.
+
+(8)
+ Similar to ``%U`` and ``%W``, ``%V`` is only used in calculations when the
+ day of the week and the ISO year (``%G``) are specified in a
+ :meth:`strptime` format string. Also note that ``%G`` and ``%Y`` are not
+ interchangable.
.. rubric:: Footnotes
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
index 24fd822..dd35c9a 100644
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -110,6 +110,14 @@ Private and special attribute names now are omitted unless the prefix starts
with underscores. A space or a colon can be added after completed keyword.
(Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.)
+datetime
+--------
+
+* :meth:`datetime.stftime <datetime.datetime.stftime>` and
+ :meth:`date.stftime <datetime.date.stftime>` methods now support ISO 8601
+ date directives ``%G``, ``%u`` and ``%V``.
+ (Contributed by Ashley Anderson in :issue:`12006`.)
+
Optimizations
=============