X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fjpa%2Fconverters%2FLocalTimeConverter.java;fp=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fjpa%2Fconverters%2FLocalTimeConverter.java;h=60019f5b242aa28aeadae17c25db6664fa7e4272;hb=e6f42c30689923d47a4f17e4a31c6791ebee69fc;hp=0000000000000000000000000000000000000000;hpb=5a509f59870c94e679a587cd9c42552c39dc6bf0;p=jpa-converters diff --git a/src/main/java/de/juplo/jpa/converters/LocalTimeConverter.java b/src/main/java/de/juplo/jpa/converters/LocalTimeConverter.java new file mode 100644 index 0000000..60019f5 --- /dev/null +++ b/src/main/java/de/juplo/jpa/converters/LocalTimeConverter.java @@ -0,0 +1,42 @@ +package de.juplo.jpa.converters; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.util.Date; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + + +/** + * Converts a {@link LocalTime} to a {@link Date}, by converting it into + * an {@Instant} for the GMT-timezone at the date of {@link Instant.EPOCH} and + * then convering that {@link Instant} into a {@link Date} as suggested in the + * official Java 8 Time tutorial. + *
+ * The {@link Date} can then be persisted as
+ * {@link java.persistene.TemporalType.TIME} with the help of the
+ * {@link java.persist.Tmporal}-annotation.
+ * @see https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html
+ * @author Kai Moritz
+ */
+@Converter(autoApply = true)
+public class LocalTimeConverter implements AttributeConverter