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

Duration methods (total_days(), in_days()) return incorrect values and/or do not match docs #475

Closed
2 tasks done
hamblin opened this issue May 24, 2020 · 0 comments · Fixed by #482
Closed
2 tasks done

Comments

@hamblin
Copy link

hamblin commented May 24, 2020

  • I am on the latest Pendulum version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • OS version and name: MacOS 10.14 (running Python 3.7.2)

  • Pendulum version: 2.1.0

Issue

The duration methods duration.total_days() and duration.in_days() do not match expected results, and/or do not match the docs. Since the docs seem to show an inconsistent / incorrect result (specifically for duration.in_days()), it isn't clear what the real expected behavior is.

I was quite confused about the logic and differences between the conversion of years/months into days for a duration (still am), so I just re-created the example used in the docs in order to test my thinking. And when doing that, I got different results to what is shown in docs.

My results below, using exact example from Pendulum docs duration section:

# I copied example from pendulum docs
>>> it = pendulum.duration(
...     years=2, months=3,
...     days=1177, seconds=7284, microseconds=1234
... ) 

>>> it.days
1997   
# seems OK... 2 * 365 days/year + 3 * 30days/month + 1177 days = 1997

>>> it.total_days()
1177.0843055698379   
# this matches result shown in docs (1177.084...)
# but result seems counter-intuitive based on name of method
# I would expect 'total_days' to be 1997.084... including days from years and months

>>> it.in_days()
1177  
# this DOES NOT match result shown in docs (docs show 1997 for it.in_days())
# but does match description of this method being truncated integer of total_days()

Based on description of duration.in_days() method in the docs, I would expect duration.total_days() and duration.in_days() to return same result, only with in_days() as a truncated integer as described. That's what I actually got, but doesn't match docs.

But larger issue seems to be that both .total_days() and .in_days() return incorrect (or at least un-intuitive) results -- I would expect them to both return 1997... in this case, including the days from years and months. (not 1177)

Seems like there is either:
A) Incorrect example in the docs (specifically where it shows return of 1997 for .in_days() method)
B) Bug in duration.in_days() and/or duration.total_days() method, especially when including years/months in duration
C) Both A and B
D)or I'm totally missing something...

This may be related to #387 but I'm creating this as separate bug because it seems there is at least a docs issue here, and because 387 relates to total_seconds() and maybe there are drop-in compatibility constraints with built-in total_seconds() method for that one?

Thanks to the creator & contributors!

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 a pull request may close this issue.

1 participant