MaxGekk commented on a change in pull request #32666:
URL: https://github.com/apache/spark/pull/32666#discussion_r641602543



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -839,8 +839,12 @@ object DateTimeUtils {
    * is valid for the `toZone` time zone, thus the local date-time may be 
adjusted.
    */
   def convertTz(micros: Long, fromZone: ZoneId, toZone: ZoneId): Long = {
-    val rebasedDateTime = getLocalDateTime(micros, toZone).atZone(fromZone)
-    instantToMicros(rebasedDateTime.toInstant)
+    val localDateTime = toJavaTimestamp(micros).toLocalDateTime
+    val zonedDateTimeFromZone = ZonedDateTime.of(localDateTime, fromZone)
+    val zonedDateTimeToZone = zonedDateTimeFromZone.withZoneSameInstant(toZone)
+    val localDateTimeConverted = zonedDateTimeToZone.toLocalDateTime
+    val timestamp = Timestamp.valueOf(localDateTimeConverted)

Review comment:
       This method uses other methods of the `Timestamp` class that assumes the 
hybrid calendar. We described nuances of the hybrid and Proleptic Gregorian 
calendar (used since Spark 3.0) in the blog post 
https://databricks.com/blog/2020/07/22/a-comprehensive-look-at-dates-and-timestamps-in-apache-spark-3-0.html
 . I do believe that your changes can cause some issues in corner cases. I will 
try to allocate some time to find such cases slightly later.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to