Open
Description
Bug report
Bug description:
Since Python 3.11, datetime.fromisoformat(...)
accepts invalid timestamps. The same code was tested in many Python versions via GitHub Actions:
Wrong format: 2024-01-17T15:21:00-0800
Fixed format: 2024-01-17T15:21:00-08:00
Python code to check:
datetime.fromisoformat("2024-01-17T15:21:00-0800")
ISO 8601 defines 2 formats:
- basic format (in short: without separators) and
- extended format (with separators).
When checking the EBNF rules, all parts of the timestamp must be with or without separators. A mix of formats is not allowed.
I haven't checked for other basic and extended format mixes.
My CI checked many Python versions and platforms. Here a failed CI pipeline, shows a correct implementation. A successful pipeline denotes a buggy Python version.
Other resources:
- datetime.strptime: Support for parsing offsets with a colon #75981
- datetime.fromisoformat(): Omitted colon in timezone suffix raises ValueError #86537
- datetime.fromisoformat incorrectly accepts and parses strings without date-time separator #107779
- parser.isoparse() accepts invalid ISO 8601 timestamps dateutil/dateutil#1341
- ISO 8601 timestamps - basic/extended format mixing adlnet/xAPI-Spec#541
- ISO8601 - Mixed Basic and Extended format bitwalker/timex#98
- ISO 8601 - https://web.archive.org/web/20171019211402/https://www.loc.gov/standards/datetime/ISO_DIS%208601-1.pdf
CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux, macOS, Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
No status