Skip to content

Preserve fractional timedelta seconds until formatting - #1401

Open
nawaaaaaAaar wants to merge 1 commit into
python-babel:masterfrom
nawaaaaaAaar:fix/timedelta-subsecond-precision
Open

nawaaaaaAaar wants to merge 1 commit into
python-babel:masterfrom
nawaaaaaAaar:fix/timedelta-subsecond-precision

Conversation

@nawaaaaaAaar

@nawaaaaaAaar nawaaaaaAaar commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1400.

Keep timedelta fractional seconds through the existing formatting logic by using total_seconds(). This is independent of the compound-unit change in #1399; this branch starts from unchanged upstream and contains no changes from that PR.

Before/after

Unchanged upstream: e2a17919f0eb988bfea2883b00793ca4d5d37c4f.

Previously, timedelta.days * 86400 + timedelta.seconds drops microseconds and floors negative durations:

  • Plus 0.5 seconds: “in 0 seconds”; minus 0.5 seconds: “1 second ago”.
  • Plus 1.9 seconds: “1 second”; minus 1.9 seconds: “2 seconds”.
  • Plus 50.999999 seconds: “50 seconds”; minus the same magnitude: “1 minute”.

Retaining the full signed duration lets the existing rounding, threshold and minimum-unit logic handle both signs consistently, without introducing a second rounding policy.

The final regression/control matrix produces sixteen failures and twenty-eight passes against unchanged production code. It checks both signs, direction on/off, fractional rounding boundaries, the minute threshold, zero, integral durations and the maximum whole-second positive timedelta.

Verification

  • Full suite on Python 3.12.13: 7,875 passed, seven skipped, two expected failures, one existing pytest deprecation warning.
  • All 44 added regression/control cases pass.
  • All 56 date-module doctests pass.
  • Full Ruff check, source/wheel builds and whitespace checks pass.
  • An isolated installed-wheel smoke test passes on Python 3.11.15, imported outside the checkout.
  • Tested together with Respect preformatted string numerators in compound-unit formatting #1399 in a separate worktree: 7,893 passed, seven skipped, two expected failures, one existing pytest warning, with full Ruff checks passing. The submitted branches remain independent.

CLDR 48.2 data was imported using the repository's download/import script and checksum validation. Local verification is Linux-only and does not claim every supported runtime or hosted CI passed.

Assistance

Investigated, implemented and tested with AI assistance. No personal account-owner review or provenance attestation is asserted.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

format_timedelta loses fractional seconds and rounds negative durations asymmetrically

2 participants