From 50b29ff0a2629f13947f7b381e20116ad062486d Mon Sep 17 00:00:00 2001 From: teernisse Date: Fri, 30 Jan 2026 09:25:51 -0500 Subject: [PATCH] Display session duration in sidebar and simplify date formatting Show human-readable session duration (e.g. "23m", "1h 15m") in the session list metadata row when duration > 0. Add formatSessionDuration helper that handles sub-minute, minute-only, and hour+minute ranges. Also replace try/catch in formatDate with an isNaN guard on the parsed Date, which is more idiomatic and avoids swallowing unrelated errors. Co-Authored-By: Claude Opus 4.5 --- src/client/components/SessionList.tsx | 35 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/client/components/SessionList.tsx b/src/client/components/SessionList.tsx index eb4f90a..0de3bf9 100644 --- a/src/client/components/SessionList.tsx +++ b/src/client/components/SessionList.tsx @@ -96,6 +96,12 @@ export function SessionList({ sessions, loading, selectedId, onSelect }: Props) {formatDate(session.modified || session.created)} · {session.messageCount} msgs + {session.duration && session.duration > 0 && ( + <> + · + {formatSessionDuration(session.duration)} + + )} ); @@ -154,17 +160,24 @@ function formatProjectName(project: string): string { return project; } +function formatSessionDuration(ms: number): string { + const minutes = Math.floor(ms / 60000); + if (minutes < 1) return "<1m"; + if (minutes < 60) return `${minutes}m`; + const hours = Math.floor(minutes / 60); + const rem = minutes % 60; + if (rem === 0) return `${hours}h`; + return `${hours}h ${rem}m`; +} + function formatDate(dateStr: string): string { if (!dateStr) return ""; - try { - const d = new Date(dateStr); - return d.toLocaleDateString(undefined, { - month: "short", - day: "numeric", - hour: "2-digit", - minute: "2-digit", - }); - } catch { - return dateStr; - } + const d = new Date(dateStr); + if (isNaN(d.getTime())) return dateStr; + return d.toLocaleDateString(undefined, { + month: "short", + day: "numeric", + hour: "2-digit", + minute: "2-digit", + }); }