Skip to content

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

Open
zuo wants to merge 26 commits into
python:mainfrom
zuo:strptime-c-and-y-fix
Open

gh-124529: Fix _strptime to make %c/%x accept a year with fewer digits#124778
zuo wants to merge 26 commits into
python:mainfrom
zuo:strptime-c-and-y-fix

Conversation

@zuo

@zuo zuo commented Sep 30, 2024

Copy link
Copy Markdown
Contributor

_strptime.TimeRE has been modified, regarding the %c and %x format
codes, to make datetime.datetime.strptime(), datetime.date.strptime()
and time.strptime() accept inputs that contain year numbers consisting
of fewer digits than usual, i.e., not zero-padded to the usual width
of 2 or 4 (which is appropriate for the format code and current locale).

Thanks to that, now the desired behavior described in gh-124529 should be
consistently observed; certain strftime/strptime round trips (involving
%c/%x and small year numbers) no longer raise ValueError for some
platforms/locales (in particular, this was the case on Linux, for various
locales, including C/C.UTF-8).

@zuo
zuo force-pushed the strptime-c-and-y-fix branch from 33d5109 to d3ae17b Compare September 30, 2024 02:51
@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
@zuo
zuo force-pushed the strptime-c-and-y-fix branch from d3ae17b to 91b6bca Compare September 30, 2024 02:52
@zuo
zuo force-pushed the strptime-c-and-y-fix branch from 91b6bca to 1d916a0 Compare September 30, 2024 02:54
Comment thread Misc/NEWS.d/next/Library/2024-09-30-04-49-22.gh-issue-124529.hDDlMH.rst Outdated
@zuo
zuo requested a review from rruuaanng September 30, 2024 19:01
@zuo
zuo force-pushed the strptime-c-and-y-fix branch from bce4b6d to 56c84dc Compare September 30, 2024 20:44
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

PS Note that the changes concern only the %c/%x-parsing-related behavior, and nothing changes when it comes to %y, %Y and %G (and any non-standard year-representation-related format codes).

@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

PPS I added (obviously) the necessary tests (directly related to the changes), but also some indirectly-related ones (especially confirming the unchanged behavior for %y/%Y/%G).

PPPS A suitable mention in the docs has also been added.

@zuo
zuo requested a review from rruuaanng October 1, 2024 13:23
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

I hope it's ready. [EDIT: not yet]

@zuo
zuo force-pushed the strptime-c-and-y-fix branch from c16b5e3 to 059d4c5 Compare October 1, 2024 20:33
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

OK, I hope now it's ready. :)

Comment thread Lib/test/test_strptime.py
@zuo

zuo commented Oct 4, 2024

Copy link
Copy Markdown
Contributor Author

TODO: if this PR's approach is accepted at all, it would be good to adjust it to the changes from PR #124946 (after it is merged).

@zuo
zuo requested a review from rruuaanng October 11, 2024 05:10
Comment thread Lib/test/test_strptime.py
Comment thread Lib/test/test_strptime.py
@donbarbos

Copy link
Copy Markdown
Contributor

looks like good idea and important fix :)
@zuo are you ready to continue?

@zuo
zuo requested a review from rruuaanng March 3, 2025 02:46
@zuo

zuo commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

looks like good idea and important fix :) @zuo are you ready to continue?

Yes, I am :)

Yet I'm not sure what is the next step...

Comment thread Doc/library/datetime.rst Outdated
@StanFromIreland

Copy link
Copy Markdown
Member

This has a lot of conflicts, and needs updates.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 18, 2026
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
@zuo
zuo requested a review from StanFromIreland as a code owner July 18, 2026 13:08
@zuo

zuo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

For the record, I'd be happy to continue with this, but I guess first the discussion in the related issue (#124529) needs to be resolved -- to decide whether this path is OK or not.

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

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants