tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [tinkerpop] aholmberg commented on a change in pull request #1165: TINKERPOP-2264 Fixed g:Date serialization for python.
Date Tue, 23 Jul 2019 16:48:59 GMT
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_r306423868
 
 

 ##########
 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)
         else:
-            # Hack for legacy Python
-            # timestamp() in Python 3.3
-            pts = time.mktime((obj.year, obj.month, obj.day,
-			                   obj.hour, obj.minute, obj.second,
-			                   -1, -1, -1)) + obj.microsecond / 1e6
+            # Hack for legacy Python - timestamp() in Python 3.3
+            pts = (time.mktime(obj.timetuple()) + obj.microsecond / 1e6) - \
+                  (time.mktime(cls.epoch.timetuple()))
 
 Review comment:
   I know this was not introduced in this change, but a "hack" should not be needed if an
alternative conversion technique is used (see above).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message