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

Period: months/years not counted in total_seconds() #387

Closed
zeebonk opened this issue Jul 12, 2019 · 6 comments
Closed

Period: months/years not counted in total_seconds() #387

zeebonk opened this issue Jul 12, 2019 · 6 comments

Comments

@zeebonk
Copy link

zeebonk commented Jul 12, 2019

Pendulum version: 2.0.5, possibly related to #346

Context
When working with classes/functions/APIs that expect some period be passed as number of seconds, I like to use a Duration + the total_seconds() function to clearly express what kind of period I'm passing.

Problem
I'm running into a situation where I want a period of a year in total seconds, but to my surprise I get 0 as a result. While experimenting I found that the same applies for months. Weeks and smaller seem to work as expected.

Examples

In [9]: pendulum.Duration(years=1).total_seconds()
Out[9]: 0.0

In [10]: pendulum.Duration(months=1).total_seconds()
Out[10]: 0.0

In [11]: pendulum.Duration(days=1).total_seconds()
Out[11]: 86400.0
@senpos
Copy link
Contributor

senpos commented Jul 26, 2019

#389
No years/months are mentioned there, but looks similar

@zeebonk
Copy link
Author

zeebonk commented Jul 30, 2019

@senpos that is not related to this issue, but I could help with an answer :)

@datarods-svc
Copy link

Any update? This bug can bite users if they're not careful.

@ALERTua
Copy link

ALERTua commented Nov 14, 2019

Here's a quick way to reproduce this:

import pendulum
a = pendulum.duration(seconds=200000000)
a.in_words()
330 weeks 4 days 19 hours 33 minutes 20 seconds

The output should contain months and years.

@rnovacek
Copy link

rnovacek commented Jun 12, 2024

I think this issue can be closed, it was fixed by PR #482.

@zeebonk
Copy link
Author

zeebonk commented Jun 14, 2024

Confirmed resolved with pendulum==3.0.0 and Python==3.11.4:

Python 3.11.4 (main, Sep 26 2023, 14:43:59) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pendulum
>>> pendulum.Duration(years=1).total_seconds()
31536000.0
>>> pendulum.Duration(months=1).total_seconds()
2592000.0

@zeebonk zeebonk closed this as completed Jun 14, 2024
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

5 participants