/*! * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015 * @version 1.3.1 * * Date formatter utility library, that allows you to format date and * time variables or Date objects using PHP DateTime format. * @see http://php.net/manual/en/function.date.php * * Authors: * [Kartik Visweswaran](https://github.com/kartik-v) * [Enrica R](https://github.com/Erik-r) * * For more JQuery plugins visit http://plugins.krajee.com * For more Yii related demos visit http://demos.krajee.com */var defaultConfig={dateSettings:{days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],meridiem:["AM","PM"]},separators:/[ \-+\/\.T:@]/g,validParts:/[djDlwSFmMnyYaAgGhHisU]/g},DateFormatter=function(e){var t=$.extend(!0,defaultConfig,e);this.dateSettings=t.dateSettings,this.separators=t.separators,this.validParts=t.validParts};DateFormatter.prototype={constructor:DateFormatter,parseDate:function(e,t){if(!e)return void 0;if(e instanceof Date)return e;if("number"==typeof e)return new Date(e);var a=this,r={date:null,year:null,month:null,day:null,dayOfWeek:null,hour:0,min:0,sec:0};if(e instanceof Date)return e;if("string"==typeof e){var s=t.match(a.validParts);if(!s||0===s.length)throw new Error("Invalid date format definition.");var n,i=e.replace(a.separators,"\x00").split("\x00"),o=!1,u=!1;for(n=0;n-1&&(r.month=c+1),c=a.dateSettings.months.indexOf(i[n]),c>-1&&(r.month=c+1)):parseInt(i[n])>=1&&parseInt(i[n])<=12&&(r.month=parseInt(i[n])),o=!0;break;case"d":case"j":parseInt(i[n])>=1&&parseInt(i[n])<=31&&(r.day=parseInt(i[n])),o=!0;break;case"g":case"h":var d=s.indexOf("a")>-1?s.indexOf("a"):s.indexOf("A")>-1?s.indexOf("A"):-1;if(d>-1){var g=i[d].toLowerCase==a.dateSettings.meridiem[0].toLowerCase?0:i[d].toLowerCase==a.dateSettings.meridiem[1].toLowerCase?12:-1;parseInt(i[n])>=1&&parseInt(i[n])<=12&&g>-1?r.hour=parseInt(i[n])+g-1:parseInt(i[n])>=0&&parseInt(i[n])<=23&&(r.hour=parseInt(i[n]))}else parseInt(i[n])>=0&&parseInt(i[n])<=23&&(r.hour=parseInt(i[n]));u=!0;break;case"G":case"H":parseInt(i[n])>=0&&parseInt(i[n])<=23&&(r.hour=parseInt(i[n])),u=!0;break;case"i":parseInt(i[n])>=0&&parseInt(i[n])<=59&&(r.min=parseInt(i[n])),u=!0;break;case"s":parseInt(i[n])>=0&&parseInt(i[n])<=59&&(r.sec=parseInt(i[n])),u=!0}return o===!0&&r.year&&r.month&&r.day?(r.date=new Date(r.year,r.month-1,r.day,r.hour,r.min,r.sec,0),r.date):u===!0?(r.date=new Date(0,0,0,r.hour,r.min,r.sec,0),r.date):!1}},guessDate:function(e,t){var a=this;if("string"!=typeof e)return e;var r=e.replace(a.separators,"\x00").split("\x00"),s=t.match(a.validParts),n=/^[djmn]/g;if(n.test(s[0])){var i,o=new Date,u=0;for(i=0;i0&&r.splice(i+1,0,r[i].substr(u))}return o}},formatDate:function(e,t){var a=this;if("string"==typeof e&&(e=a.parseDate(e,t),0==e))return!1;if(e instanceof Date){var r,s,n="",a=this,i=/[djDlwSFmMnyYaAgGhHisU]/;for(r=0;r