make up for lack of 'total_seconds()' lib function for pre 2.7 version of python

This commit is contained in:
Martin Konecny 2013-05-16 12:25:21 -04:00
parent dc1ec789d2
commit 59785a952f
2 changed files with 13 additions and 1 deletions

View file

@ -5,3 +5,13 @@ def version_cmp(version1, version2):
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
return cmp(normalize(version1), normalize(version2))
def date_interval_to_seconds(interval):
"""
Convert timedelta object into int representing the number of seconds. If
number of seconds is less than 0, then return 0.
"""
seconds = (interval.microseconds + \
(interval.seconds + interval.days * 24 * 3600) * 10 ** 6) / float(10 ** 6)
return seconds