Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
92929d8
provide support for %F token in strptime; add test for it and %T
jyalim Oct 26, 2025
b1bf9b4
📜🤖 Added by blurb_it.
blurb-it[bot] Oct 27, 2025
d84fd54
rm comment as recommended
jyalim Oct 28, 2025
cb8d7d3
Update Misc/NEWS.d/next/Library/2025-10-27-00-13-04.gh-issue-140644.W…
jyalim Oct 28, 2025
634ecea
Rename NEWS blurbit to match new github issue name
jyalim Oct 28, 2025
2e94037
Update test_strptime.py to use unittest methods, as requested
jyalim Oct 28, 2025
c23b731
simplify news per recommendation
jyalim Oct 28, 2025
e77ff96
Remove datetime tests from test_strptime.py (added to `datetimetester…
jyalim Oct 28, 2025
ffbc215
Tests moved to datetimetester.py
jyalim Oct 28, 2025
fb63ae7
Merge branch 'main' into fix-issue-140644
StanFromIreland Feb 7, 2026
ff10b73
Update Misc/NEWS.d/next/Library/2025-10-27-00-13-04.gh-issue-140715.W…
jyalim Feb 7, 2026
b4ec5f8
Update Lib/test/test_strptime.py
jyalim Feb 7, 2026
8513e1d
Update Lib/test/datetimetester.py
jyalim Feb 7, 2026
0a928e6
Update Lib/test/datetimetester.py
jyalim Feb 7, 2026
029ed4f
refactor test for %F as requested
jyalim Feb 7, 2026
88c6f02
refactor test for %F and %T as requested
jyalim Feb 7, 2026
707ea08
refactor test %T as requested; rename %F + %T tests to match datetime…
jyalim Feb 7, 2026
c61cb2f
add %F and %T tests, as requested, for ensuring strptime & strftime t…
jyalim Feb 7, 2026
10ab774
remove (0) note for %F in documentation, as requested
jyalim Feb 7, 2026
179afae
revert date change in
jyalim Feb 8, 2026
f56f54a
documenting %F addition to strptime
jyalim Feb 8, 2026
29ba043
Update Lib/test/test_strptime.py
jyalim Feb 8, 2026
7d4c618
Update Lib/test/datetimetester.py
jyalim Feb 8, 2026
2cf4890
Update Doc/library/datetime.rst
jyalim Feb 8, 2026
c5593dd
Update Doc/library/datetime.rst
jyalim Feb 8, 2026
b0ca1d2
Update Lib/test/test_strptime.py
jyalim Feb 8, 2026
46981d1
Update Lib/test/datetimetester.py
jyalim Feb 8, 2026
500552b
relocate test methods for %F and %T to TestDate and TestDateTime (res…
jyalim Feb 8, 2026
18757eb
Update Lib/test/datetimetester.py
StanFromIreland Feb 8, 2026
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
6 changes: 3 additions & 3 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ requires, and these work on all supported platforms.
| ``%e`` | The day of the month as a | ␣1, ␣2, ..., 31 | |
| | space-padded decimal number. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%F`` | Equivalent to ``%Y-%m-%d``, | 2025-10-11, | \(0) |
| ``%F`` | Equivalent to ``%Y-%m-%d``, | 2025-10-11, | |
| | the ISO 8601 format. | 1001-12-30 | |
+-----------+--------------------------------+------------------------+-------+
| ``%g`` | Last 2 digits of ISO 8601 year | 00, 01, ..., 99 | \(0) |
Expand Down Expand Up @@ -2673,10 +2673,10 @@ differences between platforms in handling of unsupported format specifiers.
``%G``, ``%u`` and ``%V`` were added.

.. versionadded:: 3.12
``%:z`` was added for :meth:`~.datetime.strftime`
``%:z`` was added for :meth:`~.datetime.strftime`.

.. versionadded:: 3.15
``%:z`` was added for :meth:`~.datetime.strptime`
``%:z`` and ``%F`` were added for :meth:`~.datetime.strptime`.

Technical Detail
^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def __init__(self, locale_time=None):
mapping['W'] = mapping['U'].replace('U', 'W')

base.__init__(mapping)
base.__setitem__('F', self.pattern('%Y-%m-%d'))
base.__setitem__('T', self.pattern('%H:%M:%S'))
base.__setitem__('R', self.pattern('%H:%M'))
base.__setitem__('r', self.pattern(self.locale_time.LC_time_ampm))
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,13 @@ def test_fromisocalendar_type_errors(self):
with self.assertRaises(TypeError):
self.theclass.fromisocalendar(*isocal)

def test_strptime_F_format(self):
test_date = "2025-10-26"
self.assertEqual(
self.theclass.strptime(test_date, "%F"),
self.theclass.strptime(test_date, "%Y-%m-%d")
)


#############################################################################
# datetime tests
Expand Down Expand Up @@ -3780,6 +3787,13 @@ def test_repr_subclass(self):
td = SubclassDatetime(2010, 10, 2, second=3)
self.assertEqual(repr(td), "SubclassDatetime(2010, 10, 2, 0, 0, 3)")

def test_strptime_T_format(self):
test_time = "15:00:00"
self.assertEqual(
self.theclass.strptime(test_time, "%T"),
self.theclass.strptime(test_time, "%H:%M:%S")
)


class TestSubclassDateTime(TestDateTime):
theclass = SubclassDatetime
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,20 @@ def test_mar1_comes_after_feb29_even_when_omitting_the_year(self):
time.strptime("Feb 29", "%b %d"),
time.strptime("Mar 1", "%b %d"))

def test_strptime_F_format(self):
test_date = "2025-10-26"
self.assertEqual(
time.strptime(test_date, "%F"),
time.strptime(test_date, "%Y-%m-%d")
)

def test_strptime_T_format(self):
test_time = "15:00:00"
self.assertEqual(
time.strptime(test_time, "%T"),
time.strptime(test_time, "%H:%M:%S")
)

class Strptime12AMPMTests(unittest.TestCase):
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def test_strptime(self):
# Should be able to go round-trip from strftime to strptime without
# raising an exception.
tt = time.gmtime(self.t)
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
'j', 'm', 'M', 'p', 'S',
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'F', 'H', 'I',
'j', 'm', 'M', 'p', 'S', 'T',
'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
format = '%' + directive
if directive == 'd':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``'%F'`` support to :meth:`~datetime.datetime.strptime`.
Loading