Skip to content

Commit

Permalink
Fix a bug in the conversion of int types to timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
FearfulTomcat27 authored Aug 30, 2024
1 parent f659030 commit 870258e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
}

0 comments on commit 870258e

Please sign in to comment.