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

de.alpharogroup.db.converter.ZonedDateTimeConverter Maven / Gradle / Ivy

There is a newer version: 6.6
Show newest version
package de.alpharogroup.db.converter;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Date;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * The class {@link ZonedDateTimeConverter} is an attribute converter for {@link ZonedDateTime} to {@link Date}.
 *
 * {@link ZonedDateTime} the type of the entity attribute
 * {@link Date} the type of the database column
 */
@Converter(autoApply = true)
public class ZonedDateTimeConverter implements AttributeConverter {

    /**
     * {@inheritDoc}
     */
    @Override
    public Date convertToDatabaseColumn(final ZonedDateTime date) {
        final Instant instant = Instant.from(date);
        return Date.from(instant);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ZonedDateTime convertToEntityAttribute(final Date value) {
        final Instant instant = value.toInstant();
        return ZonedDateTime.from(instant);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy