/**
 * PHP Date
 *
 * @version  0.2.0
 * @author   rew <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
 */
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:sP";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";Date.__parse=Date.parse;Date.parse=function(b,d){var f=window.opera?NaN:Date.__parse(b);if(!isNaN(f)){return f}var a,c=b;if(a=c.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})([\+|\-]{1}\d{2}:\d{2})?/)){f=Date.UTC(a[1],a[2]-1,a[3],a[4],a[5],a[6]);return a[7]?Date.applyDiffTime(f,a[7]):f}d=d||2000;if(a=c.match(/^[a-zA-Z]+, (\d{2,})[\s|\-]([a-zA-Z]{3})[\s|\-](\d{2}) (\d{2}):(\d{2}):(\d{2})\s*(.+)?/)){var e=new Date().__monthKeys[a[2]];f=Date.UTC(+a[3]+d,e,a[1],a[4],a[5],a[6]);return a[7]?Date.applyDiffTime(f,a[7]):f}return window.opera&&isNaN(f)?Date.__parse(b):f};Date.applyDiffTime=function(c,b){b=b.replace("JST","+0900").replace("UTC","+0000");var a=b.match(/\d{2}/g);a=((Math.abs(a[0])*60)+Math.abs(a[1]))*60*1000;return b.match(/^./)[0]==="-"?c+a:c-a};Date.prototype.__monthKeys={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};Date.prototype.__monthFullNames=["January","February","March","April","May","June","July","August","September","October","November","December"];Date.prototype.__monthShortNames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Date.prototype.__dayFullNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];Date.prototype.__dayShortNames=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];Date.prototype.__timezone={id:"Asia/Tokyo",abbr:"JST"};Date.prototype.getISOWeekNumber=function(c,e,b){var a=this,c=c||a.getFullYear(),e=e||a.getMonth(),b=b||a.getDate(),d=((new Date(c,0,4).getDay()||7)-3)+a.getElapseDays(c);if(d<=0){c=c-1;d=((new Date(c,0,4).getDay()||7)-3)+(new Date(c,11,31).getElapseDays(c))}if(e<11||b<29){return Math.ceil(d/7)}if((a.getDay()||7)<=(3-(31-b))){return 1}return Math.ceil(d/7)};Date.prototype.getISOYear=function(c,e,b){var a=this,c=c||a.getFullYear(),e=e||a.getMonth(),b=b||a.getDate(),d=a.getISOWeekNumber(c,e,b);return b<=3&&d>=52?c-1:b>=29&&d==1?c+1:c};Date.prototype.getUTCTime=function(){var a=this;return a.getTime()+(a.getTimezoneOffset()*60*1000)};Date.prototype.isLeapYear=function(a){var a=a||this.getFullYear();return(a%4===0&&a%100!==0)||a%400===0};Date.prototype.getInternetTime=function(a,c,d){var b=this,f=b.toGMTString().split(" ")[4].split(":"),a=a||+f[0],c=c||+f[1],d=d||+f[2],e=(a*3600+c*60+d+3600)/86.4;return("00"+Math.floor(e>=1000?e-1000:e)).slice(-3)};Date.prototype.getSuffix=function(a){var a=a||this.getDate();return a==1||a==21||a==31?"st":a==2||a==22?"nd":a==3||a==23?"rd":"th"};Date.prototype.getElapseDays=function(d,e,c){var a=this,d=d||a.getFullYear(),e=e||0,c=c||1,f=new Date(d,e,c),b=new Date(a.getFullYear(),a.getMonth(),a.getDate());return Math.floor((b-f)/60/60/24/1000)};Date.prototype.getMonthTotalDays=function(b,c){var a=this,b=b||a.getFullYear(),c=c||a.getMonth();return new Date(b,c+1,0).getDate()};Date.prototype.getHalfHours=function(a){var a=a||this.getHours();return a>12?a-12:a===0?12:a};Date.prototype.getGMTDiff=function(a){var b=this.getTimezoneOffset()/60;return[b>0?"-":"+",("0"+Math.abs(b)).slice(-2),a?":":"","00"].join("")};Date.prototype.format=function(e,d){var b=this;var a=function(k,j){var g=[],k=k+"";for(var h=0,l;l=k.charAt(h);h++){if(l==="\\"){g[++h]=k.charAt(h);continue}g[h]=l==="d"?("0"+b.getDate()).slice(-2):l==="D"?b.__dayShortNames[b.getDay()]:l==="j"?b.getDate():l==="l"?b.__dayFullNames[b.getDay()]:l==="N"?b.getDay()===0?7:b.getDay():l==="S"?b.getSuffix(b.getDate()):l==="w"?b.getDay():l==="z"?b.getElapseDays():l==="W"?("0"+b.getISOWeekNumber()).slice(-2):l==="F"?b.__monthFullNames[b.getMonth()]:l==="m"?("0"+(b.getMonth()+1)).slice(-2):l==="M"?b.__monthShortNames[b.getMonth()]:l==="n"?b.getMonth()+1:l==="t"?b.getMonthTotalDays():l==="L"?b.isLeapYear()?1:0:l==="o"?b.getISOYear():l==="Y"?b.getFullYear():l==="y"?(b.getFullYear()+"").slice(-2):l==="a"?b.getHours()<12?"am":"pm":l==="A"?b.getHours()<12?"AM":"PM":l==="B"?b.getInternetTime():l==="g"?b.getHalfHours():l==="G"?b.getHours():l==="h"?("0"+b.getHalfHours()).slice(-2):l==="H"?("0"+b.getHours()).slice(-2):l==="i"?("0"+b.getMinutes()).slice(-2):l==="s"?("0"+b.getSeconds()).slice(-2):l==="u"?("00"+b.getMilliseconds()).slice(-3)+"000":l==="e"?b.__timezone.id:l==="I"?0:l==="O"?b.getGMTDiff():l==="P"?b.getGMTDiff(true):l==="T"?b.__timezone.abbr:l==="Z"?(b.getTimezoneOffset()>0?"-":"")+Math.abs(b.getTimezoneOffset()*60):l==="c"?a(Date.ISO8601):l==="r"?a(Date.RFC2822):l==="U"?(b.getTime()+"").slice(0,-3):l}return g.join("")};if(!d){return a(e)}var f=b.getTime();b.setTime(typeof d==="number"?d:Date.parse(d));var c=a(e);b.setTime(f);return c};