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.

classification
Title: datetime.datetime.fromtimestamp(0, tzlocal()) throws error
Type: crash Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: ThePokestarFan, ammar2, belopolsky, corona10, mzhang13, p-ganssle
Priority: normal Keywords:

Created on 2019-10-30 15:07 by mzhang13, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (9)
msg355720 - (view) Author: Michael Zhang (mzhang13) Date: 2019-10-30 15:07
Discovered this while trying to use a function in `boto3`. Seems like when tzlocal() is passed with a 0 to datetime.datetime.fromtimestamp(), it throws an "[Errno 22] Invalid argument" error. Using 3.7.4 via Anaconda on Windows 10, and tzlocal().tznames's local timezone for me is EST/EDT.

Can replicate through this:
```
import datetime
from dateutil.tz import tzlocal

print(datetime.datetime.fromtimestamp(0, tzlocal()))
```
msg355772 - (view) Author: (ThePokestarFan) * Date: 2019-10-31 21:46
For me, it seems that dateutil is not a standard Python library module. When I run `import dateutil` it reports that there is no module called dateutil.

```
>>> import dateutil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named dateutil
```
msg355780 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2019-11-01 01:56
Python 3.9.0a0 (heads/master:112f2b805b, Nov  1 2019, 10:48:20)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> utc_tzinfo = datetime.timezone.utc
>>> print(datetime.datetime.fromtimestamp(0, utc_tzinfo))
1970-01-01 00:00:00+00:00

works properly on my Linux machine.
Can you gave me which can reproduce based on stdlib library?
msg355783 - (view) Author: Michael Zhang (mzhang13) Date: 2019-11-01 02:53
I think it might be something Windows specific; the original comment includes the version and code to reproduce.
msg355784 - (view) Author: (ThePokestarFan) * Date: 2019-11-01 02:59
Can you run

>>>import dateutil
>>>print(repr(dateutil))
msg355785 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-11-01 03:00
It is windows specific, but I don't think this is a dateutil bug rather than the python stdlib:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> from dateutil.tz import tzlocal
>>> print(datetime.datetime.fromtimestamp(0, tzlocal()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 144, in fromutc
    return f(self, dt)
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 258, in fromutc
    dt_wall = self._fromutc(dt)
  File "D:\Python365\lib\site-packages\dateutil\tz\_common.py", line 238, in _fromutc
    dtdst = enfold(dt, fold=1).dst()
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 225, in dst
    if self._isdst(dt):
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 288, in _isdst
    if self.is_ambiguous(dt):
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 250, in is_ambiguous
    (naive_dst != self._naive_is_dst(dt - self._dst_saved)))
  File "D:\Python365\lib\site-packages\dateutil\tz\tz.py", line 254, in _naive_is_dst
    return time.localtime(timestamp + time.timezone).tm_isdst
OSError: [Errno 22] Invalid argument


As you can see, none of that backtrace is within Python, it's all inside dateutil code. More than likely they are calling `time.localtime` with a value of less than 0 which throws an error on Windows. (see also issue29097)
msg355786 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-11-01 03:01
Err...I mean I think this is a dateutil bug rather than in the Python stdlib.
msg355787 - (view) Author: Michael Zhang (mzhang13) Date: 2019-11-01 03:03
Yeah, seconded with my own tracing as well.
msg355788 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-11-01 03:11
Closing, here's the bug in dateutil's repo: https://github.com/dateutil/dateutil/issues/197
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82826
2019-11-01 03:11:09ammar2setstatus: open -> closed
resolution: third party
messages: + msg355788

stage: resolved
2019-11-01 03:03:01mzhang13setmessages: + msg355787
2019-11-01 03:01:19ammar2setmessages: + msg355786
2019-11-01 03:00:30ammar2setnosy: + ammar2
messages: + msg355785
2019-11-01 02:59:08ThePokestarFansetmessages: + msg355784
2019-11-01 02:53:46mzhang13setmessages: + msg355783
2019-11-01 01:56:14corona10setnosy: + corona10
messages: + msg355780
2019-10-31 21:46:53ThePokestarFansetnosy: + ThePokestarFan
messages: + msg355772
2019-10-30 15:09:43xtreaksetnosy: + belopolsky, p-ganssle
2019-10-30 15:07:25mzhang13create