FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix handling of negative time deltas by hugovk · Pull Request #173 · python-humanize/humanize · GitHub

Fix handling of negative time deltas - #173

Merged
hugovk merged 5 commits into
python-humanize:mainfrom
hugovk:fix-small-timedelta
Feb 25, 2024
Merged

Fix handling of negative time deltas#173
hugovk merged 5 commits into
python-humanize:mainfrom
hugovk:fix-small-timedelta

Conversation

hugovk commented Feb 24, 2024
edited
Loading

Copy link
Copy Markdown
Member

Fixes #18.
Fixes #171.

The Python docs say:

String representations of timedelta objects are normalized similarly to their internal representation. This leads to somewhat unusual results for negative timedeltas. For example:

>>> timedelta(hours=-5)
datetime.timedelta(days=-1, seconds=68400)
>>> print(_)
-1 day, 19:00:00

However, we assumed all components have the same sign, and used absolute values of some of those, leading to inconsistent behaviour (on Linux and macOS; it still worked on Windows).

Instead, we should convert the whole timedelta into its absolute value, and then use its components directly.

Also test all the timedeltas with positive and negative values.

Because a small delta can be represented as timedelta(days=-1, seconds=86399, microseconds=999999), so we should assume all components have the same sign
hugovk added bug Something isn't working changelog: Fixed For any bug fixes labels Feb 24, 2024

codecov Bot commented Feb 24, 2024
edited
Loading

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.19%. Comparing base (584d470) to head (ec99f29).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #173   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files           9        9           
  Lines         746      747    +1     
=======================================
+ Hits          740      741    +1     
  Misses          6        6           
Flag Coverage Δ
macos-latest 97.59% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 97.59% <100.00%> (+<0.01%) ⬆️
windows-latest 96.11% <100.00%> (+<0.01%) ⬆️

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

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

hugovk merged commit 218a86e into python-humanize:main Feb 25, 2024
hugovk deleted the fix-small-timedelta branch February 25, 2024 15:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative amounts of time result in a day from naturaldelta naturaldelta with negative seconds loses precision and doesn't match naturaltime

1 participant


Back | FazBrowse Home | New Git URL