Skip to content

datetime.fromisoformat() accepts day 0 and year 0 combined with a 24:00 time #162306

Open

Description

@choam2426

Bug report

Bug description:

datetime.fromisoformat() accepts a day of 00 or a year of 0000 when the time is 24:00, and returns the following date instead of raising ValueError. With any other time, the same dates are rejected.

>>> from datetime import datetime
>>> datetime.fromisoformat("2026-06-00T23:00")
Traceback (most recent call last):
  ...
ValueError: day 0 must be in range 1..30 for month 6 in year 2026
>>> datetime.fromisoformat("2026-06-00T24:00")
datetime.datetime(2026, 6, 1, 0, 0)
>>> datetime.fromisoformat("0000-12-31T24:00")
datetime.datetime(1, 1, 1, 0, 0)

The C and pure-Python implementations behave the same. Before rolling 24:00 over to the next day, both check the month range and that the day is not past the end of the month, but not that the day is at least 1 or that the year is at least MINYEAR. The rolled-over date is valid, so the constructor accepts it.

gh-151770 added the missing lower bound for the month in the same check. This is the same gap for the day and the year. I have a fix with tests and will open a PR.

3.13 and earlier are not affected because they reject hour 24 (support came with gh-102450). Reproduced on 3.14.10 and 3.15.2 (Windows), 3.14.7 (Linux), and a debug build of main at b09a7e9 (Linux).

CPython versions tested on:

3.14, 3.15, CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

Activity

  1. added
    extension-modules
    stdlib
    type-bug
    on Nov 20, 2026
  2. added a commit that references this issue on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesstdlibtype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions