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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 870258ea Fix a bug in the conversion of int types to timestamps.
870258ea is described below

commit 870258eafa9f325beab0d9a328dbe4ade1951dde
Author: FearfulTomcat27 <[email protected]>
AuthorDate: Fri Aug 30 19:48:23 2024 +0800

    Fix a bug in the conversion of int types to timestamps.
---
 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();
+  }
 }

Reply via email to