Skip to content

fix precisedelta dropping sign of negative timedeltas (fixes #379) - #395

Closed
aDragon0707 wants to merge 3 commits into
python-humanize:mainfrom
aDragon0707:fix-379
Closed

aDragon0707 wants to merge 3 commits into
python-humanize:mainfrom
aDragon0707:fix-379

Conversation

@aDragon0707

Copy link
Copy Markdown

Fixes #379.

precisedelta() silently dropped the sign of negative timedeltas — the output was byte-identical to the positive counterpart (1 hour, 1 minute and 1 second for both -3661 and +3661 seconds).

  • Detect a negative value before _date_and_delta, then prefix - on the rendered result.
  • Zero stays 0 seconds (no -0).
  • Positive inputs are unchanged.

Regression test added (test_precisedelta_negative): seconds, positive control, and minimum_unit="minutes".

tests/test_time.py → 388 passed, 0 failed.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (2ad3641) to head (0522fed).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #395   +/-   ##
=======================================
  Coverage   99.56%   99.57%           
=======================================
  Files          12       12           
  Lines         927      938   +11     
=======================================
+ Hits          923      934   +11     
  Misses          4        4           
Flag Coverage Δ
macos-latest 97.65% <100.00%> (+0.02%) ⬆️
ubuntu-latest 97.65% <100.00%> (+0.02%) ⬆️
windows-latest 95.52% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugovk

hugovk commented Sep 16, 2026

Copy link
Copy Markdown
Member

Fixes #379.

If you open this issue, you'll see there's already an open PR for this: #380.

Please check next time, I'm getting so many duplicates that it wastes review time that can be spent elsewhere.

@hugovk hugovk closed this Sep 16, 2026
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.

precisedelta() silently drops the sign of negative timedeltas

2 participants