(lastSeenAt: number | null, now: number = Date.now())
| 35 | * sighting) reads as "Never", not "unknown". |
| 36 | */ |
| 37 | export const formatLastSeen = (lastSeenAt: number | null, now: number = Date.now()): string => { |
| 38 | if (lastSeenAt === null) return "Never"; |
| 39 | const delta = now - lastSeenAt; |
| 40 | if (delta < HOUR) return "Within the hour"; |
| 41 | if (delta < DAY) { |
| 42 | const hours = Math.floor(delta / HOUR); |
| 43 | return hours === 1 ? "About 1 hour ago" : `About ${hours} hours ago`; |
| 44 | } |
| 45 | const days = Math.floor(delta / DAY); |
| 46 | if (days === 1) return "About 1 day ago"; |
| 47 | if (days < 30) return `About ${days} days ago`; |
| 48 | return new Intl.DateTimeFormat(undefined, { |
| 49 | month: "short", |
| 50 | day: "numeric", |
| 51 | year: "numeric", |
| 52 | }).format(new Date(lastSeenAt)); |
| 53 | }; |
| 54 | |
| 55 | /** The tooltip behind {@link formatLastSeen}: the exact recorded instant plus |
| 56 | * the coarseness caveat, so an operator reading "Within the hour" can see what |
no outgoing calls
no test coverage detected