MCPcopy Create free account
hub / github.com/pollinations/pollinations / formatRelativeTime

Function formatRelativeTime

apps/chat/src/components/Sidebar.jsx:5–20  ·  view source on GitHub ↗
(timestamp)

Source from the content-addressed store, hash-verified

3import "./styles/Sidebar.css";
4
5const formatRelativeTime = (timestamp) => {
6 if (!timestamp) return "";
7 const now = Date.now();
8 const diff = now - new Date(timestamp).getTime();
9 const min = Math.floor(diff / 60000);
10 const hr = Math.floor(diff / 3600000);
11 const day = Math.floor(diff / 86400000);
12 if (min < 1) return "just now";
13 if (min < 60) return `${min}m ago`;
14 if (hr < 24) return `${hr}h ago`;
15 if (day < 7) return `${day}d ago`;
16 return new Date(timestamp).toLocaleDateString(undefined, {
17 month: "short",
18 day: "numeric",
19 });
20};
21
22const Sidebar = memo(
23 ({

Callers 1

Sidebar.jsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected