Skip to content

fix: preserve microsecond precision in Duration for large values#969

Open
SAY-5 wants to merge 1 commit into
python-pendulum:masterfrom
SAY-5:fix-duration-microsecond-precision
Open

fix: preserve microsecond precision in Duration for large values#969
SAY-5 wants to merge 1 commit into
python-pendulum:masterfrom
SAY-5:fix-duration-microsecond-precision

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Fixes #332.

Duration derived its normalized microseconds/seconds/days fields from total_seconds(), which returns a float and loses precision for large values:

>>> pendulum.duration(microseconds=8999999999999999).microseconds
999998  # datetime.timedelta returns 999999

The normalization now works on exact integer microseconds taken from the parent timedelta fields, matching datetime.timedelta behavior. The same float-precision issue in AbsoluteDuration (used by Time.diff()) is fixed the same way.

No documentation change needed; this restores the documented microseconds semantics.

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@codspeed-hq

codspeed-hq Bot commented May 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 1 untouched benchmark


Comparing SAY-5:fix-duration-microsecond-precision (fa6a987) with master (b99bd14)

Open in CodSpeed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant