This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: datetime.fromtimestamp raises OSError on first day after epoch on Windows
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.7, Python 3.6
Status: closed Resolution: duplicate
Dependencies: Superseder: [Windows] datetime.fromtimestamp(t) when 0 <= t <= 86399 fails on Python 3.6
View: 29097
Assigned To: Nosy List: belopolsky, eryksun, lazka, paul.moore, r.david.murray, steve.dower, tim.golden, tim.peters, zach.ware
Priority: normal Keywords:

Created on 2017-06-16 12:55 by lazka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg296191 - (view) Author: Christoph Reiter (lazka) * Date: 2017-06-16 12:55
I'm not sure this is a bug since the docs says raising OSError is allowed, but it looks weird to me.

On Windows.

Using Python 3.4:

>>> datetime.datetime.fromtimestamp(0)
datetime.datetime(1970, 1, 1, 1, 0)

Using Python 3.6.1:

>>> datetime.datetime.fromtimestamp(0)
OSError: [Errno 22] Invalid argument

The first time stamp which works with 3.6 is 86400, so exactly the next day.
msg296196 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2017-06-16 14:34
This is due to computing the PEP 495 fold in the function datetime_from_timet_and_us in Modules/_datetimemodule.c. It computes the local time for (timet - max_fold_seconds), which is negative for timestamps less than max_fold_seconds (86400). It's documented that localtime_s [1] fails for negative time values. For example:

    0:000> kc 6
    Call Site

Dereference the time_t* arg (-86400):

    0:000> ?? *(int64_t *)@rdx
    int64 0n-86400

Print the errno_t return value (0x16 is EINVAL):

    0:000> pt; r rax

msg296213 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-16 17:06
This appears to be a duplicate of issue 29097.
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74869
2017-06-16 17:06:14r.david.murraysetstatus: open -> closed

superseder: [Windows] datetime.fromtimestamp(t) when 0 <= t <= 86399 fails on Python 3.6

nosy: + r.david.murray
messages: + msg296213
resolution: duplicate
stage: resolved
2017-06-16 14:34:01eryksunsetversions: + Python 3.7
nosy: + eryksun, belopolsky, tim.peters, paul.moore, tim.golden, zach.ware, steve.dower

messages: + msg296196

components: + Library (Lib), Windows
type: behavior
2017-06-16 12:55:21lazkacreate