forked from Eligioo/nimiq-readiness-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeago.min.js
1 lines (1 loc) · 1.85 KB
/
timeago.min.js
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).timeago={})}(this,function(e){"use strict";var c=[60,60,24,7,365/7/12,12];function n(e){return e instanceof Date?+e:!isNaN(e)||/^\d+$/.test(e)?+new Date(parseInt(e)):(e=(e||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([+-]\d\d):?(\d\d)/," $1$2"),+new Date(e))}function f(e,t){for(var n=e<0?1:0,r=e=Math.abs(e),i=0;e>=c[i]&&i<c.length;i++)e/=c[i];return(0===(i*=2)?9:1)<(e=~~e)&&(i+=1),t(e,i,r)[n].replace("%s",e)}function d(e,t){return((t=t?n(t):+new Date)-n(e))/1e3}var r=["second","minute","hour","day","week","month","year"];function t(e,t){if(0===t)return["just now","right now"];var n=r[~~(t/2)];return 1<e&&(n+="s"),[e+" "+n+" ago","in "+e+" "+n]}var i=["秒","分钟","小时","天","周","个月","年"];function a(e){return o[e]||t}var o={en_US:t,zh_CN:function(e,t){if(0===t)return["刚刚","片刻后"];var n=i[~~(t/2)];return[e+" "+n+"前",e+" "+n+"后"]}},s="timeago-tid",u="datetime";function l(e){return~~e.getAttribute(s)}var v={},p=function(e){clearTimeout(e),delete v[e]};function h(e,t,n,r){p(l(e));var i=r.relativeDate,a=r.minInterval,o=d(t,i);e.innerText=f(o,n);var u=setTimeout(function(){h(e,t,n,r)},1e3*Math.max(function(e){for(var t=1,n=0,r=Math.abs(e);e>=c[n]&&n<c.length;n++)e/=c[n],t*=c[n];return~~(r=(r%=t)?t-r:t)}(o),a||1),2147483647);v[u]=0,function(e,t){e.setAttribute(s,t)}(e,u)}e.cancel=function(e){e?p(l(e)):Object.keys(v).forEach(p)},e.format=function(e,t,n){return f(d(e,n&&n.relativeDate),a(t))},e.register=function(e,t){o[e]=t},e.render=function(e,t,n){var r="length"in e?e:[e];return r.forEach(function(e){h(e,function(e){return e.getAttribute(u)}(e),a(t),n||{})}),r},Object.defineProperty(e,"__esModule",{value:!0})});