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



##########
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:
       Mixing is possible via the rebase methods like 
`RebaseDateTime.rebaseGregorianToJulianMicros()` otherwise an implementation 
works incorrectly for ancient dates (before 1582-10-15) and timestamps (before 
1900-01-01) because of different underlying calendar systems (Java 8 - 
Proleptic Gregorian calendar, Java 7 - the hybrid calendar Julian + Gregorian 
calendar), and JDK implementations - Java 8 uses more precise historical data.
   
   Since you mix Java 8 methods and Java 7 `Timestamp.valueOf()`, highly likely 
your implementation will work incorrectly.




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