Skip to content

Commit 6da69b6

Browse files
committed
%D support for strptime, including test and Doc update
1 parent fdbc135 commit 6da69b6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Doc/library/datetime.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,8 +2534,8 @@ requires, and these work on all supported platforms.
25342534
| ``%d`` | Day of the month as a | 01, 02, ..., 31 | \(9) |
25352535
| | zero-padded decimal number. | | |
25362536
+-----------+--------------------------------+------------------------+-------+
2537-
| ``%D`` | Equivalent to ``%m/%d/%y``. | 11/10/2025 | \(9), |
2538-
| | | | \(0) |
2537+
| ``%D`` | Equivalent to ``%m/%d/%y``. | 11/10/2025 | \(9) |
2538+
| | | | |
25392539
+-----------+--------------------------------+------------------------+-------+
25402540
| ``%e`` | The day of the month as a | ␣1, ␣2, ..., 31 | |
25412541
| | space-padded decimal number. | | |
@@ -2676,7 +2676,7 @@ differences between platforms in handling of unsupported format specifiers.
26762676
``%:z`` was added for :meth:`~.datetime.strftime`.
26772677

26782678
.. versionadded:: 3.15
2679-
``%:z`` and ``%F`` were added for :meth:`~.datetime.strptime`.
2679+
``%:z``, ``%F``, and ``%D`` were added for :meth:`~.datetime.strptime`.
26802680

26812681
Technical Detail
26822682
^^^^^^^^^^^^^^^^

Lib/_strptime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def __init__(self, locale_time=None):
425425
base.__setitem__('X', self.pattern(self.locale_time.LC_time))
426426
base.__setitem__('x', self.pattern(self.locale_time.LC_date))
427427
base.__setitem__('c', self.pattern(self.locale_time.LC_date_time))
428+
base.__setitem__('D', self.pattern('%m/%d/%Y'))
428429

429430
def __seqToRE(self, to_convert, directive, altregex=None):
430431
"""Convert a list to a regex string for matching a directive.

Lib/test/datetimetester.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,13 @@ def test_strptime_F_format(self):
22002200
self.theclass.strptime(test_date, "%Y-%m-%d")
22012201
)
22022202

2203+
def test_strptime_D_format(self):
2204+
test_date = "11/28/2025"
2205+
self.assertEqual(
2206+
self.theclass.strptime(test_date, "%D"),
2207+
self.theclass.strptime(test_date, "%m/%d/%Y")
2208+
)
2209+
22032210

22042211
#############################################################################
22052212
# datetime tests

0 commit comments

Comments
 (0)