| ``%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) |
``%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
^^^^^^^^^^^^^^^^
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))
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
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
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)"""
# 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':
--- /dev/null
+Add ``'%F'`` support to :meth:`~datetime.datetime.strptime`.