/**
 * PHP Date
 *
 * @version  0.3.0
 * @author   Hiroshi Hoaki <rewish.org@gmail.com>
 * @link     http://rewish.org/javascript/php_date
 * @see      http://php.net/manual/ja/function.date.php
 * @license  http://rewish.org/license/mit The MIT License
 */
(function(){Date.ATOM="Y-m-d\\TH:i:sP";Date.COOKIE="l, d-M-y H:i:s T";Date.ISO8601="Y-m-d\\TH:i:sO";Date.RFC822="D, d M y H:i:s O";Date.RFC850="l, d-M-y H:i:s T";Date.RFC1036="D, d M y H:i:s O";Date.RFC1123="D, d M Y H:i:s O";Date.RFC2822="D, d M Y H:i:s O";Date.RFC3339="Y-m-d\\TH:i:sP";Date.RSS="D, d M Y H:i:s O";Date.W3C="Y-m-d\\TH:i:sP";var h={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};var k=["January","February","March","April","May","June","July","August","September","October","November","December"];var a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var c=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];var f={id:"Asia/Tokyo",abbr:"JST"};var j=Date.parse;var d=[/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})([\+|\-]{1}\d{2}:\d{2})?/,/^[a-z]+, (\d{2,})[\s\-]([a-z]{3})[\s\-](\d{2}) (\d{2}):(\d{2}):(\d{2})\s*(.+)?/i];var b=typeof window.opera!=="undefined";function g(m,n){n=n||2;for(var l=0;l<n;++l){m="0"+m}return m.slice(-n)}Date.parse=function(n,o){var l,p;p=b?NaN:j(n);if(!isNaN(p)){return p}if(l=n.match(d[0])){p=Date.UTC(l[1],l[2]-1,l[3],l[4],l[5],l[6]);return l[7]?Date.applyDiffTime(p,l[7]):p}if(l=n.match(d[1])){p=Date.UTC(+l[3]+(o||2000),h[l[2]],l[1],l[4],l[5],l[6]);return l[7]?Date.applyDiffTime(p,l[7]):p}return b&&isNaN(p)?j(n):p};Date.applyDiffTime=function(n,m){m=m.replace("JST","+0900").replace("UTC","+0000");var l=m.match(/\d{2}/g);l=((Math.abs(l[0])*60)+Math.abs(l[1]))*60*1000;return m.match(/^./)[0]==="-"?n+l:n-l};Date.prototype.getISOWeekNumber=function(m,o,l){var p,n;m=m||this.getFullYear();o=o||this.getMonth();l=l||this.getDate();p=(new Date(m,0,4).getDay()||7)-3;n=p+this.getElapseDays(m);if(n<=0){m=m-1;n=p+(new Date(m,11,31).getElapseDays(m))}if(o<11||l<29){return Math.ceil(n/7)}if((this.getDay()||7)<=(3-(31-l))){return 1}return Math.ceil(n/7)};Date.prototype.getISOYear=function(m,n,l){m=m||this.getFullYear();n=n||this.getMonth();l=l||this.getDate();weekNumber=this.getISOWeekNumber(m,n,l);return l<=3&&weekNumber>=52?m-1:l>=29&&weekNumber==1?m+1:m};Date.prototype.getUTCTime=function(){return this.getTime()+(this.getTimezoneOffset()*60*1000)};Date.prototype.isLeapYear=function(l){l=l||this.getFullYear();return(l%4===0&&l%100!==0)||l%400===0};Date.prototype.getInternetTime=function(l,m,n){var o,p=this.toGMTString().split(" ")[4].split(":");l=l||+p[0];m=m||+p[1];n=n||+p[2];o=(l*3600+m*60+n+3600)/86.4;return g(Math.floor(o>=1000?o-1000:o),3)};Date.prototype.getSuffix=function(l){l=(""+(l||this.getDate())).slice(-1);return l==="1"?"st":l==="2"?"nd":l==="3"?"rd":"th"};Date.prototype.getElapseDays=function(n,o,m){var p=new Date(n||this.getFullYear(),o||0,m||1),l=new Date(this.getFullYear(),this.getMonth(),this.getDate());return Math.floor((l-p)/60/60/24/1000)};Date.prototype.getMonthTotalDays=function(l,m){l=l||this.getFullYear();m=m||this.getMonth();return new Date(l,m+1,0).getDate()};Date.prototype.getHalfHours=function(l){l=l||this.getHours();return l>12?l-12:l===0?12:l};Date.prototype.getGMTDiff=function(l){var m=this.getTimezoneOffset()/60;return(m>0?"-":"+")+g(Math.abs(m))+(l?":":"")+"00"};Date.prototype.format=function(o,n){if(!n){return formatter.call(this,o)}if(typeof n!=="number"){n=Date.parse(n)}var m=this.getTime();this.setTime(n);var l=formatter.call(this,o);this.setTime(m);return l};function i(n){n=n+"";var l=[];for(var m=0,o;o=n.charAt(m);++m){if(o==="\\"){l[++m]=n.charAt(m);continue}l[m]=o==="d"?g(this.getDate()):o==="D"?e[this.getDay()]:o==="j"?this.getDate():o==="l"?c[this.getDay()]:o==="N"?this.getDay()===0?7:this.getDay():o==="S"?this.getSuffix(this.getDate()):o==="w"?this.getDay():o==="z"?this.getElapseDays():o==="W"?g(this.getISOWeekNumber()):o==="F"?k[this.getMonth()]:o==="m"?g(this.getMonth()+1):o==="M"?a[this.getMonth()]:o==="n"?this.getMonth()+1:o==="t"?this.getMonthTotalDays():o==="L"?this.isLeapYear()?1:0:o==="o"?this.getISOYear():o==="Y"?this.getFullYear():o==="y"?(this.getFullYear()+"").slice(-2):o==="a"?this.getHours()<12?"am":"pm":o==="A"?this.getHours()<12?"AM":"PM":o==="B"?this.getInternetTime():o==="g"?this.getHalfHours():o==="G"?this.getHours():o==="h"?g(this.getHalfHours()):o==="H"?g(this.getHours()):o==="i"?g(this.getMinutes()):o==="s"?g(this.getSeconds()):o==="u"?g(this.getMilliseconds(),3)+"000":o==="e"?f.id:o==="I"?0:o==="O"?this.getGMTDiff():o==="P"?this.getGMTDiff(true):o==="T"?f.abbr:o==="Z"?(this.getTimezoneOffset()>0?"-":"")+Math.abs(this.getTimezoneOffset()*60):o==="c"?toFormatDate.call(this,Date.ATOM):o==="r"?toFormatDate.call(this,Date.RFC2822):o==="U"?(this.getTime()+"").slice(0,-3):o}return l.join("")}})();

