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

Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns #127552

Closed
bombs-kim opened this issue Dec 3, 2024 · 4 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@bombs-kim
Copy link
Contributor

bombs-kim commented Dec 3, 2024

found a comment in _strptime.py that I believe is unnecessary and potentially outdated:

#XXX: Does 'Y' need to worry about having less or more than

The comment reads:
# XXX: Does 'Y' need to worry about having less or more than 4 digits?

This question seems irrelevant based on the current documentation and implementation standards. Here are my reasons:

  1. Python documentation specifies a 4-digit restriction
    The Python documentation for datetime.strptime states: The strptime() method can parse years in the full [1, 9999] range, but years < 1000 must be zero-filled to 4-digit width. This makes it clear that Y is explicitly designed for 4-digit years only.

  2. Supporting more than 4 digits is impractical
    Years with 5 or more digits cannot be represented in the resulting datetime type. The datetime implementation enforces the [1, 9999] year range, which inherently limits support for larger year values.

  3. Support for fewer than 4 digits tends to not standard-compliant
    Some popular specifications expect a minimum of 4 digits for representing a year:

  • ISO 8601: Requires at least 4 digits for year representation.
  • RFC 3339: Also requires at least 4 digits for the year.
  • POSIX.1-2008: While the standard doesn’t explicitly mandate the number of digits for %Y, implementations commonly expect 4 digits as a minimum.

Given these points, I propose removing the comment as it no longer adds value and could potentially confuse contributors or maintainers. If desired, I can submit a pull request to address this.

Linked PRs

@bombs-kim bombs-kim added the docs Documentation in the Doc dir label Dec 3, 2024
@terryjreedy
Copy link
Member

@brettcannon git blame says you added this comment in 2003 in commit 474335c

@brettcannon brettcannon self-assigned this Dec 3, 2024
@brettcannon
Copy link
Member

Actually that comment was moved in 2003, but it came into existence in Dec 2002, so just shy of 22 years ago. 😅

Anyway, since the implementation has required 4 digits since my code was first committed in July 2002, I think it's safe to say that the comment is no longer necessary. 😁

@bombs-kim if you want to do a PR then go for it! Otherwise I'm assigning this to myself not to forget about it.

@serhiy-storchaka
Copy link
Member

Glibc implementation of strftime() can produce less than 4 digits. So currently strptime() is not compatible with system strftime(). There are some workarounds for datetime, but in the time module this is still an unsolved issue.

@bombs-kim
Copy link
Contributor Author

@brettcannon
Thank you for the context on the comment’s history! I’d be happy to submit a PR to remove it. I’ll proceed with that shortly.

@serhiy-storchaka
I think you raise a valid point about compatibility with strftime() in some systems. However, I believe that specific issue might be better addressed in a separate issue or discussion, as it goes beyond the scope of this comment removal?

brettcannon pushed a commit that referenced this issue Dec 4, 2024
…datetime.strptime patterns (#127590)

The code has required 4 digits for the year since its inclusion in the stdlib in 2002 (over 22 years ago as of this commit).
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 5, 2024
…Y’ in datetime.strptime patterns (pythonGH-127590)

The code has required 4 digits for the year since its inclusion in the stdlib in 2002 (over 22 years ago as of this commit).
(cherry picked from commit 51cfa56)

Co-authored-by: Beomsoo Kim <beoms424@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 5, 2024
…Y’ in datetime.strptime patterns (pythonGH-127590)

The code has required 4 digits for the year since its inclusion in the stdlib in 2002 (over 22 years ago as of this commit).
(cherry picked from commit 51cfa56)

Co-authored-by: Beomsoo Kim <beoms424@gmail.com>
brettcannon pushed a commit that referenced this issue Dec 6, 2024
…‘Y’ in datetime.strptime patterns (GH-127590) GH-127650)

gh-127552: Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns (GH-127590)

The code has required 4 digits for the year since its inclusion in the stdlib in 2002 (over 22 years ago as of this commit).
(cherry picked from commit 51cfa56)

Co-authored-by: Beomsoo Kim <beoms424@gmail.com>
cfbolz pushed a commit that referenced this issue Dec 10, 2024
…‘Y’ in datetime.strptime patterns (GH-127590) (#127649)

gh-127552: Remove comment questioning 4-digit restriction for ‘Y’ in datetime.strptime patterns (GH-127590)

The code has required 4 digits for the year since its inclusion in the stdlib in 2002 (over 22 years ago as of this commit).
(cherry picked from commit 51cfa56)

Co-authored-by: Beomsoo Kim <beoms424@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

4 participants