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

nl.vpro.persistence.LocalDateToDateConverter Maven / Gradle / Ivy

There is a newer version: 5.3.2
Show newest version
package nl.vpro.persistence;

import java.sql.Date;
import java.time.LocalDate;
import java.time.ZoneId;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

/**
 * @author Michiel Meeuwissen
 * @since 0.36
 */
@Converter
public class LocalDateToDateConverter implements AttributeConverter {

    public static final ZoneId ZONE_ID = ZoneId.of("Europe/Amsterdam");

    @Override
    public Date convertToDatabaseColumn(LocalDate localDate) {
        return localDate == null ? null : Date.valueOf(localDate);
    }

    @Override
    public LocalDate convertToEntityAttribute(Date date) {
        return date == null ? null : date.toLocalDate();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy