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



##########
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:
       BTW, I replaced `*` by `multiplyExact`, and got:
   ```
   java.lang.ArithmeticException: long overflow
        at java.lang.Math.multiplyExact(Math.java:892)
        at 
org.apache.spark.sql.catalyst.util.DateTimeUtils$.localDateTimeToMicros(DateTimeUtils.scala:79)
        at 
org.apache.spark.sql.catalyst.util.DateTimeUtilsSuite.$anonfun$new$51(DateTimeUtilsSuite.scala:660)
   ```
   on your new test:
   ```scala
       
assert(DateTimeUtils.localDateTimeToMicros(LocalDateTime.parse("-290308-12-21T19:59:05.224192"))
         == Long.MinValue)
   ```




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