Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in the conversion of int types to timestamp. #223

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}