MCPcopy Create free account
hub / github.com/UdaraJay/Stats / formatFromNow

Function formatFromNow

ui/script.js:35–45  ·  view source on GitHub ↗
(timestamp)

Source from the content-addressed store, hash-verified

33}
34
35function formatFromNow(timestamp) {
36 const now = new Date();
37 const date = new Date(timestamp.replace(" ", "T") + "Z");
38 const diff = Math.floor((now - date) / 1000);
39 const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
40
41 if (Math.abs(diff) < 60) return rtf.format(-diff, "second");
42 if (Math.abs(diff) < 3600) return rtf.format(-(diff / 60) | 0, "minute");
43 if (Math.abs(diff) < 86400) return rtf.format(-(diff / 3600) | 0, "hour");
44 return rtf.format(-(diff / 86400) | 0, "day");
45}
46
47function prettyPrintTimeDifference(t1, t2) {
48 const d1 = new Date(t1),

Callers 1

renderSessionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected