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

Function getLastActivityDateFormat

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

Source from the content-addressed store, hash-verified

247};
248
249export const getLastActivityDateFormat = (
250 value: Date | number | string,
251 options?: {
252 maxHoursAgo?: number;
253 },
254): string => {
255 const date = new Date(value);
256 const now = new Date();
257 const maxHoursAgo = options?.maxHoursAgo ?? 24;
258 const maxHoursAgoInSeconds = maxHoursAgo * oneHour;
259
260 // Calculate time delta in seconds.
261 const dt = (now.getTime() - date.getTime()) / 1000;
262
263 if (dt <= oneMinute) {
264 return 'Now';
265 }
266
267 if (dt <= oneHour) {
268 const numMinutes = Math.round(dt / oneMinute);
269 return `${numMinutes}m ago`;
270 }
271
272 if (dt <= maxHoursAgoInSeconds) {
273 const numHours = Math.round(dt / oneHour);
274 return `${numHours}h ago`;
275 }
276
277 if (dt <= oneWeek) {
278 const numDays = Math.round(dt / oneDay);
279 return `${numDays}d ago`;
280 }
281
282 return date.toLocaleString('en-US', {
283 month: 'short',
284 day: '2-digit',
285 });
286};
287
288const publishExperienceTime = (start: Date, end?: Date): string => {
289 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