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

Function getLastActivityDateFormat

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

Source from the content-addressed store, hash-verified

221};
222
223export const getLastActivityDateFormat = (
224 value: Date | number | string,
225 options?: {
226 maxHoursAgo?: number;
227 },
228): string => {
229 const date = new Date(value);
230 const now = new Date();
231 const maxHoursAgo = options?.maxHoursAgo ?? 24;
232 const maxHoursAgoInSeconds = maxHoursAgo * oneHour;
233
234 // Calculate time delta in seconds.
235 const dt = (now.getTime() - date.getTime()) / 1000;
236
237 if (dt <= oneMinute) {
238 return 'Now';
239 }
240
241 if (dt <= oneHour) {
242 const numMinutes = Math.round(dt / oneMinute);
243 return `${numMinutes}m ago`;
244 }
245
246 if (dt <= maxHoursAgoInSeconds) {
247 const numHours = Math.round(dt / oneHour);
248 return `${numHours}h ago`;
249 }
250
251 if (dt <= oneWeek) {
252 const numDays = Math.round(dt / oneDay);
253 return `${numDays}d ago`;
254 }
255
256 return date.toLocaleString('en-US', {
257 month: 'short',
258 day: '2-digit',
259 });
260};
261
262const publishExperienceTime = (start: Date, end?: Date): string => {
263 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