Skip to content

gh-140715: Add %t format code support to strptime()#144896

Open
jyalim wants to merge 5 commits intopython:mainfrom
jyalim:fix-issue-140715--t
Open

gh-140715: Add %t format code support to strptime()#144896
jyalim wants to merge 5 commits intopython:mainfrom
jyalim:fix-issue-140715--t

Conversation

@jyalim
Copy link
Contributor

@jyalim jyalim commented Feb 17, 2026

Incrementally builds C99+ datetime support with addition of %t with single line of code. Also adds tests and updates documentation.

Continued effort from PR: #140647 , #144819.

Documentation drops (0) footnote.

Passed all tests.

Passed patchcheck.

Issue: #140715


📚 Documentation preview 📚: https://cpython-previews--144896.org.readthedocs.build/

@StanFromIreland StanFromIreland self-assigned this Feb 17, 2026
Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

This is quite an odd case, as per the standard for strftime, it is a \t character, however, for strptime():

A series of conversion specifications composed of %n, %t, white-space bytes, or any combination is executed by scanning up to the first non-white-space byte (which remains unscanned), or until no more characters can be scanned.

And, more straightforward:

Arbitrary whitespace.

Considering that this is the wide-spread behaviour, it should instead be r'\s+' for %n/%t (with additional tests), and add a note to the doc.


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

Choose a reason for hiding this comment

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

Please sort them alphabetically, this list is getting long now.

test_date = "2026\t02\t16"
self.assertEqual(
self.theclass.strptime(test_date, "%Y%t%m%t%d"),
self.theclass.strptime(test_date, "%Y\t%m\t%d")
Copy link
Member

Choose a reason for hiding this comment

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

Here, I would prefer we explicitly have self.theclasss(2026, 2, 16).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments