-
Notifications
You must be signed in to change notification settings - Fork 58
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
Comments
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 |
@reinhrst , if you look at the documentation of datetime.timedelta from https://docs.python.org/3/library/datetime.html:
I would also expect the total seconds to return the duration in seconds, not the seconds part of the duration. |
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, I agree with @reinhrst that this should probably throw an exception instead of returning 0, because it is an invalid operation. |
It would be nice to see this throw an exception to avoid any misusage in the API. |
The text was updated successfully, but these errors were encountered: