Detail formatting to shared: use buildFoundDetailStrings in KlotterDialog (millis→strings via commonMain)

This commit is contained in:
2025-09-18 16:45:59 +02:00
parent cf049bade1
commit 722763fccb
2 changed files with 54 additions and 20 deletions

View File

@@ -0,0 +1,38 @@
package app.klottr.util
/**
* Delad formatterare för detaljvyn.
* - created/updated: null = dölj raden; icke-null = redan formaterad text via formatRelativeOrTime(...)
* - first/last visit: alltid sträng; använd "-" när okänt.
*/
data class FoundDetailStrings(
val createdText: String?, // null = döljs i UI
val updatedText: String?, // null = döljs i UI eller visas bara om skiljt från created
val firstVisitText: String, // "-" om okänt
val lastVisitText: String // "-" om okänt
)
/**
* Bygger fyra texter utifrån millisekunder (UTC epoch).
* @param createdMs kan vara null → createdText = null
* @param updatedMs kan vara null → updatedText = null
* @param firstVisitMs kan vara null → "-"
* @param lastVisitMs kan vara null → "-"
*/
fun buildFoundDetailStrings(
createdMs: Long?,
updatedMs: Long?,
firstVisitMs: Long?,
lastVisitMs: Long?
): FoundDetailStrings {
val created = createdMs?.let { formatRelativeOrTime(it) }
val updated = updatedMs?.let { formatRelativeOrTime(it) }
val firstV = firstVisitMs?.let { formatRelativeOrTime(it) } ?: "-"
val lastV = lastVisitMs?.let { formatRelativeOrTime(it) } ?: "-"
return FoundDetailStrings(
createdText = created,
updatedText = updated,
firstVisitText = firstV,
lastVisitText = lastV
)
}