Update demo data and time formatting
Refactor `seedDemoData` to use `java.time` for more accurate date and time generation, including specific times for today, yesterday, and older dates. Update `formatTime` in `CaseListScreen` to leverage `java.time` for a more robust and localized date and time formatting, supporting "today", "yesterday", and older date formats.
This commit is contained in:
@@ -4,6 +4,8 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.wear.tiles.TileService
|
||||
import com.doctate.watch.tile.DoctateTileService
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -72,11 +74,20 @@ object CaseStoreStub {
|
||||
|
||||
fun seedDemoData(now: Long = System.currentTimeMillis()) {
|
||||
if (_cases.value.isNotEmpty()) return
|
||||
val hour = 60L * 60L * 1_000L
|
||||
val zone = ZoneId.systemDefault()
|
||||
val today = LocalDate.now(zone)
|
||||
fun at(date: LocalDate, hour: Int, minute: Int): Long =
|
||||
date.atTime(hour, minute).atZone(zone).toInstant().toEpochMilli()
|
||||
|
||||
// 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(), now - 20 * 60_000L, now - 20 * 60_000L, "Kniegelenksarthroskopie rechts"),
|
||||
CaseEntry(CaseId.new(), now - 2 * hour, now - 2 * hour, "Befund Thorax unauffällig"),
|
||||
CaseEntry(CaseId.new(), now - 4 * hour, now - 4 * hour, "Postoperative Visite"),
|
||||
CaseEntry(CaseId.new(), recent, recent, "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"),
|
||||
)
|
||||
requestTileRefresh("seedDemoData")
|
||||
}
|
||||
|
||||
@@ -26,8 +26,10 @@ import androidx.wear.compose.material3.ScreenScaffold
|
||||
import androidx.wear.compose.material3.Text
|
||||
import com.doctate.watch.domain.CaseEntry
|
||||
import com.doctate.watch.domain.CaseStoreStub
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
|
||||
@Composable
|
||||
@@ -109,6 +111,17 @@ private fun EmptyState(onNewCase: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
private val timeFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||
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 = timeFormat.format(Date(epochMs))
|
||||
private fun formatTime(epochMs: Long): String {
|
||||
val zone = ZoneId.systemDefault()
|
||||
val created = Instant.ofEpochMilli(epochMs).atZone(zone)
|
||||
val createdDate = created.toLocalDate()
|
||||
val today = LocalDate.now(zone)
|
||||
return when (createdDate) {
|
||||
today -> created.format(timeFormat)
|
||||
today.minusDays(1) -> "Gestern - ${created.format(timeFormat)}"
|
||||
else -> created.format(dateTimeFormat)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user