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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -71,6 +71,15 @@ object DateTimeUtils {
     instantToMicros(instant)
   }
 
+  def microsToLocalDateTime(micros: Long): LocalDateTime = {
+    getLocalDateTime(micros, ZoneId.of("UTC"))
+  }
+
+  def localDateTimeToMicros(localDateTime: LocalDateTime): Long = {
+    localDateTime.toEpochSecond(ZoneOffset.UTC) * MICROS_PER_SECOND +
+      localDateTime.getNano / NANOS_PER_MICROS

Review comment:
       Also, please, add tests to check long overflow.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -71,6 +71,15 @@ object DateTimeUtils {
     instantToMicros(instant)
   }
 
+  def microsToLocalDateTime(micros: Long): LocalDateTime = {
+    getLocalDateTime(micros, ZoneId.of("UTC"))
+  }
+
+  def localDateTimeToMicros(localDateTime: LocalDateTime): Long = {
+    localDateTime.toEpochSecond(ZoneOffset.UTC) * MICROS_PER_SECOND +
+      localDateTime.getNano / NANOS_PER_MICROS

Review comment:
       Potentially, `*` and `+` can overflow. Could you use `Math.multiplyExact`

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -71,6 +71,15 @@ object DateTimeUtils {
     instantToMicros(instant)
   }
 
+  def microsToLocalDateTime(micros: Long): LocalDateTime = {
+    getLocalDateTime(micros, ZoneId.of("UTC"))

Review comment:
       ```suggestion
       getLocalDateTime(micros, ZoneOffset.UTC)
   ```




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