From 028342d4a4f02793e9f4ae17b0b7d3eddb503381 Mon Sep 17 00:00:00 2001 From: Brummel Date: Fri, 24 Apr 2026 14:34:55 +0200 Subject: [PATCH] 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. --- .../java/com/doctate/watch/domain/CaseStoreStub.kt | 13 ++++++++----- .../doctate/watch/presentation/CaseListScreen.kt | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/watch/wearos/app/src/main/java/com/doctate/watch/domain/CaseStoreStub.kt b/watch/wearos/app/src/main/java/com/doctate/watch/domain/CaseStoreStub.kt index 4e2feb8..ceb24a6 100644 --- a/watch/wearos/app/src/main/java/com/doctate/watch/domain/CaseStoreStub.kt +++ b/watch/wearos/app/src/main/java/com/doctate/watch/domain/CaseStoreStub.kt @@ -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") } diff --git a/watch/wearos/app/src/main/java/com/doctate/watch/presentation/CaseListScreen.kt b/watch/wearos/app/src/main/java/com/doctate/watch/presentation/CaseListScreen.kt index 9cfa583..3f69f09 100644 --- a/watch/wearos/app/src/main/java/com/doctate/watch/presentation/CaseListScreen.kt +++ b/watch/wearos/app/src/main/java/com/doctate/watch/presentation/CaseListScreen.kt @@ -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()