From 870258eafa9f325beab0d9a328dbe4ade1951dde Mon Sep 17 00:00:00 2001 From: FearfulTomcat27 <1471335448@qq.com> Date: Fri, 30 Aug 2024 19:48:23 +0800 Subject: [PATCH] Fix a bug in the conversion of int types to timestamps. --- .../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 3caa46c2a..2254f26b8 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 @@ 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 static Integer parseDateExpressionToInt(LocalDate localDate) { + 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 static LocalDate parseIntToLocalDate(int date) { 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(); + } }