python / python/cpython

datetime does not support timestamps after 2038 on 32-bit

Open
#101,069 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the timestamp handling in Modules/_datetimemodule.c around line 4982 and Python/pytime.c around line 173, with the reported 32-bit openSUSE environment in mind. Determine how the implementation can use 64-bit time support where available, then verify that datetime.fromtimestamp(3000000000) succeeds on 32-bit platforms without the reported overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux, python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.