Title: bug in dateutil\tz\
Type: enhancement Stage:
Components: Documentation Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: belopolsky, docs@python, jerrykramskoy, louielu, matrixise, steve.dower, tim.peters
Priority: normal Keywords:

Created on 2017-09-01 17:24 by jerrykramskoy, last changed 2017-10-11 16:52 by belopolsky.

Messages (9)
msg301143 - (view) Author: Jerry Kramskoy (jerrykramskoy) Date: 2017-09-01 17:24
Running python 3.6.2 on Windows 10.

The following method causes presents a timetstamp value of -3600 (i.e. DST adjustment of one hour) which causes time.localtime() to raise an OS Errno 22.

    def _naive_is_dst(self, dt):
        timestamp = _datetime_to_timestamp(dt)
        return time.localtime(timestamp + time.timezone).tm_isdst

Reproduce with python shell...

import time
Traceback (most recent call last):
  Python Shell, prompt 7, line 1
builtins.OSError: [Errno 22] Invalid argument

The documentation doesn't specify a legal value range for input to localtime.

Unfortunately,this causes AWS boto3 support for dynamodb to crash.

Cheers, Jerry
msg301219 - (view) Author: Louie Lu (louielu) * Date: 2017-09-04 12:46
Using macOS and Linux can't reproduce this problem, both platform
return this output:

>>> import time
>>> time.localtime(-3600)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=7, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
msg304152 - (view) Author: Stéphane Wirtel (matrixise) * Date: 2017-10-11 15:39
Hi Steve, I have added you on this issue because it's related to Windows.

Maybe you could check it.
msg304154 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2017-10-11 15:48
The docs for the `time` module say:

Although this module is always available, not all functions are available on all platforms. Most of the functions defined in this module call platform C library functions with the same name. It may sometimes be helpful to consult the platform documentation, because the semantics of these functions varies among platforms.

The Windows `localtime()` simply doesn't support dates before the epoch:
msg304155 - (view) Author: Stéphane Wirtel (matrixise) * Date: 2017-10-11 16:00
Thank you Tim,

In this case, the documentation seems to be correct, maybe we could close this issue because it's independent of Python.

What's your opinion on this point?

Close it or Improve the documentation?
msg304159 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2017-10-11 16:22
Since this is a pretty common gotcha, I'd prefer to add it as an example to the text I already quoted; e.g., add:

For example, the native Windows C libraries do not support times before the epoch, and `localtime(n)` for negative `n` raises `OSError` on Windows.
msg304160 - (view) Author: Stéphane Wirtel (matrixise) * Date: 2017-10-11 16:24
Thank you, I will provide a PR for this issue and close it once it's over.
msg304161 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2017-10-11 16:33
I'll just add that it may be a different issue to argue about how `_naive_is_dst()` is implemented.
msg304162 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2017-10-11 16:52
Is this similar to issue 29097?
Date User Action Args
2017-10-11 16:52:47belopolskysetmessages: + msg304162
2017-10-11 16:33:41tim.peterssetnosy: + belopolsky
messages: + msg304161
2017-10-11 16:24:17matrixisesetmessages: + msg304160
2017-10-11 16:22:20tim.peterssetnosy: + docs@python
messages: + msg304159

assignee: docs@python
components: + Documentation, - Library (Lib)
type: crash -> enhancement
2017-10-11 16:00:50matrixisesetmessages: + msg304155
2017-10-11 15:48:49tim.peterssetnosy: + tim.peters
messages: + msg304154
2017-10-11 15:39:49matrixisesetnosy: + matrixise, steve.dower
messages: + msg304152
2017-09-04 12:46:51louielusetnosy: + louielu
messages: + msg301219
2017-09-01 17:24:09jerrykramskoycreate