datetime fold value cleanup on increment
Open
Nobody has claimed this yet.
extension-modules
stdlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Add one microsecond to datetime with fold=1 and this fold is cleanup and we go to the past instead of go to one microsecond ahead
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
tz = ZoneInfo('Europe/Paris')
dt1 = datetime(2025, 10, 26, 2, 0, 1, tzinfo=tz)
print(dt1)
dt2 = datetime(2025, 10, 26, 2, 0, 1, fold=1, tzinfo=tz)
print(dt2)
dt3 = dt2 + timedelta(microseconds=1)
print(dt3)
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python reproduction with datetime, timedelta, and ZoneInfo for Europe/Paris, then inspect the datetime arithmetic and fold behavior involved. Done means adding one microsecond to the fold=1 value produces the immediately later datetime rather than moving into the past.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100