// [date-ext](http://neocotic.com/date-ext) 1.0.2
// (c) 2012 Alasdair Mercer
// Freely distributable under the MIT license.
// For all details and documentation:
// http://neocotic.com/date-ext
(function(){function i(a,b,c){return c&&a["set"+b](a["get"+b]()+c),a}function j(a,b,c){b?"function"!=typeof Date.prototype[a]&&(Date.prototype[a]=c):"function"!=typeof Date[a]&&(Date[a]=c)}function k(h,i,j){"string"!=typeof i&&(i=c);if(!j){var t=n(h),u=h.getDate(),v=h.getDay(),w=h.getMonth(),x=h.getFullYear(),y=h.getHours(),z=h.toString().match(g);j={d:r(u),D:a[v],j:u,l:a[v+7],N:v||7,S:e[u%10>3?0:(u%100-u%10!==10)*u%10],w:v,z:l(h),W:t.week,F:d[w+12],m:r(w+1),M:d[w],n:w+1,t:m(h),L:q(h)?1:0,o:t.year,Y:x,y:String(x).slice(2),a:y<12?"am":"pm",A:y<12?"AM":"PM",B:o(h),g:y%12||12,G:y,h:r(y%12||12),H:r(y),i:r(h.getMinutes()),s:r(h.getSeconds()),u:r(h.getMilliseconds()*1e3,6),e:z?z[0]:"",I:p(h)?1:0,O:s(h),P:s(h,":"),T:z?z[0]:"",Z:h.getTimezoneOffset()*-60,c:"",r:"",U:Math.round(h.getTime()/1e3)},j.c=k(h,b,j),j.r=k(h,c,j)}return i.replace(f,function(a){return"\\"===a?a:0===a.indexOf("\\")?a.substr(1):j[a]})}function l(a){var b=new Date(a.getFullYear(),0,1);return Math.floor((a-b)/1e3/60/60/24)}function m(a){return(new Date(a.getFullYear(),a.getMonth()+1,0)).getDate()}function n(a){var b=new Date(Date.UTC(a.getFullYear(),a.getMonth(),a.getDate())),c=b.getUTCDay();b.setUTCDate(b.getUTCDate()-(c+6)%7+3);var d=b.getTime();b.setUTCMonth(0,4);var e=Math.round((d-b)/6048e5)+1;return{day:c||7,week:e,year:b.getUTCFullYear()}}function o(a){var b=(a.getUTCHours()+1)%24+a.getUTCMinutes()/60+a.getUTCSeconds()/3600;return Math.floor(b*1e3/24)}function p(a){var b=new Date(a);return b.setMonth(0,1),b.getTimezoneOffset()!==a.getTimezoneOffset()}function q(a){return 1===(new Date(a.getFullYear(),1,29)).getMonth()}function r(a,b){b=b||2,a=String(a);while(a.length<b)a="0"+a;return a}function s(a,b){var c=a.getTimezoneOffset(),d=String(r(Math.floor(Math.abs(c)/60)*100+Math.abs(c)%60,4));return b&&(d=d.slice(0,2)+b+d.slice(2)),(c>0?"-":"+")+d}function t(a,b,c){function f(){var a=h.indexOf(d);a>-1&&(h.splice(a,1),b.call(c))}"string"==typeof b&&(c=b,b=null),"function"==typeof a&&(b=a,a=null),a==null&&(a=new Date);var d,e=a-new Date;return"function"==typeof b&&(e<=0?b.call(c):h.push(d=setTimeout(f,e))),d}function u(a){var b=h.indexOf(a);return b>-1?(clearTimeout(a),h.splice(b,1),!0):!1}var a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b="Y-m-d\\TH:i:sP",c="D, j M Y H:i:s O",d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"],e=["th","st","nd","rd"],f=/\\?[\\dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,g=/([A-Z]+)(?=[\-\+]\d{4})/g,h=[];j("addDays",!0,function(a){return i(this,"Date",a)}),j("addHours",!0,function(a){return i(this,"Hours",a)}),j("addMilliseconds",!0,function(a){return i(this,"Milliseconds",a)}),j("addMinutes",!0,function(a){return i(this,"Minutes",a)}),j("addMonths",!0,function(a){return i(this,"Month",a)}),j("addSeconds",!0,function(a){return i(this,"Seconds",a)}),j("addYears",!0,function(a){return i(this,"FullYear",a)}),j("clear",!0,function(){return this.clearDate(),this.clearTime(),this}),j("clearDate",!0,function(){return this.setFullYear(0,0,1),this}),j("clearTime",!0,function(){return this.setHours(0,0,0,0),this}),j("format",!1,function(a,b){return k(a,b)}),j("format",!0,function(a){return k(this,a)}),j("getDayOfYear",!0,function(){return l(this)}),j("getDaysInMonth",!0,function(){return m(this)}),j("getWeekOfYear",!0,function(){return n(this).week}),j("getYearOfWeek",!0,function(){return n(this).year}),j("isDaylightSavingTime",!0,function(){return p(this)}),j("isLeapYear",!0,function(){return q(this)}),j("schedule",!1,function(a,b,c){return t(a,b,c)}),j("schedule",!0,function(a,b){return t(this,a,b)}),j("unschedule",!1,u),j("unschedule",!0,u)})();