mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Air][AIR-58] Chats history panel
GitOrigin-RevId: 041899a9ddd2be18c514d888af433af6e8dbad9d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
912e587e77
commit
b78007c38c
@@ -3,6 +3,7 @@ package fleet.util
|
||||
|
||||
import java.time.*
|
||||
import java.time.format.DateTimeFormatter
|
||||
import kotlin.time.toKotlinDuration
|
||||
|
||||
private val TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm")
|
||||
private val DATE_FORMATTER = DateTimeFormatter.ofPattern("MMM d")
|
||||
@@ -32,4 +33,28 @@ fun LocalDateTime.formatTimestamp(shorten: Boolean): String {
|
||||
return DATE_WITH_YEAR_FORMATTER.format(ldt)
|
||||
}
|
||||
return FULL_FORMATTER.format(ldt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun prettyDate(time: Long): String {
|
||||
val ldt = utcSeconds(time / 1000)
|
||||
val now = OffsetDateTime.now()
|
||||
|
||||
val dif = Duration.between(ldt, now).toKotlinDuration()
|
||||
return when {
|
||||
dif.inWholeSeconds < 60 -> "Now"
|
||||
dif.inWholeMinutes < 60 -> "${dif.inWholeMinutes} min ago"
|
||||
dif.inWholeHours == 1L -> "1 hour ago"
|
||||
dif.inWholeHours < 10 -> "${dif.inWholeHours} hours ago"
|
||||
dif.inWholeDays == 0L && ldt.dayOfYear == now.dayOfYear -> "Today"
|
||||
dif.inWholeDays < 365 -> {
|
||||
val month = ldt.month.name.lowercase().replaceFirstChar { it.uppercase() }.substring(0, 3)
|
||||
val day = ldt.dayOfMonth.toString().padStart(2, '0')
|
||||
"${month} ${day}"
|
||||
}
|
||||
else -> {
|
||||
val years = now.year - ldt.year
|
||||
"$years year${if (years > 1) "s" else ""} ago"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user