MCPcopy Create free account
hub / github.com/AIScientists-Dev/Flowtrace / formatRelativeTime

Function formatRelativeTime

frontend/src/shared/lib/date-utils.ts:47–68  ·  view source on GitHub ↗
(timestamp: string, locale = 'en-US')

Source from the content-addressed store, hash-verified

45 * Uses user's local timezone.
46 */
47export function formatRelativeTime(timestamp: string, locale = 'en-US'): string {
48 try {
49 const date = parseTimestamp(timestamp)
50 if (isNaN(date.getTime())) return ''
51
52 const rtf = getRelativeTimeFormatter(locale)
53 const diffMs = date.getTime() - Date.now()
54 const absDiffMs = Math.abs(diffMs)
55
56 if (absDiffMs < 30 * 1000) {
57 return rtf.format(0, 'second')
58 }
59 if (absDiffMs < HOUR_MS) return rtf.format(Math.round(diffMs / MINUTE_MS), 'minute')
60 if (absDiffMs < DAY_MS) return rtf.format(Math.round(diffMs / HOUR_MS), 'hour')
61 if (absDiffMs < WEEK_MS) return rtf.format(Math.round(diffMs / DAY_MS), 'day')
62 if (absDiffMs < MONTH_MS) return rtf.format(Math.round(diffMs / WEEK_MS), 'week')
63 if (absDiffMs < YEAR_MS) return rtf.format(Math.round(diffMs / MONTH_MS), 'month')
64 return rtf.format(Math.round(diffMs / YEAR_MS), 'year')
65 } catch {
66 return ''
67 }
68}

Callers 2

runLabelFunction · 0.90
metaSuffixFunction · 0.90

Calls 2

parseTimestampFunction · 0.85
getRelativeTimeFormatterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…