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

Function getLastActivityDateFormat

packages/shared/src/lib/dateFormat.ts:238–275  ·  view source on GitHub ↗
(
  value: Date | number | string,
  options?: {
    maxHoursAgo?: number;
  },
)

Source from the content-addressed store, hash-verified

236};
237
238export const getLastActivityDateFormat = (
239 value: Date | number | string,
240 options?: {
241 maxHoursAgo?: number;
242 },
243): string => {
244 const date = new Date(value);
245 const now = new Date();
246 const maxHoursAgo = options?.maxHoursAgo ?? 24;
247 const maxHoursAgoInSeconds = maxHoursAgo * oneHour;
248
249 // Calculate time delta in seconds.
250 const dt = (now.getTime() - date.getTime()) / 1000;
251
252 if (dt <= oneMinute) {
253 return 'Now';
254 }
255
256 if (dt <= oneHour) {
257 const numMinutes = Math.round(dt / oneMinute);
258 return `${numMinutes}m ago`;
259 }
260
261 if (dt <= maxHoursAgoInSeconds) {
262 const numHours = Math.round(dt / oneHour);
263 return `${numHours}h ago`;
264 }
265
266 if (dt <= oneWeek) {
267 const numDays = Math.round(dt / oneDay);
268 return `${numDays}d ago`;
269 }
270
271 return date.toLocaleString('en-US', {
272 month: 'short',
273 day: '2-digit',
274 });
275};
276
277const publishExperienceTime = (start: Date, end?: Date): string => {
278 const difference =

Callers 5

RelativeTimeFunction · 0.90
MatchProfileFunction · 0.90
dateFormat.spec.tsFile · 0.90
CandidateCardFunction · 0.90
formatDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected