/** * How long ago, in the product's words - **one spelling, everywhere something says how long it has been.** * * MOVED HERE 2026-08-22 from `ReceptionistHomePage/frontDeskQueues.ts`, which is where it was written * and which re-exports it so every existing import keeps working unchanged. Its own note there gave the * reason it exists, and that reason applies past the front desk: *"the elapsed column, the late toast and * the row's own state label all say how long something has been true, and three spellings of that is * three answers to one question."* * * **Spencer, 2026-08-22:** *"405m should show in hours."* The clinician overview's in-progress badge * was rendering raw minutes with no hour rollover at all, so a visit open since the morning read **405m**. * It is the fourth spelling of this in the codebase; it is now the first caller of the shared one * rather than the fourth copy. * * The ladder, and each step is a deliberate choice about what the reader needs: * | elapsed | reads | * |---|---| * | under a minute | `now` - a number that changes while you look at it is noise | * | under an hour | `12m` | * | under a day | `6h 45m`, or `6h` on the hour - minutes still matter inside a working day | * | a day or more | `2d 3h`, or `2d` - minutes have stopped meaning anything by then | * * `now` is injectable ONLY so this can be asserted at a fixed instant. Every caller passes nothing. */ export const formatElapsedSince = (timestamp: number, now = Date.now()): string => { const elapsedMinutes = Math.floor(Math.max(0, now - timestamp) / 60_000); if (elapsedMinutes < 1) return 'now'; if (elapsedMinutes < 60) return `${elapsedMinutes}m`; const elapsedHours = Math.floor(elapsedMinutes / 60); if (elapsedHours < 24) { const remainingMinutes = elapsedMinutes % 60; return remainingMinutes > 0 ? `${elapsedHours}h ${remainingMinutes}m` : `${elapsedHours}h`; } const elapsedDays = Math.floor(elapsedHours / 24); const remainingHours = elapsedHours % 24; return remainingHours > 0 ? `${elapsedDays}d ${remainingHours}h` : `${elapsedDays}d`; };