com.databasesandlife.util.jooq.UtcInstantConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.jooq;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import org.jooq.Converter;
/**
* @deprecated Prefer TIMEZONETZ type in PostgreSQL which jOOQ automatically recognizes as Instant.
* And note that this class has issues in jOOQ 3.13 when using .update(..., val(..)). (but 3.11 is OK)
*/
@Deprecated
@SuppressWarnings("serial")
public class UtcInstantConverter implements Converter {
@Override public Class fromType() { return LocalDateTime.class; }
@Override public Class toType() { return Instant.class; }
@Override
public Instant from(LocalDateTime when) {
if (when == null) return null;
return when.toInstant(ZoneOffset.UTC);
}
@Override
public LocalDateTime to(Instant when) {
if (when == null) return null;
return when.atOffset(ZoneOffset.UTC).toLocalDateTime();
}
}