Skip to content

Commit

Permalink
refactor: TimeUtils ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunn522 committed Oct 10, 2024
1 parent ecd329d commit dbe4be5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
7 changes: 0 additions & 7 deletions src/main/java/space/space_spring/entity/ChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserChatRoom> userChatRooms;
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/space/space_spring/entity/UserChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Entity
@Getter
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/space/space_spring/util/TimeUtils.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit dbe4be5

Please sign in to comment.