MCPcopy
hub / github.com/21st-dev/1code / formatTime

Function formatTime

src/renderer/features/agents/ui/archive-popover.tsx:68–83  ·  view source on GitHub ↗
(dateInput: Date | string)

Source from the content-addressed store, hash-verified

66
67// Format relative time - moved outside component to avoid recreation
68const formatTime = (dateInput: Date | string) => {
69 const date = dateInput instanceof Date ? dateInput : new Date(dateInput)
70 const now = new Date()
71 const diffMs = now.getTime() - date.getTime()
72 const diffMins = Math.floor(diffMs / 60000)
73 const diffHours = Math.floor(diffMs / 3600000)
74 const diffDays = Math.floor(diffMs / 86400000)
75
76 if (diffMins < 1) return "now"
77 if (diffMins < 60) return `${diffMins}m`
78 if (diffHours < 24) return `${diffHours}h`
79 if (diffDays < 7) return `${diffDays}d`
80 if (diffDays < 30) return `${Math.floor(diffDays / 7)}w`
81 if (diffDays < 365) return `${Math.floor(diffDays / 30)}mo`
82 return `${Math.floor(diffDays / 365)}y`
83}
84
85// Normalized chat type for archive popover (works with both local and remote chats)
86interface NormalizedArchivedChat {

Callers 2

agents-sidebar.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected