You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by GitBox <gi...@apache.org> on 2019/07/23 16:32:33 UTC

[GitHub] [tinkerpop] TheRealFalcon commented on a change in pull request #1165: TINKERPOP-2264 Fixed g:Date serialization for python.

TheRealFalcon 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_r306417490
 
 

 ##########
 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:
   If I'm understanding this right, it's taking the epoch offset and removing it from our current time.
   So for example, `obj.timetuple()` will return current UTC-5 for me, and `cls.epoch.timetuple()` should return epoch-5, so we if we subtract them, we get the UTC time.
   
   But according to the end of https://stackoverflow.com/a/5499906/37205, the epoch offset can be different for DST timezones. I don't really understand how that can be, but when I'm not in daylight time, I'm UTC-6. I think this answer is saying that if my timezone was affected, it would return epoch as epoch-6 when current time would be UTC-5.

----------------------------------------------------------------
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