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

Use of timedelta is incorrect #1

Closed
svisser opened this issue Dec 6, 2014 · 1 comment
Closed

Use of timedelta is incorrect #1

svisser opened this issue Dec 6, 2014 · 1 comment

Comments

@svisser
Copy link

svisser commented Dec 6, 2014

Passing a timedelta now only works when the timedelta is constructed using seconds. You're using the .seconds of a timedelta but that's only the "seconds" component of it. For example:

>>> d = timedelta(days=1)
>>> d.seconds
0

You should convert the timedelta to seconds using total_seconds():

>>> d.total_seconds()
86400.0

You may need to convert this to an integer to use it. Using this method means your project will require Python 2.7+ as that's when total_seconds() was introduced.

@menezes-
Copy link
Owner

menezes- commented Dec 6, 2014

timedelta.total_seconds was also added on python 3.2+ so i will update the code to use the following function:

def total_seconds(td):
    """
    simulates the total_seconds function added in python 3.2+ and 2.7+
    See 
    :param td: timedelta
    :type td: timedelta
    :return: float representing total seconds from timedelta
    :rtype: float
    """
    return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 6

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

2 participants