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:
@@ -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):
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user