All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.jooq.UtcInstantConverter Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy