MCPcopy Index your code
hub / github.com/simstudioai/sim / formatRelativeTime

Function formatRelativeTime

packages/utils/src/formatting.ts:226–256  ·  view source on GitHub ↗
(dateString: string)

Source from the content-addressed store, hash-verified

224 * @returns A human-readable relative time string
225 */
226export function formatRelativeTime(dateString: string): string {
227 const date = new Date(dateString)
228 const now = new Date()
229 const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000)
230
231 if (diffInSeconds < 60) {
232 return 'just now'
233 }
234 if (diffInSeconds < 3600) {
235 const minutes = Math.floor(diffInSeconds / 60)
236 return `${minutes}m ago`
237 }
238 if (diffInSeconds < 86400) {
239 const hours = Math.floor(diffInSeconds / 3600)
240 return `${hours}h ago`
241 }
242 if (diffInSeconds < 604800) {
243 const days = Math.floor(diffInSeconds / 86400)
244 return `${days}d ago`
245 }
246 if (diffInSeconds < 2592000) {
247 const weeks = Math.floor(diffInSeconds / 604800)
248 return `${weeks}w ago`
249 }
250 if (diffInSeconds < 31536000) {
251 const months = Math.floor(diffInSeconds / 2592000)
252 return `${months}mo ago`
253 }
254 const years = Math.floor(diffInSeconds / 31536000)
255 return `${years}y ago`
256}

Callers 3

BaseCardFunction · 0.90
InboxTaskListFunction · 0.90
formatting.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected