UNPKG

@hakit/core

Version:

A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.

3 lines (2 loc) 563 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(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 e=[["second",60],["minute",60],["hour",24],["day",30],["month",12],["year",1/0]],i=(o-new Date().getTime())/1e3;let n=Math.abs(i);for(t=0;t<e.length&&!(n<e[t][1]);t++)n/=e[t][1];const r=m.format(Math.round(n)*(i<0?-1:1),e[t][0]);return r==="now"?"just now":r}exports.timeAgo=s; //# sourceMappingURL=time-ago.js.map