Skip to content

Commit

Permalink
[FEATURE] #140 : 설문 시각 계산 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Mar 2, 2024
1 parent 2fd00fb commit 29b528d
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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

/*
회원이 작성하는 설문 모델
Expand All @@ -15,4 +18,33 @@ data class Survey(
val content: String,
val surveyAnswerList: List<SurveyAnswer>,
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")
}
}

0 comments on commit 29b528d

Please sign in to comment.