python / python/cpython

datetime fold value cleanup on increment

Open
#137,752 4 comments 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.