Skip to content

datetime.fromisoformat() only accepts 3 or 6 decimal places for fractional seconds #95221

Closed
@rdfguy

Description

@rdfguy

The ISO 8601 spec allows any number of decimal places for fractional seconds, but the datetime.fromisoformat() method raises a ValueError if there is a fractional part that has something other than 3 or 6 decimal places (I checked the source code). This causes problems with, for example, Adobe XMP metadata.

This raises a ValueError:

import datetime
datetime.datetime.fromisoformat("2021-06-26T08:34:41.12-05:00")  # only two decimal places

Tested in this environment:

Python 3.8.3 (v3.8.3:6f8c8320e9, May 13 2020, 16:29:34) 
[Clang 6.0 (clang-600.0.57)] on darwin

Metadata

Metadata

Assignees

Labels

3.10only security fixes

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions