Open2
jooq
LocalDateTime to Timestamp
デフォルトで 2024-01-01 00:00:00.000
ミリ秒までに変換される。
LocalDateTimeはナノ秒、postgresqlのtimestampはマイクロ秒まで保持できるはずなのでどっかでおっことしてる (?) どこ
final class Convert {
...
private static final class ConvertAll<U> extends AbstractContextConverter<Object, U> {
private final Class<? extends U> toClass;
@SuppressWarnings("unchecked")
ConvertAll(Class<? extends U> toClass) {
super(Object.class, (Class<U>) toClass);
this.toClass = toClass;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public U from(Object from, ConverterContext scope) {
...
// [#12225] Avoid losing precision if possible
if (LocalDateTime.class == fromClass && Timestamp.class == toClass)
return (U) Timestamp.valueOf((LocalDateTime) from);
public class Timestamp extends java.util.Date {
...
/**
* Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
* object, with the same year, month, day of month, hours, minutes,
* seconds and nanos date-time value as the provided {@code LocalDateTime}.
* <p>
* The provided {@code LocalDateTime} is interpreted as the local
* date-time in the local time zone.
*
* @param dateTime a {@code LocalDateTime} to convert
* @return a {@code Timestamp} object
* @throws NullPointerException if {@code dateTime} is null.
* @since 1.8
*/
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
return new Timestamp(dateTime.getYear() - 1900,
dateTime.getMonthValue() - 1,
dateTime.getDayOfMonth(),
dateTime.getHour(),
dateTime.getMinute(),
dateTime.getSecond(),
dateTime.getNano());
}
...
/**
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this {@code Timestamp} object.
*
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this date.
* @see #setTime
*/
public long getTime() {
long time = super.getTime();
return (time + (nanos / 1000000));
}
LocalDateTime -> java.sql.Timestamp -> long -> timestampe (postgresql)
public class DefaultBinding<T, U> implements Binding<T, U> {
...
private static final long parse(Class<? extends java.util.Date> type, String date) throws SQLException {
// Try reading a plain number first
Long number = Longs.tryParse(date);
if (number != null)
return number;
// If that fails, try reading a formatted date
// [#7325] In SQLite dates could be stored in both ISO standard formats:
// With T (default standard), or without T (optional standard, JDBC standard)
date = StringUtils.replace(date, "T", " ");
if (type == Timestamp.class)
return Timestamp.valueOf(date).getTime();