python / python/cpython

datetime does not support timestamps after 2038 on 32-bit

未关闭
#101,069 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

extension-modules type-bug
主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 Modules/_datetimemodule.c 中第 4982 行附近以及 Python/pytime.c 中第 173 行附近的时间戳处理代码,同时考虑报告中的 32 位 openSUSE 环境。确定实现如何在可用时使用 64 位时间支持,然后验证 datetime.fromtimestamp(3000000000) 在 32 位平台上能够成功执行,且不会出现报告中的溢出问题。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, linux, python
领域
operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。