MCPcopy Index your code
hub / github.com/github/awesome-copilot / formatRelativeTime

Function formatRelativeTime

website/src/scripts/utils.ts:696–727  ·  view source on GitHub ↗
(isoDate: string | null | undefined)

Source from the content-addressed store, hash-verified

694 * @returns Relative time string
695 */
696export function formatRelativeTime(isoDate: string | null | undefined): string {
697 if (!isoDate) return "Unknown";
698
699 const date = new Date(isoDate);
700 if (isNaN(date.getTime())) return "Unknown";
701
702 const now = new Date();
703 const diffMs = now.getTime() - date.getTime();
704 const diffSeconds = Math.floor(diffMs / 1000);
705 const diffMinutes = Math.floor(diffSeconds / 60);
706 const diffHours = Math.floor(diffMinutes / 60);
707 const diffDays = Math.floor(diffHours / 24);
708 const diffWeeks = Math.floor(diffDays / 7);
709 const diffMonths = Math.floor(diffDays / 30);
710 const diffYears = Math.floor(diffDays / 365);
711
712 if (diffDays === 0) {
713 if (diffHours === 0) {
714 if (diffMinutes === 0) return "just now";
715 return diffMinutes === 1 ? "1 minute ago" : `${diffMinutes} minutes ago`;
716 }
717 return diffHours === 1 ? "1 hour ago" : `${diffHours} hours ago`;
718 }
719 if (diffDays === 1) return "yesterday";
720 if (diffDays < 7) return `${diffDays} days ago`;
721 if (diffWeeks === 1) return "1 week ago";
722 if (diffWeeks < 4) return `${diffWeeks} weeks ago`;
723 if (diffMonths === 1) return "1 month ago";
724 if (diffMonths < 12) return `${diffMonths} months ago`;
725 if (diffYears === 1) return "1 year ago";
726 return `${diffYears} years ago`;
727}
728
729/**
730 * Format a date for display (e.g., "January 15, 2026")

Callers 8

openSkillDetailsModalFunction · 0.90
openDetailsModalFunction · 0.90
openAgentDetailsModalFunction · 0.90
openWorkflowDetailsModalFunction · 0.90
openHookDetailsModalFunction · 0.90
openPluginDetailsModalFunction · 0.90
getLastUpdatedHtmlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected