Menu

Our desktop clock can say 134 different ages, and "60s ago" is not one of them while "in 60s" is
📰

Our desktop clock can say 134 different ages, and "60s ago" is not one of them while "in 60s" is

DEV Community: typescript·Daniel Pertu·4 days ago
#nYiLmLPr
#devtotypescript#devto#dev#seconds#math
Reading 0:00
15s threshold

Notifio's desktop UI is mostly a list of searches with a time next to each one. "checked 12s ago". "last check 4m ago". A found listing says when it turned up. There is no chart and no dashboard, because the only question the window has to answer continuously is "is this thing still working", and an age is the cheapest possible answer to it.

All of that comes out of one file with three functions in it:

// app/src/renderer/format.ts /** "12s ago", "4m ago", "2h ago". Empty string for a null timestamp. */ export function relativeTime ( at : number | null ) : string { if ( ! at ) return "" ; const seconds = Math . max ( 0 , Math . round ( ( Date . now ( ) - at ) / 1000 ) ) ; if ( seconds < 10 ) return "just now" ; if ( seconds < 60 ) return `${seconds}s ago` ; const minutes = Math . round ( seconds / 60 ) ; if ( minutes < 60 ) return `${minutes}m ago` ; const hours = Math .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.