Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct error in humanize() granularities for single seconds #748

Merged
merged 7 commits into from Jan 3, 2020
Merged

Correct error in humanize() granularities for single seconds #748

merged 7 commits into from Jan 3, 2020

Conversation

jadchaar
Copy link
Member

@jadchaar jadchaar commented Jan 2, 2020

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!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

Replaces: #726
Closes: #727
Closes: #697

@codecov-io
Copy link

codecov-io commented Jan 2, 2020

Codecov Report

Merging #748 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #748   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           9      9           
  Lines        1667   1669    +2     
  Branches      281    282    +1     
=====================================
+ Hits         1667   1669    +2
Impacted Files Coverage Δ
arrow/locales.py 100% <ø> (ø) ⬆️
arrow/arrow.py 100% <100%> (ø) ⬆️

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 bc5ecef...94d71e6. Read the comment docs.

@systemcatch systemcatch changed the title Humanize locale tweaks Correct error in humanize() granularities for single seconds Jan 2, 2020
@systemcatch
Copy link
Collaborator

@jadchaar both bugs look fixed now.

(arrow) chris@ThinkPad:~/arrow$ python
Python 3.7.4 (default, Sep 19 2019, 11:01:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> now=arrow.utcnow()
>>> mins=now.shift(seconds=-200)
>>> mins.humanize(now, only_distance=True)
'3 minutes'
>>> mins.humanize(now, only_distance=True, granularity="second")
'200 seconds'
>>> mins.humanize(now, granularity="second")
'200 seconds ago'
(arrow) chris@ThinkPad:~/arrow$ python
Python 3.7.4 (default, Sep 19 2019, 11:01:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> now=arrow.utcnow()
>>> mins=now.shift(seconds=-200)
>>> mins.humanize(now, only_distance=True)
'3 minutes'
>>> mins.humanize(now, only_distance=True, granularity="second")
'200 seconds'
>>> mins.humanize(now, granularity="second")
'200 seconds ago'
>>> import datetime, arrow
>>> yesterday = datetime.datetime.now()-datetime.timedelta(1)
>>> yesterday_date = yesterday.date()
>>> arrow.get(yesterday_date).humanize()
'a day ago'

Copy link
Collaborator

@systemcatch systemcatch left a comment

Choose a reason for hiding this comment

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

Solid PR, I can't believe the seconds thing was missed for so long.

arrow/arrow.py Outdated Show resolved Hide resolved
@@ -2793,6 +2825,7 @@ class CzechLocale(Locale):

timeframes = {
"now": "Teď",
"second": {"past": "vteřina", "future": "vteřina", "zero": "vteřina"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can rely on others to correct these kinds of locales.

Comment on lines -942 to +943
elif diff < 129600:
# anything less than 48 hours should be 1 day
elif diff < 172800:
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@systemcatch systemcatch left a comment

Choose a reason for hiding this comment

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

🚀

@systemcatch systemcatch merged commit 6adb8db into arrow-py:master Jan 3, 2020
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.

humanize granularity doesn't behave as expected .humanize() leads to wrong result with datetime.date
3 participants