From 33a9f6754a1d9e51913ab7088c7bbd382f9699a5 Mon Sep 17 00:00:00 2001 From: chaewon-io <0101angela@naver.com> Date: Tue, 16 Apr 2024 00:44:13 +0900 Subject: [PATCH] =?UTF-8?q?Bug:=20ZonedDateTimeConverter=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waved/common/ZonedDateTimeConverter.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java diff --git a/src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java b/src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java new file mode 100644 index 0000000..4e145f5 --- /dev/null +++ b/src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java @@ -0,0 +1,23 @@ +package com.senity.waved.common; + + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +import java.sql.Timestamp; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +@Converter(autoApply = true) +public class ZonedDateTimeConverter implements AttributeConverter { + + @Override + public Timestamp convertToDatabaseColumn(ZonedDateTime zonedDateTime) { + return (zonedDateTime == null ? null : Timestamp.from(zonedDateTime.toInstant())); + } + + @Override + public ZonedDateTime convertToEntityAttribute(Timestamp sqlTimestamp) { + return (sqlTimestamp == null ? null : ZonedDateTime.ofInstant(sqlTimestamp.toInstant(), ZoneId.systemDefault())); + } +} \ No newline at end of file