forked from mraaroncruz/jquery-fuzzytime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fuzzytime.min.js
1 lines (1 loc) · 1.52 KB
/
jquery.fuzzytime.min.js
1
(function(b){var a=function(m,e){var m=m||false,e=e||new Date().valueOf(),k=31556926,j=2629744,d=604800,l=86400,h=3600,g=60,n="a long time",c=[g,g*20,h,h*4,l,l*2,l*4,d,d*2,j,j*2,j*4,k,k*2,k*4,k*8,k*12,k*24,k*64],i=["moments","a few minutes","less than an hour","a couple of hours","less than a day","about a day","a couple of days","less than a week","about a week","less than a month","about a month","a couple of months","less than a year","about a year","a couple of years","a few years","about a decade","a couple of decades","several decades",],f=[{val:g,string:"minute"},{val:h,string:"hour"},{val:l,string:"day"},{val:d,string:"week"},{val:j,string:"month"},{val:k,string:"year"}];this.parse=function(t){var t=t||new Date(),o=false,u,s;if(/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\+\d{4}/.test(t)){s=this.iso8601(t)}else{s=new Date(t.replace(/(\d\d:\d\d:\d\d\s)\+/,"\1 GMT+")).valueOf()}u=(e-s)/1000;if(u<0){o=true}u=Math.abs(u);if(!n){return !o?"some time ago":"in some time"}else{if(!m){for(var r=0;r<c.length;r++){if(u<c[r]){n=i[r];break}}}else{for(var r=0;r<f.length;r++){if(u<f[r]["val"]){if(r==0){n="less than a minute";break}else{var q=Math.floor(u/f[r-1]["val"]),p=q+" "+f[r-1]["string"];n=q>1?p+"s":p;break}}}}}return !o?n+" ago":"in "+n};this.iso8601=function(p){var o=b.trim(p);o=o.replace(/\.\d\d\d+/,"");o=o.replace(/-/,"/").replace(/-/,"/");o=o.replace(/T/," ").replace(/Z/," UTC");o=o.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2");return new Date(o).valueOf()}};b.extend({fuzzytime:function(f,c,d){var e=new a(c,d);return e.parse(f)}})}(jQuery));