UNPKG

8.46 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).VueTimeago={})}(this,function(e){"use strict";var t=function(e){return e instanceof Date},n=36e5,r=6e4,a=2,o=/[T ]/,u=/:/,i=/^(\d{2})$/,s=[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],c=/^(\d{4})/,d=[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],l=/^-(\d{2})$/,f=/^-?(\d{3})$/,h=/^-?(\d{2})-?(\d{2})$/,p=/^-?W(\d{2})$/,v=/^-?W(\d{2})-?(\d{1})$/,m=/^(\d{2}([.,]\d*)?)$/,g=/^(\d{2}):?(\d{2}([.,]\d*)?)$/,y=/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,M=/([Z+-].*)$/,D=/^(Z)$/,T=/^([+-])(\d{2})$/,x=/^([+-])(\d{2}):?(\d{2})$/;function S(e,t,n){t=t||0,n=n||0;var r=new Date(0);r.setUTCFullYear(e,0,4);var a=7*t+n+1-(r.getUTCDay()||7);return r.setUTCDate(r.getUTCDate()+a),r}var b=function(e,b){if(t(e))return new Date(e.getTime());if("string"!=typeof e)return new Date(e);var I=(b||{}).additionalDigits;I=null==I?a:Number(I);var Y=function(e){var t,n={},r=e.split(o);if(u.test(r[0])?(n.date=null,t=r[0]):(n.date=r[0],t=r[1]),t){var a=M.exec(t);a?(n.time=t.replace(a[1],""),n.timezone=a[1]):n.time=t}return n}(e),$=function(e,t){var n,r=s[t],a=d[t];if(n=c.exec(e)||a.exec(e)){var o=n[1];return{year:parseInt(o,10),restDateString:e.slice(o.length)}}if(n=i.exec(e)||r.exec(e)){var u=n[1];return{year:100*parseInt(u,10),restDateString:e.slice(u.length)}}return{year:null}}(Y.date,I),U=$.year,X=function(e,t){if(null===t)return null;var n,r,a,o;if(0===e.length)return(r=new Date(0)).setUTCFullYear(t),r;if(n=l.exec(e))return r=new Date(0),a=parseInt(n[1],10)-1,r.setUTCFullYear(t,a),r;if(n=f.exec(e)){r=new Date(0);var u=parseInt(n[1],10);return r.setUTCFullYear(t,0,u),r}if(n=h.exec(e)){r=new Date(0),a=parseInt(n[1],10)-1;var i=parseInt(n[2],10);return r.setUTCFullYear(t,a,i),r}if(n=p.exec(e))return o=parseInt(n[1],10)-1,S(t,o);if(n=v.exec(e)){o=parseInt(n[1],10)-1;var s=parseInt(n[2],10)-1;return S(t,o,s)}return null}($.restDateString,U);if(X){var w,F=X.getTime(),W=0;return Y.time&&(W=function(e){var t,a,o;if(t=m.exec(e))return(a=parseFloat(t[1].replace(",",".")))%24*n;if(t=g.exec(e))return a=parseInt(t[1],10),o=parseFloat(t[2].replace(",",".")),a%24*n+o*r;if(t=y.exec(e)){a=parseInt(t[1],10),o=parseInt(t[2],10);var u=parseFloat(t[3].replace(",","."));return a%24*n+o*r+1e3*u}return null}(Y.time)),Y.timezone?(O=Y.timezone,w=(z=D.exec(O))?0:(z=T.exec(O))?(H=60*parseInt(z[2],10),"+"===z[1]?-H:H):(z=x.exec(O))?(H=60*parseInt(z[2],10)+parseInt(z[3],10),"+"===z[1]?-H:H):0):(w=new Date(F+W).getTimezoneOffset(),w=new Date(F+W+w*r).getTimezoneOffset()),new Date(F+W+w*r)}var O,z,H;return new Date(e)};var I=function(e,t){var n=b(e).getTime(),r=b(t).getTime();return n>r?-1:n<r?1:0};var Y=function(e,t){var n=b(e),r=b(t);return n.getTime()-r.getTime()};var $=function(e,t){var n=Y(e,t)/1e3;return n>0?Math.floor(n):Math.ceil(n)};var U=function(e,t){var n=b(e),r=b(t);return 12*(n.getFullYear()-r.getFullYear())+(n.getMonth()-r.getMonth())};var X=function(e,t){var n=b(e).getTime(),r=b(t).getTime();return n<r?-1:n>r?1:0};var w=function(e,t){var n=b(e),r=b(t),a=X(n,r),o=Math.abs(U(n,r));return n.setMonth(n.getMonth()-a*o),a*(o-(X(n,r)===-a))};var F=["M","MM","Q","D","DD","DDD","DDDD","d","E","W","WW","YY","YYYY","GG","GGGG","H","HH","h","hh","m","mm","s","ss","S","SS","SSS","Z","ZZ","X","x"];var W=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);var r=F.concat(t).sort().reverse();return new RegExp("(\\[[^\\[]*\\])|(\\\\)?("+r.join("|")+"|.)","g")};var O=function(){var e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],t=["January","February","March","April","May","June","July","August","September","October","November","December"],n=["Su","Mo","Tu","We","Th","Fr","Sa"],r=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],o=["AM","PM"],u=["am","pm"],i=["a.m.","p.m."],s={MMM:function(t){return e[t.getMonth()]},MMMM:function(e){return t[e.getMonth()]},dd:function(e){return n[e.getDay()]},ddd:function(e){return r[e.getDay()]},dddd:function(e){return a[e.getDay()]},A:function(e){return e.getHours()/12>=1?o[1]:o[0]},a:function(e){return e.getHours()/12>=1?u[1]:u[0]},aa:function(e){return e.getHours()/12>=1?i[1]:i[0]}};return["M","D","DDD","d","Q","W"].forEach(function(e){s[e+"o"]=function(t,n){return function(e){var t=e%100;if(t>20||t<10)switch(t%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"}(n[e](t))}}),{formatters:s,formattingTokensRegExp:W(s)}},z={distanceInWords:function(){var e={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};return{localize:function(t,n,r){var a;return r=r||{},a="string"==typeof e[t]?e[t]:1===n?e[t].one:e[t].other.replace("{{count}}",n),r.addSuffix?r.comparison>0?"in "+a:a+" ago":a}}}(),format:O()},H=1440,A=2520,C=43200,G=86400;var J=function(e,t,n){var r=n||{},a=I(e,t),o=r.locale,u=z.distanceInWords.localize;o&&o.distanceInWords&&o.distanceInWords.localize&&(u=o.distanceInWords.localize);var i,s,c={addSuffix:Boolean(r.addSuffix),comparison:a};a>0?(i=b(e),s=b(t)):(i=b(t),s=b(e));var d,l=$(s,i),f=s.getTimezoneOffset()-i.getTimezoneOffset(),h=Math.round(l/60)-f;if(h<2)return r.includeSeconds?l<5?u("lessThanXSeconds",5,c):l<10?u("lessThanXSeconds",10,c):l<20?u("lessThanXSeconds",20,c):l<40?u("halfAMinute",null,c):u(l<60?"lessThanXMinutes":"xMinutes",1,c):0===h?u("lessThanXMinutes",1,c):u("xMinutes",h,c);if(h<45)return u("xMinutes",h,c);if(h<90)return u("aboutXHours",1,c);if(h<H)return u("aboutXHours",Math.round(h/60),c);if(h<A)return u("xDays",1,c);if(h<C)return u("xDays",Math.round(h/H),c);if(h<G)return u("aboutXMonths",d=Math.round(h/C),c);if((d=w(s,i))<12)return u("xMonths",Math.round(h/C),c);var p=d%12,v=Math.floor(d/12);return p<3?u("aboutXYears",v,c):p<9?u("overXYears",v,c):u("almostXYears",v+1,c)};var N=function(e,t){return J(Date.now(),e,t)},Z=function(e,t,n){var r=n.includeSeconds,a=n.addSuffix;return void 0===a&&(a=!0),N(e,{locale:t,includeSeconds:r,addSuffix:a})},j=function(e){void 0===e&&(e={});var t=e.locales||{};return{name:e.name||"Timeago",props:{datetime:{required:!0},title:{type:[String,Boolean]},locale:{type:String},autoUpdate:{type:[Number,Boolean]},converter:{type:Function},converterOptions:{type:Object}},data:function(){return{timeago:this.getTimeago()}},computed:{localeName:function(){return this.locale||this.$timeago.locale}},mounted:function(){this.startUpdater()},beforeDestroy:function(){this.stopUpdater()},render:function(e){return e("time",{attrs:{datetime:new Date(this.datetime).toISOString(),title:"string"==typeof this.title?this.title:!1===this.title?null:this.timeago}},[this.timeago])},methods:{getTimeago:function(n){return(this.converter||e.converter||Z)(n||this.datetime,t[this.locale||this.$timeago.locale],this.converterOptions||{})},convert:function(e){this.timeago=this.getTimeago(e)},startUpdater:function(){var e=this;if(this.autoUpdate){var t=!0===this.autoUpdate?60:this.autoUpdate;this.updater=setInterval(function(){e.convert()},1e3*t)}},stopUpdater:function(){this.updater&&(clearInterval(this.updater),this.updater=null)}},watch:{autoUpdate:function(e){this.stopUpdater(),e&&this.startUpdater()},datetime:function(){this.convert()},localeName:function(){this.convert()},converter:function(){this.convert()},converterOptions:{handler:function(){this.convert()},deep:!0}}}},E=function(e,t){if(!e.prototype.$timeago){var n={locale:t.locale};e.prototype.$timeago=e.observable?e.observable(n):new e({data:n});var r=j(t);e.component(r.name,r)}},B=Z;e.createTimeago=j,e.install=E,e.converter=B,e.default=E,Object.defineProperty(e,"__esModule",{value:!0})});
2//# sourceMappingURL=vue-timeago.js.map