From 142fafe0ed5cdd869706c4e97ebe201a07e9ef9f Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 16 Oct 2026 15:16:29 -0400 Subject: [PATCH] Android recent tags: reuse ui/Time.kt's epochMillis (#5931) RecentTags.kt declared a second epochMillis(String?): Long beside Time.kt's epochMillis(String): Long?. A string literal resolved to the existing one, so the test asserted 0 against its null. Co-Authored-By: Claude Opus 5.5 --- .../main/java/com/fabledsword/inkwell/ui/RecentTags.kt | 10 ++++------ .../java/com/fabledsword/inkwell/ui/RecentTagsTest.kt | 7 ++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/RecentTags.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/RecentTags.kt index 5f59315..739af97 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/RecentTags.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/RecentTags.kt @@ -10,7 +10,6 @@ import androidx.compose.ui.platform.LocalContext import com.fabledsword.inkwell.TagViews import com.fabledsword.inkwell.core.Label import com.fabledsword.inkwell.core.Note -import java.time.OffsetDateTime /** * The drawer lists the few tags in use rather than every tag (#5931), so a long @@ -47,17 +46,16 @@ fun tagRecency( notes: List, views: Map, ): Map { - val latest = labels.associate { it.id to maxOf(epochMillis(it.lastUsed), views[it.id] ?: 0L) }.toMutableMap() + // A missing or unreadable stamp counts as 0: such a tag simply ranks last. + val latest = labels.associate { it.id to maxOf(it.lastUsed.millis(), views[it.id] ?: 0L) }.toMutableMap() for (note in notes) { - val at = epochMillis(note.updatedAt) + val at = note.updatedAt.millis() for (label in note.labels) latest.computeIfPresent(label.id) { _, was -> maxOf(was, at) } } return latest } -/** 0 for a missing or unreadable stamp: such a tag simply ranks last. */ -fun epochMillis(stamp: String?): Long = - stamp?.let { runCatching { OffsetDateTime.parse(it).toInstant().toEpochMilli() }.getOrNull() } ?: 0L +private fun String?.millis(): Long = this?.let(::epochMillis) ?: 0L /** * When each tag's lens was last opened here. Opening one counts as using it, diff --git a/android/app/src/test/java/com/fabledsword/inkwell/ui/RecentTagsTest.kt b/android/app/src/test/java/com/fabledsword/inkwell/ui/RecentTagsTest.kt index 8e18036..4831da6 100644 --- a/android/app/src/test/java/com/fabledsword/inkwell/ui/RecentTagsTest.kt +++ b/android/app/src/test/java/com/fabledsword/inkwell/ui/RecentTagsTest.kt @@ -1,6 +1,7 @@ package com.fabledsword.inkwell.ui import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull import org.junit.Assert.assertSame import org.junit.Test @@ -32,10 +33,10 @@ class RecentTagsTest { } @Test - fun `reads both stamp forms the store holds`() { + fun `the shared epochMillis reads both stamp forms tag recency is built from`() { + // The core writes `Z` with milliseconds; a pulled server row may carry +00:00. assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20.000Z")) assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20+00:00")) - assertEquals(0L, epochMillis(null)) - assertEquals(0L, epochMillis("not a time")) + assertNull(epochMillis("not a time")) } }