fix(android): collapse relativeTime returns to one branch (detekt ReturnCount)

Folded the early-return ladder in `relativeTime` into a single `when`
returning the result. Same four cutoff windows — `<1h` / `<24h` /
`<7d` / older — just bound to a single expression so detekt's
ReturnCount (limit 2) is satisfied. The opening "unparseable → return
raw" still uses an early return; that's only 2 total now.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-24 23:56:11 -04:00
parent 9d63030961
commit d10f13c9b1
@@ -185,22 +185,24 @@ private const val DAYS_PER_WEEK = 7L
* up the row over malformed timestamps.
*/
private fun relativeTime(iso: String): String {
val t = runCatching { OffsetDateTime.parse(iso) }.getOrNull() ?: return iso
val local = t.atZoneSameInstant(ZoneId.systemDefault())
val parsed = runCatching { OffsetDateTime.parse(iso) }.getOrNull()
?: return iso
val local = parsed.atZoneSameInstant(ZoneId.systemDefault())
val now = OffsetDateTime.now(ZoneId.systemDefault())
val minutes = ChronoUnit.MINUTES.between(local, now)
if (minutes < MINUTES_PER_HOUR) {
val m = if (minutes < 1) 1 else minutes
return "${m}m ago"
}
val hours = ChronoUnit.HOURS.between(local, now)
if (hours < HOURS_PER_DAY) return "${hours}h ago"
val days = ChronoUnit.DAYS.between(local, now)
if (days < DAYS_PER_WEEK) {
val dow = local.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault())
val time = local.toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm"))
return "$dow $time"
return when {
minutes < MINUTES_PER_HOUR -> "${minutes.coerceAtLeast(1)}m ago"
hours < HOURS_PER_DAY -> "${hours}h ago"
days < DAYS_PER_WEEK -> {
val dow = local.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault())
val time = local.toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm"))
"$dow $time"
}
else -> {
val pattern = if (local.year == now.year) "MMM d" else "MMM d, yyyy"
local.toLocalDate().format(DateTimeFormatter.ofPattern(pattern))
}
}
val pattern = if (local.year == now.year) "MMM d" else "MMM d, yyyy"
return local.toLocalDate().format(DateTimeFormatter.ofPattern(pattern))
}