MCPcopy
hub / github.com/Fission-AI/OpenSpec / formatRelativeTime

Function formatRelativeTime

src/core/list.ts:58–77  ·  view source on GitHub ↗

* Format a date as relative time (e.g., "2 hours ago", "3 days ago")

(date: Date)

Source from the content-addressed store, hash-verified

56 * Format a date as relative time (e.g., "2 hours ago", "3 days ago")
57 */
58function formatRelativeTime(date: Date): string {
59 const now = new Date();
60 const diffMs = now.getTime() - date.getTime();
61 const diffSecs = Math.floor(diffMs / 1000);
62 const diffMins = Math.floor(diffSecs / 60);
63 const diffHours = Math.floor(diffMins / 60);
64 const diffDays = Math.floor(diffHours / 24);
65
66 if (diffDays > 30) {
67 return date.toLocaleDateString();
68 } else if (diffDays > 0) {
69 return `${diffDays}d ago`;
70 } else if (diffHours > 0) {
71 return `${diffHours}h ago`;
72 } else if (diffMins > 0) {
73 return `${diffMins}m ago`;
74 } else {
75 return 'just now';
76 }
77}
78
79export class ListCommand {
80 async execute(targetPath: string = '.', mode: 'changes' | 'specs' = 'changes', options: ListOptions = {}): Promise<void> {

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected