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

jiangtian pushed a commit to branch rc/2.0.2
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/rc/2.0.2 by this push:
     new fcd439c9 Fix date string parse error (#413)
fcd439c9 is described below

commit fcd439c99c46bf47e853e3ef9a8b93a9050e94f7
Author: Haonan <[email protected]>
AuthorDate: Wed Feb 19 09:22:08 2025 +0800

    Fix date string parse error (#413)
    
    (cherry picked from commit 06036eff9df8ca180d6458751175674f37e4f264)
---
 .../src/main/java/org/apache/tsfile/utils/DateUtils.java       |  7 ++++---
 .../src/test/java/org/apache/tsfile/utils/DateUtilsTest.java   | 10 ++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/DateUtils.java 
b/java/tsfile/src/main/java/org/apache/tsfile/utils/DateUtils.java
index 3dfc709f..dc531baa 100644
--- a/java/tsfile/src/main/java/org/apache/tsfile/utils/DateUtils.java
+++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/DateUtils.java
@@ -27,7 +27,6 @@ import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 
 public class DateUtils {
-  private static final DateTimeFormatter DATE_FORMATTER = 
DateTimeFormatter.ofPattern("yyyy-MM-dd");
   public static final int EMPTY_DATE_INT = 10000101;
 
   public static String formatDate(int date) {
@@ -44,7 +43,7 @@ public class DateUtils {
     }
     LocalDate date;
     try {
-      date = LocalDate.parse(dateExpression, DATE_FORMATTER);
+      date = LocalDate.parse(dateExpression);
     } catch (DateTimeParseException e) {
       throw new DateTimeParseException(
           "Invalid date format. Please use YYYY-MM-DD format.", 
dateExpression, 0);
@@ -61,7 +60,9 @@ public class DateUtils {
     }
     if (localDate.getYear() < 1000 || localDate.getYear() > 9999) {
       throw new DateTimeParseException(
-          "Year must be between 1000 and 9999.", 
localDate.format(DATE_FORMATTER), 0);
+          "Year must be between 1000 and 9999.",
+          localDate.format(DateTimeFormatter.ISO_LOCAL_DATE),
+          0);
     }
     return localDate.getYear() * 10000
         + localDate.getMonthValue() * 100
diff --git 
a/java/tsfile/src/test/java/org/apache/tsfile/utils/DateUtilsTest.java 
b/java/tsfile/src/test/java/org/apache/tsfile/utils/DateUtilsTest.java
index 6154a3a9..27ee0520 100644
--- a/java/tsfile/src/test/java/org/apache/tsfile/utils/DateUtilsTest.java
+++ b/java/tsfile/src/test/java/org/apache/tsfile/utils/DateUtilsTest.java
@@ -54,6 +54,16 @@ public class DateUtilsTest {
         });
   }
 
+  @Test
+  public void testParseDateExpressionToInt_InvalidDate2() {
+    String dateExpression = "2023-04-31";
+    assertThrows(
+        DateTimeParseException.class,
+        () -> {
+          DateUtils.parseDateExpressionToInt(dateExpression);
+        });
+  }
+
   @Test
   public void testParseDateExpressionToInt_NullOrEmpty() {
     assertThrows(

Reply via email to