// - render the proxy (act-as) session duration the server now sends as a real number. // // Before this the duration lived only inside the human description ("...(duration 252000ms)"), so the // feed could print that sentence verbatim but never reformat or sort by it without regexing prose. // // UNDEFINED IS NOT ZERO, and that distinction is the whole reason the structured field exists. // Virtually every row in this feed - reads, changes, sign-ins - has NO duration; only a proxy access-end // does. A `?? 0` anywhere in this path would stamp "0s" onto all of them. Zero itself is a legitimate // value (a session opened and closed inside one millisecond), so it must render, which is exactly why // "absent" cannot be represented as 0. // // Anything nonsensical - NaN, Infinity, negative (a clock problem, not a fact about the session) - // degrades to undefined so the caller shows nothing. A patient's own access log is the last place to // display "NaN" or assert a negative duration. export function formatSessionDuration(durationMs: number | undefined): string | undefined { if (durationMs === undefined || !Number.isFinite(durationMs) || durationMs < 0) { return undefined; } const totalSeconds = Math.round(durationMs / 1000); const hours = Math.floor(totalSeconds / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); const seconds = totalSeconds % 60; // Two units at most: "1h 1m" and "4m 12s" read cleanly, "1h 1m 12s" is noise on a feed row. if (hours > 0) { return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`; } if (minutes > 0) { return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`; } return `${seconds}s`; }