Skip to content

fix edge case for humanize month - #894

Closed
devchilll wants to merge 4 commits into
arrow-py:masterfrom
devchilll:humanize
Closed

fix edge case for humanize month#894
devchilll wants to merge 4 commits into
arrow-py:masterfrom
devchilll:humanize

Conversation

@devchilll

@devchilll devchilll commented Dec 10, 2020

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

Description of Changes

Added edge case handling for the humanize method to describe the delta of both 30 days and 31 days as "1 month".

For instance,

dt=arrow.get("2020-11-08T15:12:18.911919+00:00")
later=dt.shift(months=+1)
print(dt.humanize(later))
print(later.humanize(dt))

should print

a month ago
in a month

Closes: #749

@codecov

codecov Bot commented Dec 10, 2020

Copy link
Copy Markdown

Codecov Report

Merging #894 (0e76c3e) into master (e521f27) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #894   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines         1817      1819    +2     
  Branches       320       321    +1     
=========================================
+ Hits          1817      1819    +2     
Impacted Files Coverage Δ
arrow/arrow.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e521f27...0e76c3e. Read the comment docs.

@systemcatch systemcatch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem now @yiransii is that we get this happening.

>>> import arrow
>>> dt1=arrow.utcnow()
>>> dt2=dt1.shift(days=+29)
>>> dt1
<Arrow [2020-12-15T19:38:49.844060+00:00]>
>>> dt2
<Arrow [2021-01-13T19:38:49.844060+00:00]>
>>> dt1.humanize(dt2)
'a month ago'
>>> dt2.humanize(dt1)
'in a month'

Where as on master we still get the correct result.

>>> dt1.humanize(dt2)
'4 weeks ago'
>>> dt2.humanize(dt1)
'in 4 weeks'

@systemcatch

Copy link
Copy Markdown
Collaborator

Hey @yiransii I'll close this for now, let me know if you want to take it up again.

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.

Refactor humanize() method, expand usage, fix edge cases

2 participants