Skip to content

Commit

Permalink
Bug: ZonedDateTimeConverter 파일 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chaewon-io committed Apr 15, 2024
1 parent 6e7e175 commit 33a9f67
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java
Original file line number Diff line number Diff line change
@@ -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<ZonedDateTime, Timestamp> {

@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()));
}
}

0 comments on commit 33a9f67

Please sign in to comment.