dianfu commented on code in PR #29603:
URL: https://github.com/apache/flink/pull/29603#discussion_r4376808507


##########
flink-python/pyflink/fn_execution/coder_impl_slow.py:
##########
@@ -607,9 +607,15 @@ def __init__(self, precision, timezone):
         self.timezone = timezone
 
     def internal_to_timestamp(self, milliseconds, nanoseconds):
-        return self.timezone.localize(
-            super(LocalZonedTimestampCoderImpl, self).internal_to_timestamp(
-                milliseconds, nanoseconds))
+        return super(LocalZonedTimestampCoderImpl, self).internal_to_timestamp(
+            milliseconds, nanoseconds).replace(tzinfo=datetime.timezone.utc) \
+            .astimezone(self.timezone)
+
+    @staticmethod
+    def timestamp_to_internal(timestamp):
+        if timestamp.tzinfo is not None:
+            timestamp = timestamp.astimezone(datetime.timezone.utc)
+        return TimestampCoderImpl.timestamp_to_internal(timestamp)

Review Comment:
   Normalizing to UTC here exposes the inherited truncation of negative 
fractional epoch seconds. For example, `1970-01-01 07:59:59.999+08:00` 
represents `-1 ms`, but the parent encoder truncates `-0.001` seconds to `0` 
and then adds `999` milliseconds, producing `999 ms`. The fast implementation 
has the same issue.
   
   This value previously round-tripped correctly with the Shanghai coder. With 
this change, it moves forward by one second. 



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to