From 3f9866e8a10a644c1e6f0d4406f48e153c03cdb6 Mon Sep 17 00:00:00 2001 From: Pouzor Date: Sun, 10 May 2026 21:45:22 +0200 Subject: [PATCH] fix(detail): handle non-Z timezone offsets in Last Seen Backend sends ISO timestamps with +00:00 offset. Code blindly appended 'Z' when the string didn't end with 'Z', producing '...+00:00Z' which parses to Invalid Date. Detect any timezone marker (Z, z, or numeric offset like +00:00) and only append 'Z' for naive datetimes. Co-authored-by: --- .../src/components/panels/DetailPanel.tsx | 2 +- .../panels/__tests__/DetailPanel.test.tsx | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/panels/DetailPanel.tsx b/frontend/src/components/panels/DetailPanel.tsx index 96d8cd4..cddd301 100644 --- a/frontend/src/components/panels/DetailPanel.tsx +++ b/frontend/src/components/panels/DetailPanel.tsx @@ -234,7 +234,7 @@ export function DetailPanel({ onEdit }: DetailPanelProps) { {data.mac && } {data.os && } {data.check_method && } - {data.last_seen && } + {data.last_seen && } {/* Properties section */} diff --git a/frontend/src/components/panels/__tests__/DetailPanel.test.tsx b/frontend/src/components/panels/__tests__/DetailPanel.test.tsx index 52c3c5f..1c12e31 100644 --- a/frontend/src/components/panels/__tests__/DetailPanel.test.tsx +++ b/frontend/src/components/panels/__tests__/DetailPanel.test.tsx @@ -487,4 +487,27 @@ describe('DetailPanel', () => { expect(screen.getByText('health').tagName).not.toBe('A') }) }) + + describe('Last Seen formatting', () => { + it('renders a valid date when last_seen has +00:00 offset (no Z)', () => { + setupStore({ last_seen: '2026-05-10T17:54:38.221403+00:00' }) + render() + const row = screen.getByText('Last Seen').parentElement + expect(row?.textContent).not.toMatch(/Invalid Date/) + }) + + it('renders a valid date when last_seen ends with Z', () => { + setupStore({ last_seen: '2026-05-10T17:54:38.221403Z' }) + render() + const row = screen.getByText('Last Seen').parentElement + expect(row?.textContent).not.toMatch(/Invalid Date/) + }) + + it('treats naive ISO strings as UTC', () => { + setupStore({ last_seen: '2026-05-10T17:54:38' }) + render() + const row = screen.getByText('Last Seen').parentElement + expect(row?.textContent).not.toMatch(/Invalid Date/) + }) + }) })