MCPcopy Create free account
hub / github.com/47ng/nuqs / formatDate

Function formatDate

packages/docs/src/components/commit-graph.tsx:537–555  ·  view source on GitHub ↗
(date: string | Date)

Source from the content-addressed store, hash-verified

535}
536
537function formatDate(date: string | Date): string {
538 const d = typeof date === 'string' ? new Date(date) : date
539 const now = new Date()
540 const diffMs = now.getTime() - d.getTime()
541 const diffMins = Math.floor(diffMs / 60_000)
542 const diffHours = Math.floor(diffMs / 3_600_000)
543 const diffDays = Math.floor(diffMs / 86_400_000)
544
545 if (diffMins < 1) return 'just now'
546 if (diffMins < 60) return `${diffMins}m ago`
547 if (diffHours < 24) return `${diffHours}h ago`
548 if (diffDays < 7) return `${diffDays}d ago`
549
550 return d.toLocaleDateString('en-US', {
551 month: 'short',
552 day: 'numeric',
553 year: d.getFullYear() !== now.getFullYear() ? 'numeric' : undefined
554 })
555}
556
557function formatFullDate(date: string | Date): string {
558 const d = typeof date === 'string' ? new Date(date) : date

Callers 1

CommitGraphFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected