MCPcopy Create free account
hub / github.com/HairlessVillager/minecommit / formatDate

Function formatDate

minecommit-gui/src/components/commit-graph.tsx:468–486  ·  view source on GitHub ↗
(date: string | Date)

Source from the content-addressed store, hash-verified

466}
467
468function formatDate(date: string | Date): string {
469 const d = typeof date === "string" ? new Date(date) : date
470 const now = new Date()
471 const diffMs = now.getTime() - d.getTime()
472 const diffMins = Math.floor(diffMs / 60_000)
473 const diffHours = Math.floor(diffMs / 3_600_000)
474 const diffDays = Math.floor(diffMs / 86_400_000)
475
476 if (diffMins < 1) return "just now"
477 if (diffMins < 60) return `${diffMins}m ago`
478 if (diffHours < 24) return `${diffHours}h ago`
479 if (diffDays < 7) return `${diffDays}d ago`
480
481 return d.toLocaleDateString("en-US", {
482 month: "short",
483 day: "numeric",
484 year: d.getFullYear() !== now.getFullYear() ? "numeric" : undefined,
485 })
486}
487
488function formatFullDate(date: string | Date): string {
489 const d = typeof date === "string" ? new Date(date) : date

Callers 1

CommitGraphFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected