Skip to content
16 changes: 13 additions & 3 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2584,8 +2584,11 @@ requires, and these work on all supported platforms.
| ``%S`` | Second as a zero-padded | 00, 01, ..., 59 | \(4), |
| | decimal number. | | \(9) |
+-----------+--------------------------------+------------------------+-------+
| ``%t`` | The tab character | ``\t`` | \(0) |
| | (``'\t'``). | | |
| ``%t`` | The tab character, ``'\t'``, | ``\t`` | \(11) |
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the footnote.

As for the text, in general we note strptime() specific things in a foot note, however I like this approach, but the it can be more concise:

The tab character (``'\t'``).
For :meth:`!strptime`, arbitrary whitespace.

| | for ``strftime``, else | | |
| | for ``strptime``, any | | |
| | blank-space character(s), | | |
| | i.e., ``'\s+'``. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%T`` | ISO 8601 time format, | 10:01:59 | |
| | equivalent to ``%H:%M:%S``. | | |
Expand Down Expand Up @@ -2676,7 +2679,8 @@ differences between platforms in handling of unsupported format specifiers.
``%:z`` was added for :meth:`~.datetime.strftime`.

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

Technical Detail
^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -2880,6 +2884,12 @@ Notes:
:exc:`DeprecationWarning`. In 3.15 or later we may change this into
an error or change the default year to a leap year. See :gh:`70647`.

(11)
See `The Open Group Base Specifications Issue 8 IEEE Std 1003.1-2024
documentation for strptime
<https://pubs.opengroup.org/onlinepubs/9799919799/functions/strptime.html>`_
for details on the :meth: `~.datetime.strptime` invocation.

.. rubric:: Footnotes

.. [#] If, that is, we ignore the effects of Relativity
Expand Down
4 changes: 3 additions & 1 deletion Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ def __init__(self, locale_time=None):
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
for tz in tz_names),
'Z'),
'%': '%'}
't': r'\s+',
'%': '%'
}
if self.locale_time.LC_alt_digits is None:
for d in 'dmyCHIMS':
mapping['O' + d] = r'(?P<%s>\d\d|\d| \d)' % d
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,16 @@ def test_strptime_D_format(self):
self.theclass.strptime(test_date, "%m/%d/%y")
)

def test_strptime_t_format(self):
test_year,test_month,test_day = 2026,2,20
self.assertEqual(
self.theclass.strptime(
f'{test_year} \r {test_month}\t \n{test_day}',
"%Y%t%m%t%d"
),
self.theclass(test_year,test_month,test_day)
)


#############################################################################
# datetime tests
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,19 @@ def test_strptime_D_format(self):
time.strptime(test_date, "%m/%d/%y")
)

def test_strptime_t_format(self):
test_year,test_month,test_day = 2026,2,20
self.assertEqual(
time.strptime(
f'{test_year} \r {test_month}\t \n{test_day}',
"%Y%t%m%t%d"
),
time.strptime(
f'{test_year}-{test_month}-{test_day}',
"%Y-%m-%d"
)
)

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

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def test_strptime(self):
# raising an exception.
tt = time.gmtime(self.t)
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'D', 'F', 'H', 'I',
'j', 'm', 'M', 'p', 'S', 'T',
'j', 'm', 'M', 'p', 'S', 't', '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 ``'%t'`` support to :meth:`~datetime.datetime.strptime`.
Loading