Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

datetime library doesn't support valid ISO-8601 alternative for midnight #102450

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@TizzySaurus

Description

@TizzySaurus

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

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp