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

naturaldelta rounds down the months #116

Closed
ghost opened this issue Feb 24, 2020 · 2 comments
Closed

naturaldelta rounds down the months #116

ghost opened this issue Feb 24, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 24, 2020

this should be 5 months

>> import humanize
>> humanize.naturaldelta(13140015)
'4 months'
@hugovk hugovk changed the title naturaldelta naturaldelta rounds down the months Feb 24, 2020
@hugovk
Copy link
Collaborator

hugovk commented Feb 24, 2020

Thanks for the report.

13140015 is 2019-09-25 07:36:15.471987, which right now is 152 days ago.

This is the relevant part of the code:

    months = int(days // 30.5)

Which works out like:

>>> 152 / 30.5
4.983606557377049
>>> 152 // 30.5
4.0
>>> int(152 // 30.5)
4

So it's rounding down, to report the number of full months that has elapsed.

@ghost ghost closed this as completed May 25, 2020
@luisgc93
Copy link

luisgc93 commented Dec 19, 2020

I was about to open a similar issue.

So it's rounding down, to report the number of full months that has elpased.

To me this doesn't seem like a very "human" approach.

Say you have two dates:

date_1 = datetime.date(2020, 12, 13)
date_2 = datetime.date(2021, 3, 13)

A human would say that the time difference is 3 months. However, since the exact difference is 90 days, these are rounded down to 2 months.

This issue was closed.
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

No branches or pull requests

2 participants