fix: naturaldelta includes months when years > 1 and months=True#350
Open
amitmishra11 wants to merge 2 commits into
Open
fix: naturaldelta includes months when years > 1 and months=True#350amitmishra11 wants to merge 2 commits into
amitmishra11 wants to merge 2 commits into
Conversation
The final branch of naturaldelta (years > 1) always returned a bare
year count even when months=True. A TODO comment in the code already
identified this gap. Now, when use_months is True and the remaining
days round to 1-11 months, the output includes the month count
('4 years, 7 months'). When they round to 12 months the year count
is incremented instead, consistent with the years == 1 branch.
Test expectations updated to reflect the corrected output.
Fixes python-humanize#108
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #350 +/- ##
==========================================
- Coverage 99.56% 99.34% -0.22%
==========================================
Files 12 12
Lines 913 920 +7
==========================================
+ Hits 909 914 +5
- Misses 4 6 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 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.
Fixes #108
Changes proposed in this pull request:
naturaldelta(years > 1) now respectsmonths=Trueby appending the month count when0 < num_months < 12, and rolls over to the next year whennum_months == 12— consistent with theyears == 1branch.Summary
naturaldelta(timedelta(days=int(4.6*365)), months=True)returned"4 years"instead of"4 years, 7 months". A# TODOcomment in the source already identified this gap.Changes
src/humanize/time.py: resolve the TODO at the end ofnaturaldelta; handlenum_months == 12rollover for theyears > 1branchtests/test_time.py: update stale expectations to reflect the corrected output (e.g."2 years"->"2 years, 1 month","27 years"->"27 years, 5 months")Testing
Fixes #108