Fix false stale Fleet reports caused by clock skew

This commit is contained in:
2026-09-19 20:17:43 -04:00
parent 345839fbd4
commit 1d073779fe
9 changed files with 224 additions and 15 deletions
+4 -4
View File
@@ -54,9 +54,9 @@
mapLabelOverride
}: Props = $props();
function ago(iso: string | null): string {
function ago(iso: string | null, now: number): string {
if (!iso) return 'never';
const d = Date.now() - new Date(iso).getTime();
const d = now - new Date(iso).getTime();
if (d < 60_000) return `${Math.max(1, Math.floor(d / 1000))}s ago`;
if (d < 3_600_000) return `${Math.floor(d / 60_000)}m ago`;
if (d < 86_400_000) return `${Math.floor(d / 3_600_000)}h ago`;
@@ -175,9 +175,9 @@
{#if health === 'offline' && lastError}
<span class="err">{lastError}</span>
{:else if lastSeenAt}
<span>Last seen {ago(lastSeenAt)}</span>
<span>Last seen {ago(lastSeenAt, $uiNow)}</span>
{:else if lastRestartedAt}
<span>Restart {ago(lastRestartedAt)}</span>
<span>Restart {ago(lastRestartedAt, $uiNow)}</span>
{:else}
<span class="dim">No data</span>
{/if}