yiyutian1 commented on code in PR #25763:
URL: https://github.com/apache/flink/pull/25763#discussion_r1891197006


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/DateTimeUtils.java:
##########
@@ -421,6 +436,21 @@ public static TimestampData parseTimestampData(String 
dateStr, int precision, Ti
                         .toInstant());
     }
 
+    public static TimestampData parseTimestampData(String dateStr, String 
format, String timezone) {
+        if (dateStr == null || format == null || timezone == null) {
+            return null;
+        }
+
+        TimestampData ts = parseTimestampData(dateStr, format);
+        if (ts == null) {
+            return null;
+        }
+
+        ZonedDateTime utcZoned = 
ts.toLocalDateTime().atZone(UTC_ZONE.toZoneId());
+        ZonedDateTime targetTime = 
utcZoned.withZoneSameInstant(ZoneId.of(timezone));

Review Comment:
   The conversion using `UTC` in the middle is not necessary. Can achieve the 
same result using:
   
   // after getting the TimeStamp from parser:
   ```
   ZonedDateTime zoneDate = ts.toLocalDateTime().atZone(ZoneId.of(timezone));
   return TimestampData.fromInstant(zoneDate.toInstant());
   ```



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/DateTimeUtils.java:
##########
@@ -421,6 +436,21 @@ public static TimestampData parseTimestampData(String 
dateStr, int precision, Ti
                         .toInstant());
     }
 
+    public static TimestampData parseTimestampData(String dateStr, String 
format, String timezone) {
+        if (dateStr == null || format == null || timezone == null) {
+            return null;
+        }
+
+        TimestampData ts = parseTimestampData(dateStr, format);
+        if (ts == null) {
+            return null;
+        }
+
+        ZonedDateTime utcZoned = 
ts.toLocalDateTime().atZone(UTC_ZONE.toZoneId());
+        ZonedDateTime targetTime = 
utcZoned.withZoneSameInstant(ZoneId.of(timezone));

Review Comment:
   The conversion using `UTC` in the middle is not necessary. Can directly 
achieve the same result using:
   
   // after getting the TimeStamp from parser:
   ```
   ZonedDateTime zoneDate = ts.toLocalDateTime().atZone(ZoneId.of(timezone));
   return TimestampData.fromInstant(zoneDate.toInstant());
   ```



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