Skip to content

Commit

Permalink
[FEATURE] #81 : 현재 날짜와 마감기한 비교하는 로직 구현 및 마감기한 자연어로 변환하는 로직 도메인 모델로 마이…
Browse files Browse the repository at this point in the history
…그레이션
  • Loading branch information
jeongjaino committed Jan 5, 2024
1 parent 326cfab commit 50f0585
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wap.wapp.core.model.survey

import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

// 운영진이 등록하는 설문 모델
data class SurveyForm(
Expand All @@ -17,4 +19,31 @@ data class SurveyForm(
emptyList(),
LocalDateTime.MIN,
)

fun calculateDeadline(): String {
val currentDateTime = LocalDateTime.now()
val duration = Duration.between(currentDateTime, deadline)

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 deadline.format(DateTimeFormatter.ofPattern("yyyy.MM.dd")) + " 마감"
}

fun isAfterDeadline(): Boolean {
val currentDateTime = LocalDateTime.now()
return deadline.isAfter(currentDateTime)
}
}

0 comments on commit 50f0585

Please sign in to comment.