19 lines
630 B
Kotlin
19 lines
630 B
Kotlin
package kr.co.vividnext.sodalive.extensions
|
|
|
|
import java.time.Duration
|
|
import java.time.LocalDateTime
|
|
|
|
fun LocalDateTime.getTimeAgoString(): String {
|
|
val now = LocalDateTime.now()
|
|
val duration = Duration.between(this, now)
|
|
|
|
return when {
|
|
duration.toMinutes() < 1 -> "방금 전"
|
|
duration.toMinutes() < 60 -> "${duration.toMinutes()}분전"
|
|
duration.toHours() < 24 -> "${duration.toHours()}시간전"
|
|
duration.toDays() < 30 -> "${duration.toDays()}일전"
|
|
duration.toDays() < 365 -> "${duration.toDays() / 30}개월전"
|
|
else -> "${duration.toDays() / 365}년전"
|
|
}
|
|
}
|