Add "minutes ago" time formatting

Introduces a `minutesAgo` helper function and uses it in `CaseStoreStub`
to populate `CaseEntry` objects with relative timestamps for recent
activities. Also updates `formatTime` in `CaseListScreen` to display
"Gerade eben", "Vor 1 Minute", or "Vor X Minuten" for entries younger
than an hour. This provides a more user-friendly display for recent
cases.
This commit is contained in:
2026-04-24 14:34:55 +02:00
parent 50fbc2690e
commit 028342d4a4
2 changed files with 16 additions and 5 deletions
@@ -78,17 +78,20 @@ object CaseStoreStub {
val today = LocalDate.now(zone)
fun at(date: LocalDate, hour: Int, minute: Int): Long =
date.atTime(hour, minute).atZone(zone).toInstant().toEpochMilli()
fun minutesAgo(m: Long): Long = now - m * 60_000L
// Ordered newest -> oldest to satisfy the `lastActivityAt desc` invariant.
// Covers all three date-label variants: today (HH:mm), yesterday (Gestern - HH:mm), older (dd.MM.yy - HH:mm).
val recent = now - 20 * 60_000L
_cases.value = listOf(
CaseEntry(CaseId.new(), recent, recent, "Kniegelenksarthroskopie rechts"),
// Covers all label variants: "Vor 1 Minute" / "Vor X Minuten" / HH:mm /
// "Gestern - HH:mm" / "dd.MM.yy - HH:mm". `sortedByDescending` keeps the
// store invariant (newest first) intact regardless of the current time of day.
val entries = listOf(
CaseEntry(CaseId.new(), minutesAgo(1), minutesAgo(1), "Anamnese Herr Weber"),
CaseEntry(CaseId.new(), minutesAgo(32), minutesAgo(32), "Kniegelenksarthroskopie rechts"),
CaseEntry(CaseId.new(), at(today, 8, 15), at(today, 8, 15), "Befund Thorax unauffällig"),
CaseEntry(CaseId.new(), at(today.minusDays(1), 16, 40), at(today.minusDays(1), 16, 40), "Postoperative Visite Zimmer 12"),
CaseEntry(CaseId.new(), at(today.minusDays(3), 11, 20), at(today.minusDays(3), 11, 20), "MRT Schulter links"),
CaseEntry(CaseId.new(), at(today.minusDays(8), 9, 5), at(today.minusDays(8), 9, 5), "Laborkontrolle Diabetes"),
)
_cases.value = entries.sortedByDescending { it.lastActivityAt }
requestTileRefresh("seedDemoData")
}
@@ -128,6 +128,14 @@ private val timeFormat = DateTimeFormatter.ofPattern("HH:mm", Locale.getDefault(
private val dateTimeFormat = DateTimeFormatter.ofPattern("dd.MM.yy - HH:mm", Locale.getDefault())
private fun formatTime(epochMs: Long): String {
val ageMinutes = (System.currentTimeMillis() - epochMs) / 60_000L
if (ageMinutes in 0L until 60L) {
return when (ageMinutes) {
0L -> "Gerade eben"
1L -> "Vor 1 Minute"
else -> "Vor $ageMinutes Minuten"
}
}
val zone = ZoneId.systemDefault()
val created = Instant.ofEpochMilli(epochMs).atZone(zone)
val createdDate = created.toLocalDate()