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: time.localtime returns error for negative values
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, mba, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2019-01-21 11:32 by mba, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg334132 - (view) Author: Mba (mba) Date: 2019-01-21 11:32
Steps to reproduce the bug:
```
>>> import sys
>>> sys.version
'3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)]'

>>> import datetime
>>> print(datetime.datetime.now().astimezone().tzinfo)
datetime.timezone(datetime.timedelta(0, 3600), 'Central European Standard Time')

>>> import time
>>> time.localtime(0)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.localtime(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
```

On Ubuntu it works fine:
```
>>> time.localtime(-1)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=59, tm_sec=59, tm_wday=3, tm_yday=1, tm_isdst=0)
```
msg334133 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-21 11:42
It's a limitation of the Windows C library. I'm quite sure that Python 2 has a the same issue, it shouldn't be a regression.
msg335188 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-02-11 02:22
Victor is correct, this is a limitation in Windows. As the documentation for time notes:

>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.

https://docs.python.org/3/library/time.html#module-time

And as the Windows documentation notes: 

>less than 0 or greater than _MAX__TIME64_T: EINVAL

https://msdn.microsoft.com/en-us/library/a442x3ye.aspx?f=255&MSPPError=-2147217396
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 79977
2019-02-11 02:22:30ammar2setstatus: open -> closed

nosy: + ammar2
messages: + msg335188

resolution: not a bug
stage: resolved
2019-01-21 11:42:35vstinnersetnosy: + vstinner
messages: + msg334133
2019-01-21 11:32:19mbacreate