MCPcopy
hub / github.com/anomalyco/opencode / getRelativeTime

Function getRelativeTime

packages/app/src/utils/time.ts:9–22  ·  view source on GitHub ↗
(dateString: string, t: Translate)

Source from the content-addressed store, hash-verified

7type Translate = (key: TimeKey, params?: Record<string, string | number>) => string
8
9export function getRelativeTime(dateString: string, t: Translate): string {
10 const date = new Date(dateString)
11 const now = new Date()
12 const diffMs = now.getTime() - date.getTime()
13 const diffSeconds = Math.floor(diffMs / 1000)
14 const diffMinutes = Math.floor(diffSeconds / 60)
15 const diffHours = Math.floor(diffMinutes / 60)
16 const diffDays = Math.floor(diffHours / 24)
17
18 if (diffSeconds < 60) return t("common.time.justNow")
19 if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes })
20 if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours })
21 return t("common.time.daysAgo.short", { count: diffDays })
22}

Callers 1

DialogSelectFileFunction · 0.90

Calls 1

tFunction · 0.70

Tested by

no test coverage detected