-
Notifications
You must be signed in to change notification settings - Fork 1
/
jdate.min.js
1 lines (1 loc) · 5.72 KB
/
jdate.min.js
1
var jdate={};(function(a){var b=["January","February","March","April","May","June","July","August","September","October","November","December"],c=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],d=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f={1:"st",2:"nd",3:"rd","default":"th"};a.extend_date=function(){Date.strptime=a.strptime,Date.prototype.strftime=function(b){return a.strftime(this,b)}};var g={daysInMonth:function(a){var b=g.isLeapYear(a)?29:28;return[31,b,31,30,31,30,31,31,30,31,30,31]},getTimezone:function(a){return a.toString().replace(/^.*? ([A-Z]{3}) [0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3")},getGMTOffset:function(a){return(a.getTimezoneOffset()>0?"-":"+")+i.pad(Math.floor(a.getTimezoneOffset()/60),2)+i.pad(a.getTimezoneOffset()%60,2)},getDayOfYear:function(a){var b=0;for(var c=0;c<a.getMonth();++c)b+=g.daysInMonth(a)[c];return b+a.getDate()},getWeekOfYear:function(a,b){var c=this.getDayOfYear(a)+(b-a.getDay()),d=new Date(a.getFullYear(),0,1),e=7-d.getDay()+b;return i.pad(Math.floor((c-e)/7)+1,2)},isLeapYear:function(a){var b=a.getFullYear();return(b&3)==0&&!!(b%100||b%400==0&&b)},getFirstDayOfMonth:function(a){var b=(a.getDay()-(a.getDate()-1))%7;return b<0?b+7:b},getLastDayOfMonth:function(a){var b=(a.getDay()+(g.daysInMonth(a)[a.getMonth()]-a.getDate()))%7;return b<0?b+7:b},getSuffix:function(a){var b=a.getDate().toString(),c=parseInt(b.slice(-1));return f[c]||f["default"]},applyOffset:function(a,b){a.setTime(a.valueOf()-b*1e3);return a},century:function(a){return parseInt(a.getFullYear().toString().substring(0,2),10)}},h={values_of:function(a){var b=[];$.each(a,function(a,c){b.push(c)});return b}},i={pad:function(a,b,c){c||(c="0");var d=a.toString(),e=b-d.length;while(e-->0)d=c+d;return d}},j={a:function(a){return e[a.getDay()]},A:function(a){return d[a.getDay()]},b:function(a){return c[a.getMonth()]},B:function(a){return b[a.getMonth()]},c:function(a){return a.toLocaleString()},C:function(a){return g.century(a)},d:function(a){return i.pad(a.getDate(),2)},e:function(a){return i.pad(a.getDate(),2," ")},H:function(a){return i.pad(a.getHours(),2)},I:function(a){return i.pad(a.getHours()%12||12,2)},j:function(a){return i.pad(g.getDayOfYear(a),3)},k:function(a){return i.pad(a.getHours(),2," ")},l:function(a){return i.pad(a.getHours()%12||12,2," ")},L:function(a){return i.pad(a.getMilliseconds(),3)},m:function(a){return i.pad(a.getMonth()+1,2)},M:function(a){return i.pad(a.getMinutes(),2)},p:function(a){return a.getHours()<12?"AM":"PM"},P:function(a){return a.getHours()<12?"am":"pm"},q:function(a){return g.getSuffix(a)},s:function(a){return Math.round(a.valueOf()/1e3)},S:function(a){return i.pad(a.getSeconds(),2)},u:function(a){return a.getDay()||7},U:function(a){return g.getWeekOfYear(a,0)},w:function(a){return a.getDay()},W:function(a){return g.getWeekOfYear(a,1)},x:function(a){return a.toLocaleDateString()},X:function(a){return a.toLocaleTimeString()},y:function(a){return a.getFullYear().toString().substring(2,4)},Y:function(a){return a.getFullYear()},z:function(a){var b=a.getTimezoneOffset()/60*100;return(b>0?"-":"+")+i.pad(b,4)},"%":function(){return"%"}};j.h=j.b,j.N=j.L;var k={a:{r:"(?:"+e.join("|")+")"},A:{r:"(?:"+d.join("|")+")"},b:{r:"("+c.join("|")+")",p:function(a){this.month=$.inArray(a,c)}},B:{r:"("+b.join("|")+")",p:function(a){this.month=$.inArray(a,b)}},C:{r:"(\\d{1,2})",p:function(a){this.century=parseInt(a,10)}},d:{r:"(\\d{1,2})",p:function(a){this.day=parseInt(a,10)}},H:{r:"(\\d{1,2})",p:function(a){this.hour=parseInt(a,10)}},j:{r:"(\\d{1,3})",p:function(a){this.day=parseInt(a,10)}},L:{r:"(\\d{3})",p:function(a){this.milliseconds=parseInt(a,10)}},m:{r:"(\\d{1,2})",p:function(a){this.month=parseInt(a,10)-1}},M:{r:"(\\d{2})",p:function(a){this.minute=parseInt(a,10)}},M:{r:"(\\d{2})",p:function(a){this.minute=parseInt(a,10)}},p:{r:"(AM|PM)",p:function(a){a=="AM"?this.hour==12&&(this.hour=0):this.hour<12&&(this.hour+=12)}},P:{r:"(am|pm)",p:function(a){a=="am"?this.hour==12&&(this.hour=0):this.hour<12&&(this.hour+=12)}},q:{r:"(?:"+h.values_of(f).join("|")+")"},S:{r:"(\\d{2})",p:function(a){this.second=parseInt(a,10)}},y:{r:"(\\d{1,2})",p:function(a){this.year=parseInt(a,10)}},Y:{r:"(\\d{4})",p:function(a){this.century=Math.floor(parseInt(a,10)/100),this.year=parseInt(a,10)%100}},z:{r:"(Z|[+-]\\d{2}:?\\d{2})",p:function(a){if(a=="Z")this.zone=0;else{var b=parseInt(a[0]+a[1]+a[2],10)*3600;a[3]==":"?b+=parseInt(a[4]+a[5],10)*60:b+=parseInt(a[3]+a[4],10)*60,this.zone=b}}}};k.e=k.d,k.h=k.b,k.I=k.H,k.k=k.H,k.l=k.H,a.strftime=function(a,b){var c="",d=b;for(;;){var e=/%./g,f=e.exec(d);if(!f)return c+d;c+=d.slice(0,e.lastIndex-2),d=d.slice(e.lastIndex);var g=f[0].charAt(1),h=j[g];h?c+=h.call(this,a):c+="%"+g}},a.strptime=function(a,b){var c=[],d="",e=b;for(;;){var f=/%./g,h=f.exec(e);if(!h){d+=e;break}d+=e.slice(0,f.lastIndex-2),e=e.slice(f.lastIndex);var i=h[0].charAt(1),j=k[i];if(!j)return null;j.p&&(c=c.concat(j.p)),d+=j.r}var d=new RegExp("^"+d+"$"),l=a.match(d)||[];if(l.length!=c.length+1)return null;var m={};$.each(c,function(a,b){b.call(m,l[a+1])});var n=new Date;if("year"in m)if("century"in m)m.year+=m.century*100;else{m.year+=g.century(n)*100;var o=new Date(n.getFullYear()+50,n.getMonth(),n.getDate());m.year>o.getFullYear()&&(m.year-=100)}if("year"in m&&"day"in m&&!("month"in m)){var p=new Date(m.year,0,1),q=g.daysInMonth(p);for(var r=0;r<q.length;r++){if(m.day<=q[r]){m.month=r;break}m.day-=q[r]}}var s=new Date("year"in m?m.year:n.getFullYear(),"month"in m?m.month:n.getMonth(),"day"in m?m.day:n.getDate(),m.hour||0,m.minute||0,m.second||0,m.milliseconds||0);if(!("zone"in m))return s;s=new Date(s.valueOf()-s.getTimezoneOffset()*1e3*60);return g.applyOffset(s,m.zone||0)}})(jdate)