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

Function commentDateFormat

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

Source from the content-addressed store, hash-verified

151}
152
153export function commentDateFormat(
154 value: Date | number | string,
155 now = new Date(),
156): string {
157 const date = new Date(value);
158 const dt = (now.getTime() - date.getTime()) / 1000;
159
160 if (dt <= oneMinute) {
161 return 'Now';
162 }
163
164 if (dt <= oneHour) {
165 const numMinutes = Math.round(dt / oneMinute);
166 return `${numMinutes} ${numMinutes === 1 ? 'min' : 'mins'}`;
167 }
168
169 if (dt <= oneDay) {
170 const numHours = Math.round(dt / oneHour);
171 return `${numHours} ${numHours === 1 ? 'hr' : 'hrs'}`;
172 }
173
174 if (dt <= oneYear) {
175 return date.toLocaleString('en-US', {
176 month: 'short',
177 day: 'numeric',
178 });
179 }
180
181 return date.toLocaleString('en-US', {
182 month: 'short',
183 day: 'numeric',
184 year: 'numeric',
185 });
186}
187
188export const isDateOnlyEqual = (left: Date, right: Date): boolean => {
189 const formattedLeft = new Date(

Callers 1

dateFormat.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected