You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
datetime.astimezone() method does not handle invalid local times as required by PEP 495 #83861
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/abalkin'closed_at=Nonecreated_at=<Date2020-02-19.00:56:00.603>labels= ['type-bug', '3.9']
title='datetime.astimezone() method does not handle invalid local times as required by PEP 495'updated_at=<Date2020-02-19.00:56:00.603>user='https://github.com/abalkin'
Activity
abalkin commentedon Feb 19, 2020
Let g be an invalid time in a New York spring-forward gap:
According to PEP-495, conversion of such instance to UTC should return a value that corresponds to a valid local time greater than g, but
>>> print(g.astimezone(timezone.utc).astimezone()) 2020-03-08 01:30:00-05:00Also, conversion of the same instance with fold=1 to UTC and back should produce a lesser time, but
Note that conversion to and from timestamp works correctly:
abalkin commentedon Feb 2, 2023
This bug is still present in the current master:
Note that the same calculation done with explicit zone info gives correct results:
(kudos to @pganssle!)
Fix datetime.astimezone() method (pythongh-83861)
Fix datetime.astimezone() method (pythongh-83861)
gh-83861: Fix datetime.astimezone() method (GH-101545)
Merge branch 'main' into superopt
encukou commentedon Mar 10, 2025
The PR was merged for 3.12, so I'll close.