Skip to content

Commit

Permalink
[FEATURE]#75 : LocalDateTime으로 일자 계산 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Aug 4, 2024
1 parent 43e3101 commit 0dd13c9
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bff.wespot.common.util

import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit

Expand All @@ -19,6 +20,17 @@ fun String.timeDifference(): Long {
return daysDifference
}

fun LocalDateTime.toDateString(): String {
val currentDateTime = LocalDateTime.now()
val daysBetween = ChronoUnit.DAYS.between(this, currentDateTime)

return when (daysBetween) {
0L -> "오늘"
in 1..7 -> "${daysBetween}일 전"
else -> this.format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))
}
}

fun Long.toDateString(date: String): String =
when(this) {
0L -> {
Expand Down

0 comments on commit 0dd13c9

Please sign in to comment.