Skip to content

Isoparser misinterprets T24:00 #658

@pganssle

Description

@pganssle

When I originally wrote the ISO 8601 parser, I misinterpreted the standard. From Wikipedia:

Midnight is a special case and may be referred to as either "00:00" or "24:00". The notation "00:00" is used at the beginning of a calendar day and is the more frequently used. At the end of a day use "24:00". "2007-04-05T24:00" is the same instant as "2007-04-06T00:00" (see Combined date and time representations below).

But:

>>> from dateutil.parser import isoparse
>>> isoparse("2007-04-05T24:00")
datetime.datetime(2007, 4, 5, 0, 0)
>>> isoparse("2007-04-06T00:00")
datetime.datetime(2007, 4, 6, 0, 0)

This is a bit tricky to handle because time and date parsing happen separately, so there's no obvious way to increment the date based on the value of the time until after it's parsed (at which point there is no difference between 00:00 and 24:00). I think the right solution is to allow _parse_isotime to return [24, 0, 0, 0, TZINFO], and handle that in parse_isotime and parse_isodatetime accordingly.

It's not clear to me whether the spec allows a bare time representation of "24:00" or if 24:00 is only valid in the context of a datetime. We should do whatever the spec says I think.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions