/*
*  $Id: dateextensions.js 43 2006-08-17 19:11:44Z wingedfox $
*  $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.001/dateextensions.js $
*
*  Extension implements additional methods to operate with Date object
*  @author Ilya Lebedev <ilya@lebedev.net>
*  @modified $Date: 2006-08-17 23:11:44 +0400 (Чтв, 17 Авг 2006) $
*  @version $Rev: 43 $
*  @license LGPL 2.1 or later
*/
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');Date.prototype.isLeapYear=function(){var i=this.getFullYear();return(i%4==0&&i%100!=0)||i%400==0};Date.prototype.getDayOfYear=function(){var i=[0,31,59,90,120,151,181,212,243,273,304,334],I=this.getMonth(),l=this.getDate()+i[I];return this.isLeapYear()&&I>2?l+1:l};Date.prototype.getIsoYear=function(){var i=this.getDayOfYear(),I=(new Date(this.getFullYear(),0,1)).getIsoDay(),l=this.getFullYear();if(i<=(8-I)&&I>4){return l-1}else if(((this.isLeapYear()?366:365)-i)<(4-this.getIsoDay())){return l+1}else{return l}};Date.prototype.getIsoDay=function(){var i=this.getFullYear(),I=(i-1)%100,l=(i-1)-I,o=I+Math.floor(I/4),O=1+((((Math.floor(l/100)%4)*5)+o)%7);return(1+((this.getDayOfYear()+(O-1)-1)%7));};Date.prototype.getIsoWeek=function(){var i=this.getFullYear(),I=this.getIsoYear(),l=(new Date(i,0,1)).getIsoDay();if(I<i){if(l==5||(l==6&&(new Date(I,0,1)).isLeapYear())){o=53}else{o=52}}else if(I>i){o=1}else{var o=Math.floor((this.getDayOfYear()+(7-this.getIsoDay())+(l-1))/7);if(l>4)o-=1}return o};Date.prototype.toFormatString=function(i,I){var l=this;if(!i)return this.toString();if(typeof I!='string')I="0";if(I.length>1)I.length=1;return i.replace(/%\w+/g,function(o){o=o.replace(/[%\s]/,"");switch(o){case"a":return DAY_NAMES[l.getDay()];case"A":return DAY_NAMES[l.getDay()+7];case"b":case"h":return MONTH_NAMES[l.getMonth()];case"B":return MONTH_NAMES[l.getMonth()+12];case"c":return;case"C":return Math.round(l.getFullYear()/100);case"d":return String(l.getDate()).padLeft(2,I);case"D":return l.toFormatString("%m/%d/%y",I);case"e":return String(l.getDate()+1).padLeft(2);case"g":return l.getIsoYear().slice(-2);case"G":return l.getIsoYear();case"H":return String(l.getHours()).padLeft(2,I);case"I":return(l.getHours()>12?l.getHours()-12:l.getHours()).padLeft(2,I);case"j":return String(l.getDayOfYear()).padLeft(3,I);case"m":return String(l.getMonth()+1).padLeft(2,I);case"M":return String(l.getMinutes()).padLeft(2,I);case"n":return"\n";case"p":return(l.getHours()>12?"PM":"AM");case"r":return l.toFormatString("%I",I)+":"+l.toFormatString("%M",I)+":"+l.toFormatString("%S",I)+" "+l.toFormatString("%p",I);case"R":return l.toFormatString("%H",I)+":"+l.toFormatString("%M",I);case"S":return String(l.getSeconds()).padLeft(2,I);case"t":return"\t";case"T":return l.toFormatString("%H",I)+":"+l.toFormatString("%M",I)+":"+l.toFormatString("%S",I);case"u":return l.getIsoDay();case"U":return String(parseInt((l.getDayOfYear()-1-l.getIsoDay()+13)/7-1)).padLeft(2,"0");case"V":return String(l.getIsoWeek()).padLeft(2,I);case"w":return l.getDay();case"W":return String(parseInt((l.getDayOfYear()-1-l.getDay()+13)/7-1)).padLeft(2,"0");case"x":return;case"X":return;case"y":return String(l.getFullYear()).slice(-2);case"Y":return l.getFullYear();case"z":return;case"Z":return l.getTimezoneOffset()/60}return o})};
