Python 2.6 compatibility for date queries.

The method datetime.timedelta.total_seconds() is only available since 2.7.
This commit is contained in:
Stig Inge Lea Bjørnsen 2014-02-19 00:30:29 +01:00
parent 64fdd174b3
commit cf0a10b652

View file

@ -331,7 +331,14 @@ class FalseQuery(Query):
def _to_epoch_time(date):
epoch = datetime.fromtimestamp(0)
return int((date - epoch).total_seconds())
delta = date - epoch
try:
return int((delta).total_seconds())
except AttributeError:
# datetime.timedelta.total_seconds() is not available on Python 2.6
return int((delta.microseconds
+ (delta.seconds + delta.days * 24 * 3600) * 10 ** 6)
/ 10.0 ** 6)
def _parse_periods(pattern):