com.clickzetta.platform.util.DateUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickzetta-java Show documentation
Show all versions of clickzetta-java Show documentation
The java SDK for clickzetta's Lakehouse
package com.clickzetta.platform.util;
import java.sql.Date;
import java.time.LocalDate;
public class DateUtil {
public static final int MIN_DATE_VALUE =
(int)LocalDate.parse("0001-01-01").toEpochDay();
public static final int MAX_DATE_VALUE =
(int)LocalDate.parse("9999-12-31").toEpochDay();
private DateUtil() {
}
public static void checkDateWithinRange(long days) {
if (days < MIN_DATE_VALUE || days > MAX_DATE_VALUE) {
throw new IllegalArgumentException(
"Date value <" + days + ">} is out of range '0001-01-01':'9999-12-31'");
}
}
public static int sqlDateToEpochDays(Date date) {
long days = date.toLocalDate().toEpochDay();
checkDateWithinRange(days);
return (int)days;
}
public static Date epochDaysToSqlDate(int days) {
checkDateWithinRange(days);
return Date.valueOf(LocalDate.ofEpochDay(days));
}
public static String epochDaysToDateString(int days) {
return LocalDate.ofEpochDay(days).toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy