You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by ha...@apache.org on 2025/02/18 09:58:47 UTC
(tsfile) branch fix_date_parse created (now aa00d6ec)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a change to branch fix_date_parse
in repository https://gitbox.apache.org/repos/asf/tsfile.git
at aa00d6ec Fix date string parse error
This branch includes the following new commits:
new aa00d6ec Fix date string parse error
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(tsfile) 01/01: Fix date string parse error
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch fix_date_parse
in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit aa00d6ecf58ceaefd72440d59654a73aff764306
Author: HTHou <ha...@apache.org>
AuthorDate: Tue Feb 18 17:58:29 2025 +0800
Fix date string parse error
---
.../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(