Preserve milli-precision in non-prepared datetimes

When a datetime was used for a 'timestamp' value in a non-prepared
statement, all sub-second precision was lost.  After this change,
millisecond level precision will be kept.
This commit is contained in:
Tyler Hobbs
2013-12-18 12:43:53 -06:00
parent 02fe5792a8
commit 2766377dfa
2 changed files with 4 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
from binascii import hexlify
import calendar
from collections import namedtuple
import datetime
import logging
@@ -788,7 +789,8 @@ def cql_encode_object(val):
def cql_encode_datetime(val):
return "'%s'" % val.strftime('%Y-%m-%d %H:%M:%S-0000')
timestamp = calendar.timegm(val.utctimetuple())
return str(long(timestamp * 1e3 + getattr(val, 'microsecond', 0) / 1e3))
def cql_encode_date(val):

View File

@@ -131,7 +131,7 @@ class TypeTests(unittest.TestCase):
v1_uuid = uuid1()
v4_uuid = uuid4()
mydatetime = datetime(2013, 1, 1, 1, 1, 1)
mydatetime = datetime(2013, 12, 31, 23, 59, 59, 999000)
params = [
"sometext",