From d10f13c9b14e04fe03f9709f558552eb7d0d83b0 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 24 May 2026 23:56:11 -0400 Subject: [PATCH] fix(android): collapse relativeTime returns to one branch (detekt ReturnCount) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../minstrel/history/ui/HistoryTab.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/history/ui/HistoryTab.kt b/android/app/src/main/java/com/fabledsword/minstrel/history/ui/HistoryTab.kt index 9f399d7a..7dfae70a 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/history/ui/HistoryTab.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/history/ui/HistoryTab.kt @@ -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)) }