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.total_seconds() fails for months and years #44

Open
pilgrimbeart opened this issue Sep 21, 2017 · 4 comments
Open

Duration.total_seconds() fails for months and years #44

pilgrimbeart opened this issue Sep 21, 2017 · 4 comments

Comments

@pilgrimbeart
Copy link

pilgrimbeart commented Sep 21, 2017

>>> import isodate
>>> isodate.parse_duration("P3M").total_seconds()
0.0
@pilgrimbeart pilgrimbeart changed the title .total_seconds*() fails .total_seconds*() fails for months and years Sep 21, 2017
@pilgrimbeart pilgrimbeart changed the title .total_seconds*() fails for months and years Duration.total_seconds() fails for months and years Sep 21, 2017
@reinhrst
Copy link
Contributor

reinhrst commented Nov 3, 2017

Of course it fails.... How many seconds are there in a month? Depends on whether it's February or August, and this is not known for a P3M. However I would argue that it should return an exception, rather than 0.0..

@mristin
Copy link

mristin commented Mar 5, 2018

@reinhrst , if you look at the documentation of datetime.timedelta from https://docs.python.org/3/library/datetime.html:

timedelta.total_seconds()

Return the total number of seconds contained in the duration. Equivalent to td / timedelta(seconds=1).

Note that for very large time intervals (greater than 270 years on most platforms) this method will lose microsecond accuracy.
New in version 3.2.

I would also expect the total seconds to return the duration in seconds, not the seconds part of the duration.

@theferrit32
Copy link

Timedelta has a total_seconds but it does not handle any sort of conversion from months to seconds. Month is not a standardized time interval unit. It is only useful for scheduling tasks that run on monthly or yearly intervals, to allow more human-understandable schedules (execute this every 5th day of every month, etc). The number of seconds between each execution will not be the same though, so there is no way to map it to a number of seconds, or even days, unless you provide which two months you're talking about, and which year it is (since month lengths vary by year). That seems like it is not useful. For that same reason month/year is not a unit in the timedelta module, week is the largest standardized duration unit.

I agree with @reinhrst that this should probably throw an exception instead of returning 0, because it is an invalid operation.

@mmerickel
Copy link

It would be nice to see this throw an exception to avoid any misusage in the API.

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