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

Function publishTimeRelativeShort

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

Source from the content-addressed store, hash-verified

32};
33
34export const publishTimeRelativeShort = (
35 value: Date | number | string,
36 now = new Date(),
37): string => {
38 const date = new Date(value);
39
40 // Calculate time delta in seconds.
41 const dt = (now.getTime() - date.getTime()) / 1000;
42
43 if (dt <= oneMinute) {
44 return 'now';
45 }
46
47 if (dt <= oneHour) {
48 const numMinutes = Math.round(dt / oneMinute);
49 return `${numMinutes}m`;
50 }
51
52 if (dt <= oneDay) {
53 const numHours = Math.round(dt / oneHour);
54 return `${numHours}h`;
55 }
56
57 if (dt <= oneWeek) {
58 const numDays = Math.round(dt / oneDay);
59 return `${numDays}d`;
60 }
61
62 if (dt <= oneYear) {
63 const numWeeks = Math.round(dt / oneWeek);
64 return `${numWeeks}w`;
65 }
66
67 const numYears = Math.round(dt / oneYear);
68 return `${numYears}y`;
69};
70
71// Full, readable date for the notification timestamp tooltip — e.g.
72// "15 April 2024 at 14:30".

Callers 7

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

Calls

no outgoing calls

Tested by

no test coverage detected