From 231b3c0e0d818683bb82d2b286970cf7d19c9f77 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Tue, 9 Jun 2026 17:23:50 +0200 Subject: [PATCH] fix(NearbyScreen): sort "?" entries to bottom in TIME filter Contacts with lastmod=0 or lastmod>now (RTC not synced after reboot but contacts have timestamps from a prior session) were sorted to the top because their raw lastmod > 0. Now both cases are normalised to 0 before the comparison, so unknown-time entries always appear at the bottom. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/ui-new/NearbyScreen.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/ui-new/NearbyScreen.h b/examples/companion_radio/ui-new/NearbyScreen.h index 32250950..ed0d05be 100644 --- a/examples/companion_radio/ui-new/NearbyScreen.h +++ b/examples/companion_radio/ui-new/NearbyScreen.h @@ -139,11 +139,14 @@ class NearbyScreen : public UIScreen { e.lastmod = ci.lastmod; } + uint32_t _now_ts = rtc_clock.getCurrentTime(); for (int i = 0; i < _count - 1; i++) { int best = i; for (int j = i + 1; j < _count; j++) { if (_filter == FILTER_COUNT - 1) { - uint32_t tj = _entries[j].lastmod, tb = _entries[best].lastmod; + // Treat lastmod=0 or lastmod>now (RTC not synced) as "unknown" → sort to bottom. + uint32_t tj = (_entries[j].lastmod > 0 && _now_ts >= _entries[j].lastmod) ? _entries[j].lastmod : 0; + uint32_t tb = (_entries[best].lastmod > 0 && _now_ts >= _entries[best].lastmod) ? _entries[best].lastmod : 0; if (tj > 0 && (tb == 0 || tj > tb)) best = j; // descending — most recent first } else { float dj = _entries[j].dist_km, db = _entries[best].dist_km;