Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion 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-26, | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the example changed?

| | the ISO 8601 format. | 1001-12-30 | |
+-----------+--------------------------------+------------------------+-------+
| ``%g`` | Last 2 digits of ISO 8601 year | 00, 01, ..., 99 | \(0) |
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 @@ -1212,6 +1212,20 @@ def test_strptime_leap_year(self):
date.strptime('20-03-14', '%y-%m-%d')
date.strptime('02-29,2024', '%m-%d,%Y')

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

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

class SubclassDate(date):
sub_var = 1

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