ciso8601
ciso8601 copied to clipboard
Incorrect parsing "24" hour
Hello!
Stumbled on this strange behavior, consider myself as a bug, what do you think?
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ciso8601
>>> ciso8601.parse_datetime("2020-02-28T23:00:00Z")
datetime.datetime(2020, 2, 28, 23, 0, tzinfo=datetime.timezone.utc)
>>> ciso8601.parse_datetime("2020-02-28T24:00:00Z")
datetime.datetime(2020, 2, 29, 0, 0, tzinfo=datetime.timezone.utc)
>>> ciso8601.parse_datetime("2020-02-28T25:00:00Z")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: hour must be in 0..23
It is not only passes "24" hour, but also returns different date. Logic is obvious (next day, 00 hour), but behavior is incorrect IMHO
"2020-02-28T24:00:00Z" != datetime.datetime(2020, 2, 29, 0, 0, tzinfo=datetime.timezone.utc)
Also, 24 is not in range 00..23
This actually was a valid ISO 8601 datetime.
Prior to ISO 8601-1:2019
, 24:00
was a valid time in ISO 8601.
However, as of ISO 8601-1:2019
, it has been explicitly disallowed.
We haven't figured out how exactly to handle this evolution of the specification within ciso8601
's interface.
Tracking this in #100