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

Difference between Period().total_days() and Period().in_days() ? #702

Closed
2 tasks done
layoaster opened this issue Apr 12, 2023 · 1 comment
Closed
2 tasks done

Comments

@layoaster
Copy link

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

Issue

I'm struggling to understand the difference between these two methods. I would expect them both to return the same result (90 days) but they don't.

Sample:

In [20]: import pendulum

In [21]: from_ = pendulum.parse('2023-01-12 17:49:49+00:00')

In [22]: to_ = pendulum.parse('2023-04-12 16:49:49+00:00')

In [23]: period = from_.diff(to_)

In [24]: period.in_days()
Out[24]: 90

In [25]: period.total_days()
Out[25]: 89.95833333333333

Someone else reported the same issue thing but it didn't clear up things for me.

@layoaster
Copy link
Author

layoaster commented Apr 13, 2023

I think that I got the answer by myself:

Given the previous time range, the correct duration in hours is 89 days and 23 hours. Therefore, I believe that

  • total_days() calculates the total period duration in days.
  • in_days(): finds the number of natural days present in the period, whether a day has 24 hours or not.

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

1 participant