Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime does not support timestamps after 2038 on 32-bit #101069

Open
bmwiedemann opened this issue Jan 16, 2023 · 6 comments
Open

datetime does not support timestamps after 2038 on 32-bit #101069

bmwiedemann opened this issue Jan 16, 2023 · 6 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@bmwiedemann
Copy link
Contributor

Bug report

cpython on 32-bit platforms cannot handle dates beyond 2038-01-19

python3.10 -c 'import datetime; datetime.datetime.fromtimestamp(3000000000)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
OverflowError: timestamp out of range for platform time_t

Your environment

  • CPython versions tested on: 3.8, 3.9, 3.10
  • Operating system and architecture: openSUSE-Tumbleweed 20230110 i586

This comes from
https://github.com/python/cpython/blob/8e9d08b0/Modules/_datetimemodule.c#L4982
https://github.com/python/cpython/blob/8e9d08b0/Python/pytime.c#L173

These could use __time64_t if available or we compile everything with __TIMESIZE=64

@bmwiedemann bmwiedemann added the type-bug An unexpected behavior, bug, or error label Jan 16, 2023
bmwiedemann added a commit to bmwiedemann/django that referenced this issue Jan 16, 2023
This is a continuation of a92c838

beware python/cpython#101069 :
This currently breaks on i586 with

      File "/usr/lib/python3.8/email/utils.py", line 147, in formatdate
        dt = datetime.datetime.fromtimestamp(timeval, datetime.timezone.utc)
    OverflowError: timestamp out of range for platform time_t

probably from
https://github.com/python/cpython/blob/8e9d08b0/Modules/_datetimemodule.c#L4982
@sobolevn
Copy link
Member

It works on my machine (macOS 10.14) on main:

(.venv) ~/Desktop/cpython  main ✔                                                    
» ./python.exe -c 'import datetime; datetime.datetime.fromtimestamp(3000000000)' 

(.venv) ~/Desktop/cpython  main ✔                                                    
» echo $?                                                                        
0

The same for 3.9:

Python 3.9.15 (main, Nov 22 2022, 17:18:20) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime; datetime.datetime.fromtimestamp(3000000000)
datetime.datetime(2065, 1, 24, 8, 20)

I don't say that this is not a bug, I say that this is totally system-specific.

@mcepl
Copy link
Contributor

mcepl commented Jan 16, 2023

It works on my machine (macOS 10.14) on main:

Is your system 32bit? I doubt it with Mac.

@sobolevn
Copy link
Member

No, it is 64 bit

@bmwiedemann bmwiedemann changed the title datetime does not support timestamps after 2038 datetime does not support timestamps after 2038 on 32-bit Jan 16, 2023
@mcepl
Copy link
Contributor

mcepl commented Feb 6, 2023

No, it is 64 bit

Then your comment is unfortunately irrelevant.

@sobolevn
Copy link
Member

sobolevn commented Feb 6, 2023

@mcepl yeap, that's what I said :)

I don't say that this is not a bug, I say that this is totally system-specific.

@bmwiedemann
Copy link
Contributor Author

I guess, this could be solved outside of python by rebuilding our 32-bit Linuxes with
-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64

So that their (or glibc's) time_t would have 8 bytes.

bmwiedemann added a commit to bmwiedemann/django that referenced this issue Feb 7, 2023
Co-Authored-By: Mariusz Felisiak

This is a continuation of a92c838

To avoid triggering python/cpython#101069
we do not yet set expiration after 2038, but just one year ahead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants