Skip to content

strptime token support and documentation modernization #140644

@jyalim

Description

@jyalim
import datetime
# this will fail
datetime.datetime.strptime('2025-10-26','%F') 
# this will succeed
d0 = datetime.datetime.strptime('15:00:00','%T') 
print(d0.strftime('%FT%T'))

Example above ('%F', C99+ time.h format token) requires simple fix in the code; requires larger alignment in documentation.

Example Code Patch

To support '%F' in strptime requires adding a single line of code. The example above is fixed with the following line added to the TimeRE class __init__ method in Lib/_strptime.py,

base.__setitem__('F', self.pattern('%Y-%m-%d'))

just like existing code in that method for %T support (https://github.com/python/cpython/blob/main/Lib/_strptime.py#L421)

Documentation

The documentation refers to C89 (https://github.com/python/cpython/blob/main/Doc/library/datetime.rst?plain=1#L2498-L2636) and does not fully document the current level of strptime support.

Final thoughts

A larger discussion should be had on modernizing datetime and fully supporting C99 (ideally newer) time.h format tokens.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions