Skip to content

datetime.fromtimestamp(t).astimezone() fails for 0<=t<86400 in Windows #107078

@LefterisJP

Description

@LefterisJP

Bug report

dt.datetime.fromtimestamp(t).astimezone() fails for 0<=t<86400 in Windows for at least python 3.9, 3.10, 3.11.
Works fine in Linux, Mac.

>> import datetime as dt
>> dt.datetime.fromtimestamp(0)
datetime.datetime(1970, 1, 1, 1, 0)

>> dt.datetime.fromtimestamp(86400)
datetime.datetime(1970, 1, 2, 1, 0)

>> dt.datetime.fromtimestamp(0).astimezone()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

>> dt.datetime.fromtimestamp(86399).astimezone()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

>> dt.datetime.fromtimestamp(86400).astimezone()
datetime.datetime(1970, 1, 2, 1, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'W. Europe Standard Time'))

A screenshot also:
F1qM1ZmXgAAVrTw

Your environment

  • CPython versions tested on: 3.9, 3.10, 3.11
  • Operating system and architecture: Windows

Additional information

This looks very very related to this issue: #73283 but now it seems to happen for astimezone.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions