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) 376 B
"use strict";exports.timeAgo=function(e,t){for(var r=(t||new Date).getTime()-e.getTime(),n=Math.abs(r),o=0,a=[["year",31536e6],["month",26352e5],["day",864e5],["hour",36e5],["minute",6e4],["second",1e3]];o<a.length;o++){var i=a[o],s=i[0],u=Math.floor(n/i[1]);if(u>0){var g=u+" "+s+(u>1?"s":"");return r>0?g+" ago":"in "+g}}return"just now"}; //# sourceMappingURL=index.js.map