diff --git a/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt b/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt index 1c39f74e..4662b99f 100644 --- a/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt +++ b/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt @@ -1,6 +1,9 @@ package com.wap.wapp.core.model.survey +import java.time.Duration import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter /* 회원이 작성하는 설문 모델 @@ -15,4 +18,33 @@ data class Survey( val content: String, val surveyAnswerList: List, val surveyedAt: LocalDateTime, -) +) { + fun calculateSurveyedAt(): String { + val currentDateTime = LocalDateTime.now(TIME_ZONE_SEOUL) + val duration = Duration.between(surveyedAt, currentDateTime) + + if (duration.toMinutes() == 0L) { + return "방금" + } else if (duration.toMinutes() < 60) { + val leftMinutes = duration.toMinutes().toString() + return leftMinutes + "분 전 작성" + } + + if (duration.toHours() < 24) { + val leftHours = duration.toHours().toString() + return leftHours + "시간 전 작성" + } + + if (duration.toDays() < 31) { + val leftDays = duration.toDays().toString() + return leftDays + "일 전 작성" + } + + return surveyedAt.format(yyyyMMddFormatter) + " 작성" + } + + companion object { + val yyyyMMddFormatter = DateTimeFormatter.ofPattern("yyyy.MM.dd") + val TIME_ZONE_SEOUL = ZoneId.of("Asia/Seoul") + } +}