MCPcopy Create free account
hub / github.com/dailydotdev/apps / commentDateFormat

Function commentDateFormat

packages/shared/src/lib/dateFormat.ts:138–171  ·  view source on GitHub ↗
(
  value: Date | number | string,
  now = new Date(),
)

Source from the content-addressed store, hash-verified

136}
137
138export function commentDateFormat(
139 value: Date | number | string,
140 now = new Date(),
141): string {
142 const date = new Date(value);
143 const dt = (now.getTime() - date.getTime()) / 1000;
144
145 if (dt <= oneMinute) {
146 return 'Now';
147 }
148
149 if (dt <= oneHour) {
150 const numMinutes = Math.round(dt / oneMinute);
151 return `${numMinutes} ${numMinutes === 1 ? 'min' : 'mins'}`;
152 }
153
154 if (dt <= oneDay) {
155 const numHours = Math.round(dt / oneHour);
156 return `${numHours} ${numHours === 1 ? 'hr' : 'hrs'}`;
157 }
158
159 if (dt <= oneYear) {
160 return date.toLocaleString('en-US', {
161 month: 'short',
162 day: 'numeric',
163 });
164 }
165
166 return date.toLocaleString('en-US', {
167 month: 'short',
168 day: 'numeric',
169 year: 'numeric',
170 });
171}
172
173export const isDateOnlyEqual = (left: Date, right: Date): boolean => {
174 const formattedLeft = new Date(

Callers 1

dateFormat.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected