Skip to content

Format precise durations without calendar date limits - #448

Open
xiehuanyi wants to merge 1 commit into
python-humanize:mainfrom
xiehuanyi:fix-large-precise-durations
Open

xiehuanyi wants to merge 1 commit into
python-humanize:mainfrom
xiehuanyi:fix-large-precise-durations

Conversation

@xiehuanyi

Copy link
Copy Markdown

precisedelta(timedelta(days=4_000_000)) currently raises OverflowError: date value out of range. The duration itself is valid; the failure comes from constructing a calendar date that this formatter never uses. The same limit affects numeric seconds and timedelta.min/timedelta.max.

Operate directly on absolute timedeltas for duration inputs, retaining the existing relative-date path for datetime inputs. Annotate the unit accumulators as float because unit suppression and minimum-unit rounding can produce fractional counts.

Six regressions cover signed4-million-day timedeltas, the corresponding numeric seconds, and the timedelta bounds. All six fail before the fix. Afterward,735 behavior/doctest cases pass with112 translation-related skips, strict mypy . passes, all repository prek hooks pass, and git diff --check passes. Performance benchmarks were excluded from this behavior run.

Prepared with AI assistance.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 18:22

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.

@Wkhanex Wkhanex 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.

I checked 31 standalone cases across signed durations and numeric seconds, including 4,000,000 and 999,999,999 days, timedelta.min/max, invalid-input fallbacks and fractional seconds retained beside a large day count. All passed. The result for timedelta.max at minimum_unit='days' was 1000000000 days, reflecting rounding rather than a calendar-date overflow.

I also checked minimum_unit='seconds' with years/months/hours/minutes suppressed: both one day and 999,999,999 days retained the additional 0.50 seconds. For this source checkout I supplied only the build-generated version metadata module as a stub; the time formatter itself was unchanged.

I used Python 3.12.14 against commit cb8ced7. These were focused checks, not a full-suite run.

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.

3 participants