UNPKG

short-time-ago

Version:

A small, no dependencies, Typescript utility to describe time differences in a human readable format (for example, '1 minute ago')

3 lines (2 loc) 369 B
function e(e,t){const o=[["year",31536e6],["month",26352e5],["day",864e5],["hour",36e5],["minute",6e4],["second",1e3]],n=(t||new Date).getTime()-e.getTime(),r=Math.abs(n);for(const[e,t]of o){const o=Math.floor(r/t);if(o>0){const t=`${o} ${e}${o>1?"s":""}`;return n>0?`${t} ago`:`in ${t}`}}return"just now"}export{e as timeAgo}; //# sourceMappingURL=index.modern.js.map