fixed issue with timestamp and DST

This commit is contained in:
Nati CT
2014-04-22 15:16:12 +03:00
committed by Jon Haddad
parent eca27faed0
commit e9403e562c
2 changed files with 8 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import copy import copy
import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from cqlengine import BaseContainerColumn, Map, columns from cqlengine import BaseContainerColumn, Map, columns
from cqlengine.columns import Counter, List, Set from cqlengine.columns import Counter, List, Set
@@ -150,10 +151,11 @@ class BatchQuery(object):
if isinstance(self.timestamp, (int, long)): if isinstance(self.timestamp, (int, long)):
ts = self.timestamp ts = self.timestamp
elif isinstance(self.timestamp, timedelta): elif isinstance(self.timestamp, (datetime, timedelta)):
ts = long((datetime.now() + self.timestamp - datetime.fromtimestamp(0)).total_seconds() * 1000000) ts = self.timestamp
elif isinstance(self.timestamp, datetime): if isinstance(self.timestamp, timedelta):
ts = long((self.timestamp - datetime.fromtimestamp(0)).total_seconds() * 1000000) ts += datetime.now() # Apply timedelta
long(time.mktime(ts.timetuple()) * 1e+6 + ts.microsecond)
else: else:
raise ValueError("Batch expects a long, a timedelta, or a datetime") raise ValueError("Batch expects a long, a timedelta, or a datetime")

View File

@@ -1,3 +1,4 @@
import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from cqlengine.functions import QueryValue from cqlengine.functions import QueryValue
from cqlengine.operators import BaseWhereOperator, InOperator from cqlengine.operators import BaseWhereOperator, InOperator
@@ -496,7 +497,7 @@ class BaseCQLStatement(object):
else: else:
tmp = self.timestamp tmp = self.timestamp
return long(((tmp - datetime.fromtimestamp(0)).total_seconds()) * 1000000) return long(time.mktime(tmp.timetuple()) * 1e+6 + tmp.microsecond)
def __unicode__(self): def __unicode__(self):
raise NotImplementedError raise NotImplementedError