Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-124529: Fix _strptime to make %c/%x accept a year with fewer digits #124778

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zuo
Copy link
Contributor

@zuo zuo commented Sep 30, 2024

Slightly relax (by modifying _strptime.TimeRE) how datetime.datetime.strptime(), datetime.date.strptime() and time.strptime() parse format strings that include %c or %x -- so that year number representations consisting of fewer digits than the usual four or two are now accepted (note that nothing changes for %Y and %y). Thanks to that, the desired behavior described in gh-124529 is now consistently observed on all concerned platforms and locales, i.e., now certain strftime/strptime round trips (such as datetime.strptime(dt.strftime("%c"), "%c"))) never raise ValueError (that previously might happen, e.g., on Linux -- for various locales, including C/C.UTF-8).

Directly related tests have been added, plus a few other (indirectly-related) tests have also been added, for consistency and better coverage.

@zuo zuo changed the title gh-124529: Fix _strptime to make %c/%y accept a year with fewer digits gh-124529: Fix _strptime to make %c/%x accept a year with fewer digits Sep 30, 2024
@@ -0,0 +1,9 @@
Fix :meth:`datetime.datetime.strptime`, :meth:`datetime.date.strptime` as
well as :func:`time.strptime` (by modifying :class:`_strptime.TimeRE`) to

Choose a reason for hiding this comment

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

Maybe you shouldn't write classes or methods with underscores to NEWS, because they're not public.
And, Maybe you can try to shorten the description of NEWS, it's too long.

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