gweis / isodate

ISO 8601 date/time parser
BSD 3-Clause "New" or "Revised" License
155 stars 59 forks source link

parse_time exceptions on seconds that are half microsecond to 60 seconds #53

Closed huadongliu closed 2 years ago

huadongliu commented 6 years ago

https://github.com/gweis/isodate/blob/master/src/isodate/isotime.py#L127

import isodate from decimal import Decimal isodate.parse_datetime('2018-09-22T16:14:59.9999994') datetime.datetime(2018, 9, 22, 16, 14, 59, 999999) isodate.parse_datetime('2018-09-22T16:14:59.9999995') Traceback (most recent call last): File "", line 1, in File "/nail/home/hliu/isodate/.tox/py36/lib/python3.6/site-packages/isodate/isodatetime.py", line 56, in parse_datetime tmptime = parse_time(timestring) File "/nail/home/hliu/isodate/.tox/py36/lib/python3.6/site-packages/isodate/isotime.py", line 133, in parse_time tzinfo) ValueError: second must be in 0..59 print(Decimal('59.9999995').quantize(Decimal('.000001'))) 60.000000 print(Decimal('59.9999994').quantize(Decimal('.000001'))) 59.999999

podfran commented 3 years ago

Hi, I'm having the same issue. In C# DateTime.MaxValue is the equivalent of 23:59:59.9999999 UTC which is a one 100-nanosecond (a tenth of a microsecond) before 00:00:00 UTC, January 1, 10000. When that is parsed by isodate.parse_datetime it raises the exception described above - it parses 59.9999999 (7 nines) as 60. Instead I think it should cap at 1 microsecond away from 60 as it seems that is the smallest unit of time datetime.time can express and the full minute is not meant.

gweis commented 2 years ago

fixed in 89f8089