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

Function publishTimeRelativeShort

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

Source from the content-addressed store, hash-verified

18 !Number.isNaN(date.getTime());
19
20export const publishTimeRelativeShort = (
21 value: Date | number | string,
22 now = new Date(),
23): string => {
24 const date = new Date(value);
25
26 // Calculate time delta in seconds.
27 const dt = (now.getTime() - date.getTime()) / 1000;
28
29 if (dt <= oneMinute) {
30 return 'now';
31 }
32
33 if (dt <= oneHour) {
34 const numMinutes = Math.round(dt / oneMinute);
35 return `${numMinutes}m`;
36 }
37
38 if (dt <= oneDay) {
39 const numHours = Math.round(dt / oneHour);
40 return `${numHours}h`;
41 }
42
43 if (dt <= oneWeek) {
44 const numDays = Math.round(dt / oneDay);
45 return `${numDays}d`;
46 }
47
48 if (dt <= oneYear) {
49 const numWeeks = Math.round(dt / oneWeek);
50 return `${numWeeks}w`;
51 }
52
53 const numYears = Math.round(dt / oneYear);
54 return `${numYears}y`;
55};
56
57// Full, readable date for the notification timestamp tooltip — e.g.
58// "15 April 2024 at 14:30".

Callers 6

NotificationItemFunction · 0.90
SignalList.tsxFile · 0.90
dateFormat.spec.tsFile · 0.90
publishTimeLiveTimerFunction · 0.85
postUpdatedDateFormatFunction · 0.85
formatDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected