--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.util.GregorianCalendar;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts an {@link OffsetTime} to a {@link GregorianCalendar}, by converting
+ * it into a {@ZonedDateTime} at the date of {@link Instant.EPOCH} and
+ * then convering that {@link ZonedDateTime} into a {@link GregorianCalendar}
+ * as suggested in the official Java 8 Time tutorial.
+ * <p>
+ * The {@link GregorianCalendar} 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 OffsetTimeConverter implements AttributeConverter<OffsetTime, GregorianCalendar>
+{
+ private final static LocalDate EPOCH = LocalDate.from(Instant.EPOCH);
+
+
+ @Override
+ public GregorianCalendar convertToDatabaseColumn(OffsetTime ot)
+ {
+ ZoneOffset offset = ot.getOffset();
+ return GregorianCalendar.from(ZonedDateTime.of(EPOCH, ot.toLocalTime(), offset));
+ }
+
+ @Override
+ public OffsetTime convertToEntityAttribute(GregorianCalendar calendar)
+ {
+ return OffsetTime.from(calendar.toInstant());
+ }
+}