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

Error condition in _datetimemodule.c is unchecked withdatetime.fromtimestamp on local times > Y10k #91581

Closed
@pganssle

Description

@pganssle

On twitter, someone asked about a weird difference in the error messages fromdatetime.fromtimestamp() when called with a timestamp that falls on 10000-01-01 when compared to 10000-01-02. Compare:

$ TZ=UTC python -c "from datetime import *; datetime.fromtimestamp(253402300799 + 1)"Traceback (most recent call last):  File "<string>", line 1, in <module>ValueError: year 0 is out of range$ TZ=UTC python -c "from datetime import *; datetime.fromtimestamp(253402300799 + 1 + 24 * 3600)"Traceback (most recent call last):  File "<string>", line 1, in <module>ValueError: year 10000 is out of range

Turns out that this is because in the localtime-specific implementation ofdatetime.fromtimestamp in_datetimemodule.c, there's an unchecked error condition when callingutc_to_seconds, which fails with-1.

As a practical matter, this always results in basically the same error anyway, since in all situations whereresult_seconds gets set to-1 the subsequent calculations fail anyway, and the only difference is that the error message has a slightly different form, but we may as well fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp