Skip to content

Commit e5fecbb

Browse files
committed
Accept suggestions
1 parent 2b27924 commit e5fecbb

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

Doc/library/datetime.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,10 +2658,13 @@ requires, and these work on all supported platforms.
26582658
| ``%Y`` | Year with century as a decimal | 0001, 0002, ..., 2013, | \(2) |
26592659
| | number. | 2014, ..., 9998, 9999 | |
26602660
+-----------+--------------------------------+------------------------+-------+
2661-
| ``%z`` | UTC offset in the form | (empty), +0000, | \(6) |
2662-
| | ``±HH[MM[SS[.ffffff]]]`` | -0400, +1030, | |
2663-
| | (empty string if the object is | +063415, +04, | |
2664-
| | naive). | -030712.345216 | |
2661+
| ``%z`` | UTC offset. | (empty), +0000, | \(6) |
2662+
| | ``strptime()`` accepts | -0400, +1030, | |
2663+
| | ``±HH[MM[SS[.ffffff]]]``; | +063415, +04, | |
2664+
| | ``strftime()`` outputs | -030712.345216 | |
2665+
| | ``±HHMM[SS[.ffffff]]`` | | |
2666+
| | (empty string if the object is | | |
2667+
| | naive). | | |
26652668
+-----------+--------------------------------+------------------------+-------+
26662669
| ``%Z`` | Time zone name (empty string | (empty), UTC, GMT | \(6) |
26672670
| | if the object is naive). | | |
@@ -2683,10 +2686,13 @@ convenience.
26832686
| | number, zero-padded to 6 | 999999 | |
26842687
| | digits. | | |
26852688
+-----------+--------------------------------+------------------------+-------+
2686-
| ``%:z`` | UTC offset in the form | (empty), +00:00, | \(6) |
2687-
| | ``±HH[:MM[:SS[.ffffff]]]`` | -04:00, +10:30, | |
2688-
| | (empty string if the object is | +06:34:15, +04, | |
2689-
| | naive). | -03:07:12.345216 | |
2689+
| ``%:z`` | UTC offset. | (empty), +00:00, | \(6) |
2690+
| | ``strptime()`` accepts | -04:00, +10:30, | |
2691+
| | ``±HH[:MM[:SS[.ffffff]]]``; | +06:34:15, +04, | |
2692+
| | ``strftime()`` outputs | -03:07:12.345216 | |
2693+
| | ``±HH:MM[:SS[.ffffff]]`` | | |
2694+
| | (empty string if the object is | | |
2695+
| | naive). | | |
26902696
+-----------+--------------------------------+------------------------+-------+
26912697

26922698
The full set of format codes supported varies across platforms, because Python
@@ -2871,6 +2877,10 @@ Notes:
28712877
aware :class:`.datetime` object will be produced. The ``tzinfo`` of the
28722878
result will be set to a :class:`timezone` instance.
28732879

2880+
.. versionchanged:: next
2881+
The ``%z`` and ``%:z`` directives in :meth:`~.datetime.strptime`
2882+
now accept time zone offsets in ``±HH`` format (for example, ``+03``).
2883+
28742884
(7)
28752885
When used with the :meth:`~.datetime.strptime` method, ``%U`` and ``%W`` are only used
28762886
in calculations when the day of the week and the calendar year (``%Y``)

Lib/test/datetimetester.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,8 @@ def test_strptime(self):
30603060
with self.assertRaises(ValueError): strptime("-2400", "%z")
30613061
with self.assertRaises(ValueError): strptime("-000", "%z")
30623062
with self.assertRaises(ValueError): strptime("z", "%z")
3063+
with self.assertRaises(ValueError): strptime("+3", "%z")
3064+
with self.assertRaises(ValueError): strptime("-7", "%z")
30633065

30643066
def test_strptime_ampm(self):
30653067
dt = datetime(1999, 3, 17, 0, 44, 55, 2)

0 commit comments

Comments
 (0)