MCPcopy Index your code
hub / github.com/coder/coder / shortRelativeTime

Function shortRelativeTime

site/src/utils/time.ts:107–137  ·  view source on GitHub ↗
(date: DateTimeInput)

Source from the content-addressed store, hash-verified

105 * sidebar timestamps.
106 */
107export function shortRelativeTime(date: DateTimeInput): string {
108 const now = dayjs();
109 const then = dayjs(date);
110 const diffSeconds = now.diff(then, "second");
111
112 if (diffSeconds < 60) {
113 return "now";
114 }
115 const diffMinutes = now.diff(then, "minute");
116 if (diffMinutes < 60) {
117 return `${diffMinutes}m`;
118 }
119 const diffHours = now.diff(then, "hour");
120 if (diffHours < 24) {
121 return `${diffHours}h`;
122 }
123 const diffDays = now.diff(then, "day");
124 if (diffDays < 7) {
125 return `${diffDays}d`;
126 }
127 const diffWeeks = now.diff(then, "week");
128 if (diffWeeks < 5) {
129 return `${diffWeeks}w`;
130 }
131 const diffMonths = now.diff(then, "month");
132 if (diffMonths < 12) {
133 return `${diffMonths}mo`;
134 }
135 const diffYears = now.diff(then, "year");
136 return `${diffYears}y`;
137}
138
139export function relativeTimeWithoutSuffix(date: DateTimeInput) {
140 return dayjs(date).fromNow(true);

Callers 3

time.test.tsFile · 0.90
ChatSearchResultRowFunction · 0.90
ChatTreeNodeFunction · 0.90

Calls 1

diffMethod · 0.65

Tested by

no test coverage detected