-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotodate.min.js
More file actions
executable file
·2 lines (2 loc) · 10.9 KB
/
protodate.min.js
File metadata and controls
executable file
·2 lines (2 loc) · 10.9 KB
1
2
/*! protodate (lite) - v3.0.8 */
class ProtoDate extends Date{}!function(){"use strict";ProtoDate.MONTHS=["January","February","March","April","May","June","July","August","September","October","November","December"],ProtoDate.DAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ProtoDate.PROTODATE_VERSION="3.0.8",ProtoDate.MILLISECOND=1,ProtoDate.SECOND=1e3,ProtoDate.MINUTE=6e4,ProtoDate.HOUR=36e5,ProtoDate.DAY=864e5,ProtoDate.YEAR=31536e6,ProtoDate.TIME_FORMATS=["G00 \\h\\o\\u\\r\\s","g \\o\\c\\l\\o\\c\\k","g \\o \\c\\l\\o\\c\\k","g i","g i a","g i A","g i s","g i s a","g i s A","h i","h i a","h i A","h i s","h i s a","h i s A","H i","H i a","H i A","H i s","G i","G i a","G i A","G i s","g i s v","g i s a v","g i s A v","h i s v","h i s a v","h i s A v","H i s v","G i s v"],ProtoDate.DATE_FORMATS=["y","Y","F","M","F Y","F y","M Y","M y","F jS Y","F jS","M jS Y","M jS","F j Y","F j","M j Y","M j","jS F Y","jS F","jS M Y","jS M","j F Y","j F","j M Y","j M","Y m d","m d y","m d Y","Y n d","n d y","n d Y","Y m j","m j y","m j Y","Y n j","n j y","n j Y","D Y m d","D m d y","D m d Y","D Y n d","D n d y","D n d Y","D Y m j","D m j y","D m j Y","D Y n j","D n j y","D n j Y","l Y m d","l m d y","l m d Y","l Y n d","l n d y","l n d Y","l Y m j","l m j y","l m j Y","l Y n j","l n j y","l n j Y"]}(),ProtoDate.prototype.getUnixTimestamp=function(){return~~(this.getTime()/1e3)},function(){"use strict";ProtoDate.isDate=function(t){return"function"==typeof t.getTime&&!isNaN(t.getTime())}}(),function(){"use strict";ProtoDate.prototype.format=function(t){if(!ProtoDate.isDate(this))return!1;for(var e=[],r=0;r<t.length;r++)switch(t[r]){case"\\":e.push(t[++r]);break;case"Y":e.push(""+this.getFullYear());break;case"y":e.push((""+this.getFullYear()).substring(2));break;case"m":e.push(("0"+(this.getMonth()+1)).substr(-2,2));break;case"n":e.push(""+(this.getMonth()+1));break;case"t":e.push(""+new ProtoDate(this.getFullYear(),this.getMonth()+1,0).getDate());break;case"d":e.push(("0"+this.getDate()).substr(-2,2));break;case"j":e.push(this.getDate()+"");break;case"w":e.push(this.getDay());break;case"g":e.push(""+(this.getHours()>12?this.getHours()-12:this.getHours()));break;case"G":e.push(""+this.getHours());break;case"h":e.push(("0"+(this.getHours()>12?this.getHours()-12:this.getHours())).substr(-2,2));break;case"H":e.push(("0"+this.getHours()).substr(-2,2));break;case"i":e.push(("0"+this.getMinutes()).substr(-2,2));break;case"s":e.push(("0"+this.getSeconds()).substr(-2,2));break;case"N":e.push(0==this.getDay()?7:this.getDay());break;case"L":e.push(this.getFullYear()%4==0&&this.getFullYear()%100!=0||this.getFullYear()%400==0?"1":"0");break;case"o":e.push(0==this.getMonth()&&this.getDate()<6&&this.getDay()<4?this.getFullYear()-1:this.getFullYear());break;case"B":e.push(Math.floor(1e3*((this.getUTCHours()+1)%24+this.getUTCMinutes()/60+this.getUTCSeconds()/3600)/24));break;case"v":e.push((this.getTime()+"").substr(-3));break;case"Z":e.push(60*this.getTimezoneOffset());break;case"U":e.push(Math.floor(this.getTime()/1e3));break;case"a":e.push(this.getHours()>11?"pm":"am");break;case"A":e.push(this.getHours()>11?"PM":"AM");break;case"l":e.push(ProtoDate.DAYS[this.getDay()]);break;case"D":e.push(ProtoDate.DAYS[this.getDay()].substr(0,3));break;case"F":e.push(ProtoDate.MONTHS[this.getMonth()]);break;case"M":e.push(ProtoDate.MONTHS[this.getMonth()].substring(0,3));break;case"c":e.push(this.toISOString());break;case"S":var s=!1,a=e[e.length-1].toString()[1],o=e[e.length-1].toString()[0];void 0===a&&(a=o,o=null),"1"==a&&(s="st"),"2"==a&&(s="nd"),"3"==a&&(s="rd"),"1"!=o&&s||(s="th"),e.push(s);break;case"W":for(var i=new ProtoDate(this.getFullYear(),0),u=new ProtoDate(this.getFullYear(),this.getMonth(),this.getDate());u.getDay()<6;)u.setDate(u.getDate()+1);u=u.getTime();for(var n=0;i.getTime()<u;)4==i.getDay()&&n++,i.setDate(i.getDate()+1);e.push(n);break;case"z":i=new ProtoDate(this.getFullYear(),0,1,0,0,0,0);for(var h=0;i.getTime()<this.getTime();)h++,i.setDate(i.getDate()+1);e.push(h);break;case"J":var b=parseInt(this.format("Y")),D=parseInt(this.format("n"));1!==D&&2!==D||(b-=1,D+=12);var c=parseInt(this.format("j")),g=Math.floor(b/100),f=2-g+Math.floor(g/4),l=Math.floor(365.25*(b+4716)),d=Math.floor(30.6001*(D+1));e.push(f+c+l+d-1524.5);break;case"P":var P=this.format("J"),k=29.53*parseFloat("0."+((P-2451549.5)/29.53+"").split(".")[1]);return k>27.65625?"New Moon":k>23.96875?"Waning Crescent":k>20.28125?"Third Quarter":k>16.59375?"Waning Gibbous":k>12.90625?"Full Moon":k>9.21875?"Waxing Gibbous":k>5.53125?"First Quarter":k>1.84375?"Waxing Crescent":"New Moon";default:e.push(t[r])}return e.join("")}}(),function(){"use strict";ProtoDate.validateFormat=function(t,e){for(var r=0;r<e.length;r++)switch(e[r]){case"\\":if(e[++r]!==t[0])return!1;t=t.substr(1);break;case"Y":if(!/^(\d){4}/.test(t))return!1;t=t.substr(4);break;case"y":if(!/^(\d){2}/.test(t))return!1;t=t.substr(2);break;case"m":case"h":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>12||!+t.substr(0,2))return!1;t=t.substr(2);break;case"n":case"g":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>12||!+s[0])return!1;t=t.substr(s[0].length);break;case"d":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>31||!+t.substr(0,2))return!1;t=t.substr(2);break;case"j":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>31||!+s[0])return!1;t=t.substr(s[0].length);break;case"G":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>23)return!1;t=t.substr(s[0].length);break;case"H":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>23)return!1;t=t.substr(2);break;case"i":case"s":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>59)return!1;t=t.substr(2);break;case"v":if(!/^(\d){3}/.test(t))return!1;t=t.substr(3);break;case"a":case"A":var s=t.substr(0,2).toLowerCase();if(!~["am","pm"].indexOf(s))return!1;t=t.substr(2);break;case"l":for(var a=t.toLowerCase(),o=!1,i=0;i<ProtoDate.DAYS.length;i++)if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase())){o=ProtoDate.DAYS[i];break}if(!o)return!1;t=t.substr(o.length);break;case"D":a=t.toLowerCase();var u=0;for(i=0;i<ProtoDate.DAYS.length;i++){if(ProtoDate.DAYS[i].length>6&&!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,6))){u=6;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,5))){u=5;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,4))){u=4;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,3))){u=3;break}}if(!u)return!1;t=t.substr(u);break;case"F":s=t.toLowerCase();var n=!1;for(i=0;i<ProtoDate.MONTHS.length;i++)if(!s.indexOf(ProtoDate.MONTHS[i].toLowerCase())){n=ProtoDate.MONTHS[i];break}if(!n)return!1;t=t.substr(n.length);break;case"M":for(s=t.toLowerCase(),n=!1,i=0;i<ProtoDate.MONTHS.length;i++)if(!s.indexOf(ProtoDate.MONTHS[i].toLowerCase().substr(0,3))){n=ProtoDate.MONTHS[i];break}if(!n)return!1;t=t.substr(3);break;case"S":if(!~["st","nd","rd","th"].indexOf(t.toLowerCase().substr(0,2)))return!1;t=t.substr(2);break;default:if(e[r]!==t[0])return!1;t=t.substr(1)}return!t.trim().length}}(),function(){"use strict";ProtoDate.parse=function(t,e){if(!(e||(t=t.replace(/\W+/g," ").trim(),e=ProtoDate.guessFormat(t))))return!1;if(!ProtoDate.validateFormat(t,e))return!1;for(var r=new ProtoDate,s=r.getFullYear(),a=r.getMonth(),o=r.getDate(),i=r.getHours(),u=r.getMinutes(),n=r.getSeconds(),h=r.getMilliseconds(),b=!0,D=!1,c=0;c<e.length;c++)switch(e[c]){case"\\":t=t.substr(2),c+=2;break;case"Y":s=t.substr(0,4),t=t.substr(4);break;case"y":var g=(""+(new Date).getFullYear()).substr(2),f=t.substr(0,2);s=(f>g?"19":"20")+f,t=t.substr(2);break;case"m":a=t.substr(0,2)-1,t=t.substr(2);break;case"n":a=(Y=t.match(/^(\d){1,2}/)[0])-1,t=t.substr(Y.length);break;case"d":o=+t.substr(0,2),t=t.substr(2);break;case"j":o=+(Y=t.match(/^(\d){1,2}/)[0]),t=t.substr(Y.length);break;case"g":i=12==(l=t.match(/^(\d){1,2}/)[0])?0:+l,t=t.substr(l.length);break;case"G":D=!0,i=+(l=t.match(/^(\d){1,2}/)[0]),t=t.substr(l.length);break;case"h":var l;i=12==(l=t.substr(0,2))?0:+l,t=t.substr(2);break;case"H":D=!0,i=+t.substr(0,2),t=t.substr(2);break;case"i":u=+t.substr(0,2),t=t.substr(2);break;case"s":n=+t.substr(0,2),t=t.substr(2);break;case"v":h=+t.substr(0,3),t=t.substr(3);break;case"a":case"A":"pm"==t.substr(0,2).toLowerCase()&&(b=!1);break;case"l":for(var d=t.toLowerCase(),P=!1,k=0;k<ProtoDate.DAYS.length&&(P=ProtoDate.DAYS[k],d.indexOf(P.toLowerCase()));k++);t=t.substr(P.length);break;case"D":d=t.toLowerCase();var m=0;for(k=0;k<ProtoDate.DAYS.length;k++){if(ProtoDate.DAYS[k].length>6&&!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,6))){m=6;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,5))){m=5;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,4))){m=4;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,3))){m=3;break}}t=t.substr(m);break;case"F":var Y=t.toLowerCase(),M=!1,p=0;for(k=0;k<ProtoDate.MONTHS.length;k++)if(!Y.indexOf(ProtoDate.MONTHS[k].toLowerCase())){M=ProtoDate.MONTHS[k],p=k;break}a=p,t=t.substr(M.length);break;case"M":for(Y=t.toLowerCase(),M=!1,p=0,k=0;k<ProtoDate.MONTHS.length;k++)if(!Y.indexOf(ProtoDate.MONTHS[k].toLowerCase().substr(0,3))){M=ProtoDate.MONTHS[k];break}a=p,t=t.substr(3);break;case"S":t=t.substr(2);break;default:t=t.substr(1)}return b||D||(i+=12),new ProtoDate(s,a,o,i,u,n,h)}}(),function(){"use strict";ProtoDate.prototype.elapsedSince=function(t){if(!ProtoDate.isDate(t))return!1;var e=Math.abs(this.getTime()-t.getTime()),r={};return r.y=Math.floor(e/ProtoDate.YEAR),e-=r.y*ProtoDate.YEAR,r.d=Math.floor(e/ProtoDate.DAY),e-=r.d*ProtoDate.DAY,r.h=Math.floor(e/ProtoDate.HOUR),e-=r.h*ProtoDate.HOUR,r.m=Math.floor(e/ProtoDate.MINUTE),e-=r.m*ProtoDate.MINUTE,r.s=Math.floor(e/ProtoDate.SECOND),e-=r.s*ProtoDate.SECOND,r.ms=e,r.verbose=function(){var t=[];return r.y&&t.push(r.y+" year"+(r.y>1?"s":"")),r.d&&t.push(r.d+" day"+(r.d>1?"s":"")),r.h&&t.push(r.h+" hour"+(r.h>1?"s":"")),r.m&&t.push(r.m+" minute"+(r.m>1?"s":"")),r.s&&t.push(r.s+" second"+(r.s>1?"s":"")),t.length>1&&(t[t.length-1]="and "+t[t.length-1]),t.join(", ")},r.clock=function(t){return[r.h,r.m,t?r.s+"."+("00"+r.ms).substr(-3):+r.s].join(":")},r}}(),function(){"use strict";ProtoDate.prototype.minus=function(t,e){return this.setTime(this.getTime()-t*e),this}}(),function(){"use strict";ProtoDate.prototype.plus=function(t,e){return this.setTime(this.getTime()+t*e),this}}(),function(){"use strict";ProtoDate.guessFormat=function(t){var e,r,s,a;for(a=0;a<ProtoDate.DATE_FORMATS.length;a++)if(r=ProtoDate.DATE_FORMATS[a],ProtoDate.validateFormat(t,r))return r;for(s=0;s<ProtoDate.TIME_FORMATS.length;s++){if(e=ProtoDate.TIME_FORMATS[s],ProtoDate.validateFormat(t,e))return e;for(a=0;a<ProtoDate.DATE_FORMATS.length;a++){if(r=ProtoDate.DATE_FORMATS[a],ProtoDate.validateFormat(t,r+" "+e))return r+" "+e;if(ProtoDate.validateFormat(t,e+" "+r))return e+" "+r}}}}(),function(){"use strict";ProtoDate.prototype.toDate=function(){return new Date(this.getTime())}}(),function(){"use strict";ProtoDate.fromDate=function(t){if(!ProtoDate.isDate(t))throw new Error("ProtoDate.fromDate expects a Date object.");return new ProtoDate(t.getTime())}}(),"undefined"!=typeof module&&module.exports&&(module.exports=ProtoDate);