This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch rc/1.1
in repository https://gitbox.apache.org/repos/asf/tsfile.git
The following commit(s) were added to refs/heads/rc/1.1 by this push:
new c37cbf0e [To rc/1.1]Fix bug in the conversion of int types to timestamp
c37cbf0e is described below
commit c37cbf0e5c2ddadff6c6e8b619412fb34da907b3
Author: FearfulTomcat27 <[email protected]>
AuthorDate: Fri Aug 30 19:41:22 2024 +0800
[To rc/1.1]Fix bug in the conversion of int types to timestamp
Signed-off-by: FearfulTomcat27 <[email protected]>
---
java/tsfile/src/main/java/org/apache/tsfile/utils/DateUtils.java | 9 +++++++++
1 file changed, 9 insertions(+)
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 3caa46c2..2254f26b 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
@@ -21,6 +21,8 @@ package org.apache.tsfile.utils;
import java.sql.Date;
import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -65,6 +67,7 @@ public class DateUtils {
+ localDate.getDayOfMonth();
}
+ // Do not use this method to get a timestamp, use parseIntToTimestamp
instead.
public static Date parseIntToDate(int date) {
return new Date(date / 10000 - 1900, (date / 100) % 100 - 1, date % 100);
}
@@ -76,4 +79,10 @@ public class DateUtils {
throw new DateTimeParseException("Invalid date format.", "", 0);
}
}
+
+ public static long parseIntToTimestamp(int date, ZoneId zoneId) {
+ return ZonedDateTime.of(date / 10000, (date / 100) % 100, date % 100, 0,
0, 0, 0, zoneId)
+ .toInstant()
+ .toEpochMilli();
+ }
}