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

@zuozuo 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
zuoforce-pushed the strptime-c-and-y-fix branch from 33d5109 to d3ae17bCompareSeptember 30, 2024 02:51
@zuozuo changed the title gh-124529: Fix _strptime to make %c/%y accept a year with fewer digitsgh-124529: Fix _strptime to make %c/%x accept a year with fewer digitsSep 30, 2024
@zuo
zuoforce-pushed the strptime-c-and-y-fix branch from d3ae17b to 91b6bcaCompareSeptember 30, 2024 02:52
@zuo
zuoforce-pushed the strptime-c-and-y-fix branch from 91b6bca to 1d916a0CompareSeptember 30, 2024 02:54
Comment threadMisc/NEWS.d/next/Library/2024-09-30-04-49-22.gh-issue-124529.hDDlMH.rst Outdated
@zuo
zuo requested a review from rruuaanngSeptember 30, 2024 19:01
@zuo
zuoforce-pushed the strptime-c-and-y-fix branch from bce4b6d to 56c84dcCompareSeptember 30, 2024 20:44
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
ContributorAuthor

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
ContributorAuthor

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 rruuaanngOctober 1, 2024 13:23
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
ContributorAuthor

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

@zuo
zuoforce-pushed the strptime-c-and-y-fix branch from c16b5e3 to 059d4c5CompareOctober 1, 2024 20:33
@zuo

zuo commented Oct 1, 2024

Copy link
Copy Markdown
ContributorAuthor

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

Comment threadLib/test/test_strptime.py
@zuo

zuo commented Oct 4, 2024

Copy link
Copy Markdown
ContributorAuthor

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 rruuaanngOctober 11, 2024 05:10
Comment threadLib/test/test_strptime.py
Comment threadLib/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 rruuaanngMarch 3, 2025 02:46
@zuo

zuo commented Mar 3, 2025

Copy link
Copy Markdown
ContributorAuthor

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 threadDoc/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-actionsgithub-actionsBot 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 commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

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.

@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jul 22, 2026
Sign up for freeto 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.

4 participants

@zuo@donbarbos@StanFromIreland@rruuaanng