This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new af7ae01d1b5 Directly throw DateTimeParseException instead of wrapping 
RuntimeException (#15096)
af7ae01d1b5 is described below

commit af7ae01d1b5bf38facc259018569b246f069444d
Author: Jackie Tien <[email protected]>
AuthorDate: Mon Mar 24 10:13:43 2025 +0800

    Directly throw DateTimeParseException instead of wrapping RuntimeException 
(#15096)
---
 .../org/apache/iotdb/db/utils/DateTimeUtils.java   | 35 ++++++++++------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
index a49f37f8a06..a94bda73033 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
@@ -43,7 +43,6 @@ import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
-import java.time.format.DateTimeParseException;
 import java.time.format.ResolverStyle;
 import java.time.format.SignStyle;
 import java.time.temporal.ChronoField;
@@ -533,27 +532,23 @@ public class DateTimeUtils {
   }
 
   public static long getInstantWithPrecision(String str, String 
timestampPrecision) {
-    try {
-      ZonedDateTime zonedDateTime = ZonedDateTime.parse(str, formatter);
-      Instant instant = zonedDateTime.toInstant();
-      if ("us".equals(timestampPrecision) || 
"microsecond".equals(timestampPrecision)) {
-        if (instant.getEpochSecond() < 0 && instant.getNano() > 0) {
-          // adjustment can reduce the loss of the division
-          long millis = Math.multiplyExact(instant.getEpochSecond() + 1, 
1000_000L);
-          long adjustment = instant.getNano() / 1000 - 1L;
-          return Math.addExact(millis, adjustment);
-        } else {
-          long millis = Math.multiplyExact(instant.getEpochSecond(), 
1000_000L);
-          return Math.addExact(millis, instant.getNano() / 1000);
-        }
-      } else if ("ns".equals(timestampPrecision) || 
"nanosecond".equals(timestampPrecision)) {
-        long millis = Math.multiplyExact(instant.getEpochSecond(), 
1000_000_000L);
-        return Math.addExact(millis, instant.getNano());
+    ZonedDateTime zonedDateTime = ZonedDateTime.parse(str, formatter);
+    Instant instant = zonedDateTime.toInstant();
+    if ("us".equals(timestampPrecision) || 
"microsecond".equals(timestampPrecision)) {
+      if (instant.getEpochSecond() < 0 && instant.getNano() > 0) {
+        // adjustment can reduce the loss of the division
+        long millis = Math.multiplyExact(instant.getEpochSecond() + 1, 
1000_000L);
+        long adjustment = instant.getNano() / 1000 - 1L;
+        return Math.addExact(millis, adjustment);
+      } else {
+        long millis = Math.multiplyExact(instant.getEpochSecond(), 1000_000L);
+        return Math.addExact(millis, instant.getNano() / 1000);
       }
-      return instant.toEpochMilli();
-    } catch (DateTimeParseException e) {
-      throw new RuntimeException(e.getMessage());
+    } else if ("ns".equals(timestampPrecision) || 
"nanosecond".equals(timestampPrecision)) {
+      long millis = Math.multiplyExact(instant.getEpochSecond(), 
1000_000_000L);
+      return Math.addExact(millis, instant.getNano());
     }
+    return instant.toEpochMilli();
   }
 
   /** convert date time string to millisecond, microsecond or nanosecond. */

Reply via email to