Skip to content

[3.15] gh-159739: Preserve large years in time conversions (GH-160175) - #161649

Open
miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-e1a4c15-3.15
Open

miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-e1a4c15-3.15

Conversation

@miss-islington

Copy link
Copy Markdown
Contributor

The time module added 1900 to the C library year using int arithmetic, which overflowed for timestamps whose calendar year exceeds INT_MAX. On platforms that accept these timestamps, gmtime(), localtime(), and ctime() could report a negative year; perform the addition in a wider type. Backport to 3.15 and 3.14.

Time tuple consumers parsed calendar years as C int before subtracting 1900, so they rejected valid struct_time results. Date and datetime timestamp conversion could also overflow before reporting the invalid year. Preserve the full time tuple range and report oversized datetime years correctly. Backport to 3.15 and 3.14.
(cherry picked from commit e1a4c15)

Co-authored-by: Jelle Zijlstra jelle@openai.com

…60175)

* pythongh-159739: Preserve large years in time conversions

The time module added 1900 to the C library year using int arithmetic, which overflowed for timestamps whose calendar year exceeds INT_MAX. On platforms that accept these timestamps, gmtime(), localtime(), and ctime() could report a negative year; perform the addition in a wider type. Backport to 3.15 and 3.14.

* pythongh-159739: Round-trip large years and validate datetime timestamps

Time tuple consumers parsed calendar years as C int before subtracting 1900, so they rejected valid struct_time results. Date and datetime timestamp conversion could also overflow before reporting the invalid year. Preserve the full time tuple range and report oversized datetime years correctly. Backport to 3.15 and 3.14.
(cherry picked from commit e1a4c15)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants