Skip to content

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

Closed
@bombs-kim

Description

@bombs-kim

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

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

Status

Done

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions