From dbe4be5fdf9cb23af48e20efd168a266e0bb487a Mon Sep 17 00:00:00 2001 From: hyunn522 Date: Thu, 10 Oct 2024 11:35:34 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20TimeUtils=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/entity/ChatRoom.java | 7 ------- .../space_spring/entity/UserChatRoom.java | 8 -------- .../space/space_spring/util/TimeUtils.java | 20 +++++++++++++++++++ 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 src/main/java/space/space_spring/util/TimeUtils.java diff --git a/src/main/java/space/space_spring/entity/ChatRoom.java b/src/main/java/space/space_spring/entity/ChatRoom.java index 9272fc18..87107e81 100644 --- a/src/main/java/space/space_spring/entity/ChatRoom.java +++ b/src/main/java/space/space_spring/entity/ChatRoom.java @@ -51,13 +51,6 @@ public void updateName(String name) { this.name = name; } - public LocalDateTime getEncodedTime() { - return this.getCreatedAt() - .atZone(ZoneId.of("UTC")) // UTC로 해석 - .withZoneSameInstant(ZoneId.of("Asia/Seoul")) // 서울 시간대로 변환 - .toLocalDateTime(); // LocalDateTime으로 변환 - } - // // 양방향 매핑 // @OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL) // private List userChatRooms; diff --git a/src/main/java/space/space_spring/entity/UserChatRoom.java b/src/main/java/space/space_spring/entity/UserChatRoom.java index 3bf08201..d30e363d 100644 --- a/src/main/java/space/space_spring/entity/UserChatRoom.java +++ b/src/main/java/space/space_spring/entity/UserChatRoom.java @@ -9,7 +9,6 @@ import org.hibernate.annotations.Comment; import java.time.LocalDateTime; -import java.time.ZoneId; @Entity @Getter @@ -52,13 +51,6 @@ public void setLastReadTime(LocalDateTime lastReadTime) { this.lastReadTime = lastReadTime; } - public LocalDateTime getEncodedTime() { - return this.getLastReadTime() - .atZone(ZoneId.of("UTC")) // UTC로 해석 - .withZoneSameInstant(ZoneId.of("Asia/Seoul")) // 서울 시간대로 변환 - .toLocalDateTime(); - } - public void setUserRejoin() { this.setLastReadTime(LocalDateTime.now()); this.updateActive(); diff --git a/src/main/java/space/space_spring/util/TimeUtils.java b/src/main/java/space/space_spring/util/TimeUtils.java new file mode 100644 index 00000000..e452cc19 --- /dev/null +++ b/src/main/java/space/space_spring/util/TimeUtils.java @@ -0,0 +1,20 @@ +package space.space_spring.util; + +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.ZoneId; + +@Component +public class TimeUtils { + + /** + * UTC 시간을 서울 시간으로 변환 + */ + public LocalDateTime getEncodedTime(LocalDateTime originalTime) { + return originalTime + .atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Asia/Seoul")) + .toLocalDateTime(); + } +}