This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients brett.cannon, catlee, erik.stephens, guettli, jribbens, lemburg, skip.montanaro, steve.roberts, tim.peters, tomster, vstinner
Date 2008-10-31.17:20:27
SpamBayes Score 7.93254e-14
Marked as misclassified No
Message-id <>
I wrote this function is my program:

def timedelta2seconds(delta):
    Convert a datetime.timedelta() objet to a number of second
    (floatting point number).

    >>> timedelta2seconds(timedelta(seconds=2, microseconds=40000))
    >>> timedelta2seconds(timedelta(minutes=1, milliseconds=250))
    return delta.microseconds / 1000000.0 \
        + delta.seconds + delta.days * 60*60*24

About the use cases: I use it to compute the compression rate of an 
audio song (bytes / seconds), to compute the bit rate of a video 
(bytes / seconds). I'm using datetime.timedelta() to store the 
audio/video duration.

It's not related to time_t: see issue #2736 for 
datetime.datetime.totimestamp(). And about time_t: I don't about 31 
bits signed integer. It's not beacuse other programs have arbitrary 
limits than Python should also be limited.

About the patch: I don't like the name "tosecs", it's not consistent 
with the constructor: timedelta(seconds=...).tosec[ond]s(). And why 
dropping the microseconds? For short duration, microseconds are 
Date User Action Args
2008-10-31 17:20:28vstinnersetrecipients: + vstinner, lemburg, tim.peters, skip.montanaro, brett.cannon, jribbens, guettli, catlee, tomster, erik.stephens, steve.roberts
2008-10-31 17:20:28vstinnersetmessageid: <>
2008-10-31 17:20:28vstinnerlinkissue1673409 messages
2008-10-31 17:20:27vstinnercreate