MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / fuzzyTimeAgo

Function fuzzyTimeAgo

webapp/src/lib/util.ts:34–47  ·  view source on GitHub ↗
(date: Date | string)

Source from the content-addressed store, hash-verified

32}
33
34export function fuzzyTimeAgo(date: Date | string): string {
35 const now = new Date();
36 if (isToday(date)) return 'Today';
37 if (isYesterday(date)) return 'Yesterday';
38
39 const days = differenceInCalendarDays(now, date);
40 if (days < 7) return `${days} day${days > 1 ? 's' : ''} ago`;
41
42 const weeks = differenceInCalendarWeeks(now, date);
43 if (weeks < 4) return `${weeks} week${weeks > 1 ? 's' : ''} ago`;
44
45 const months = differenceInCalendarMonths(now, date);
46 return `${months} month${months > 1 ? 's' : ''} ago`;
47}
48
49export function timeAgo(date: Date | string): string {
50 return formatDistanceToNow(date, { addSuffix: true });

Callers 1

QuestionDetailedHeaderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…