Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
According toISO-8601, a time of24:00 on a given date is a valid alternative to00:00 of the following date, however Python does not support this, raising the following error when attempted:ValueError: hour must be in 0..23.
This bug can be seen from multiple scenarios, specifically anything that internally calls the_check_time_fields function, such as the following:
>>>importdatetime>>>datetime.datetime(2022,1,2,24,0,0)# should be equivalent to 2022-01-03 00:00:00Traceback (mostrecentcalllast):File"<pyshell#2>",line1,in<module>datetime.datetime(2022,3,4,24,0,0)ValueError:hourmustbein0..23
The fix for this is relatively simple: have an explicit check within_check_time_fields for the scenario wherehour == 24 and minute == 0 and second == 0 and microsecond == 0, or more conciselyhour == 24 and not any((minute, second, microsecond)), and in this scenario increase the day by one (adjusting the week/month/year as necessary) and set the hour to 0.
I imagine thecheck_time_args C function would also have to be updated.
Your environment
- CPython versions tested on: 3.9.12, 3.10.7, 3.11.2 (presumably applies to all)
- Operating system and architecture: MacOS Ventura arm64 (presumably applies to all)
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status