feat: add "Updated X ago" display for realtime indicators and implement auto-refresh tick functionality

This commit is contained in:
Usman Baig
2026-02-11 20:49:09 +01:00
parent 37257c40ad
commit 4aefca7118
3 changed files with 78 additions and 29 deletions

View File

@@ -25,6 +25,18 @@ export function getDateRange(days: number): { start: string; end: string } {
}
}
/**
* Format "updated X ago" for polling indicators (e.g. "Just now", "12 seconds ago")
*/
export function formatUpdatedAgo(timestamp: number): string {
const diff = Math.floor((Date.now() - timestamp) / 1000)
if (diff < 5) return 'Just now'
if (diff < 60) return `${diff} seconds ago`
if (diff < 120) return '1 minute ago'
const minutes = Math.floor(diff / 60)
return `${minutes} minutes ago`
}
/**
* Format relative time (e.g., "2 hours ago")
*/