@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
25 lines (24 loc) • 643 B
JavaScript
function f(a, u) {
const o = a.getTime();
if (isNaN(o))
return console.error("Invalid timestamp"), "unknown";
const m = new Intl.RelativeTimeFormat(u, { numeric: "auto" });
let t;
const n = [
["second", 60],
["minute", 60],
["hour", 24],
["day", 30],
["month", 12],
["year", 1 / 0]
], i = (o - (/* @__PURE__ */ new Date()).getTime()) / 1e3;
let e = Math.abs(i);
for (t = 0; t < n.length && !(e < n[t][1]); t++)
e /= n[t][1];
const r = m.format(Math.round(e) * (i < 0 ? -1 : 1), n[t][0]);
return r === "now" ? "just now" : r;
}
export {
f as timeAgo
};
//# sourceMappingURL=time-ago.js.map