aholmberg commented on a change in pull request #1165: TINKERPOP-2264 Fixed 
g:Date serialization for python.
URL: https://github.com/apache/tinkerpop/pull/1165#discussion_r306423448
 
 

 ##########
 File path: 
gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
 ##########
 @@ -339,18 +339,17 @@ class DateIO(_GraphSONTypeIO):
     python_type = datetime.datetime
     graphson_type = "g:Date"
     graphson_base_type = "Date"
+    epoch = datetime.datetime(1970, 1, 1)
 
     @classmethod
     def dictify(cls, obj, writer):
-        # Java timestamp expects miliseconds
+        # Java timestamp expects milliseconds.
         if six.PY3:
-            pts = obj.timestamp()
+            pts = (obj - cls.epoch) / datetime.timedelta(seconds=1)
 
 Review comment:
   To me this is a bit of a confusing way to get to a timestamp. I might 
suggest having a look at datetime handling in the Cassandra driver: 
https://github.com/datastax/python-driver/blob/master/cassandra/cqltypes.py#L577-L579
   This technique has a few advantages:
   - No special cases per python runtime
   - Handles datetime inputs with timezones attached, normalizing back to UTC
   - More readable (imo)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to