epoch-timeago
Version:
Convert Unix time to a relative time string e.g., "4 hours ago".
2 lines (1 loc) • 774 B
JavaScript
;var a=void 0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function b(a,b){if(a!==b)throw new TypeError("Cannot instantiate an arrow function")}var c=[3154e7,2628e6,6048e5,864e5,36e5,6e4,-Infinity],d=function(c,d){var e=this;return b(this,a),function(a,f){return b(this,e),f>=2*a?"".concat(Math.floor(f/a)," ").concat(c,"s ago"):d}.bind(this)}.bind(void 0),e=[d("year","1 year ago"),d("month","1 month ago"),d("week","1 week ago"),d("day","1 day ago"),d("hour","an hour ago"),d("minute","a minute ago"),function(){return b(this,a),"just now"}.bind(void 0)],f=function(d){var f=this;b(this,a);var g=Date.now()-d,h=c.findIndex(function(a){return b(this,f),g>=a}.bind(this)),i=e[h](c[h],g);return i}.bind(void 0);exports.default=f;