Fix naturaldelta truncating years instead of rounding#295
Open
ArmaanjeetSandhu wants to merge 1 commit intopython-humanize:mainfrom
Open
Fix naturaldelta truncating years instead of rounding#295ArmaanjeetSandhu wants to merge 1 commit intopython-humanize:mainfrom
ArmaanjeetSandhu wants to merge 1 commit intopython-humanize:mainfrom
Conversation
Previously, `naturaldelta` calculated years using integer division (floor), which caused durations close to the next year (e.g., 2.9 years) to be reported incorrectly (e.g., as "2 years"). This commit changes the logic to round the number of years to the nearest integer, consistent with how other units (minutes, hours) are handled and matching the function's docstring. - Update `src/humanize/time.py` to round years. - Add regression test in `tests/test_time.py` for ~2.9 years.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #295 +/- ##
=======================================
Coverage 99.51% 99.51%
=======================================
Files 11 11
Lines 831 832 +1
=======================================
+ Hits 827 828 +1
Misses 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
naturaldeltainsrc/humanize/time.pyto useround()instead of integer division (//) for year calculations. This fixes a bug where 2.9 years was incorrectly formatted as "2 years" instead of "3 years".tests/test_time.pyto verify that a timedelta of 1058 days (~2.9 years) correctly rounds to "3 years".