[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/template/lib/mootools/more-1.4/Types/ -> Date.js (source)

   1  (function(){var Date=this.Date;var DateMethods=Date.Methods={ms:"Milliseconds",year:"FullYear",min:"Minutes",mo:"Month",sec:"Seconds",hr:"Hours"};["Date","Day","FullYear","Hours","Milliseconds","Minutes","Month","Seconds","Time","TimezoneOffset","Week","Timezone","GMTOffset","DayOfYear","LastMonth","LastDayOfMonth","UTCDate","UTCDay","UTCFullYear","AMPM","Ordinal","UTCHours","UTCMilliseconds","UTCMinutes","UTCMonth","UTCSeconds","UTCMilliseconds"].each(function(method){Date.Methods[method.toLowerCase()]=method});var pad=function(n,digits,string){if(digits==1){return n}return n<Math.pow(10,digits-1)?(string||"0")+pad(n,digits-1,string):n};Date.implement({set:function(prop,value){prop=prop.toLowerCase();var method=DateMethods[prop]&&"set"+DateMethods[prop];if(method&&this[method]){this[method](value)}return this}.overloadSetter(),get:function(prop){prop=prop.toLowerCase();var method=DateMethods[prop]&&"get"+DateMethods[prop];if(method&&this[method]){return this[method]()}return null}.overloadGetter(),clone:function(){return new Date(this.get("time"))},increment:function(interval,times){interval=interval||"day";times=times!=null?times:1;switch(interval){case"year":return this.increment("month",times*12);case"month":var d=this.get("date");this.set("date",1).set("mo",this.get("mo")+times);return this.set("date",d.min(this.get("lastdayofmonth")));case"week":return this.increment("day",times*7);case"day":return this.set("date",this.get("date")+times)}if(!Date.units[interval]){throw new Error(interval+" is not a supported interval")}return this.set("time",this.get("time")+times*Date.units[interval]())},decrement:function(interval,times){return this.increment(interval,-1*(times!=null?times:1))},isLeapYear:function(){return Date.isLeapYear(this.get("year"))},clearTime:function(){return this.set({hr:0,min:0,sec:0,ms:0})},diff:function(date,resolution){if(typeOf(date)=="string"){date=Date.parse(date)}return((date-this)/Date.units[resolution||"day"](3,3)).round()},getLastDayOfMonth:function(){return Date.daysInMonth(this.get("mo"),this.get("year"))},getDayOfYear:function(){return(Date.UTC(this.get("year"),this.get("mo"),this.get("date")+1)-Date.UTC(this.get("year"),0,1))/Date.units.day()},setDay:function(day,firstDayOfWeek){if(firstDayOfWeek==null){firstDayOfWeek=Date.getMsg("firstDayOfWeek");if(firstDayOfWeek===""){firstDayOfWeek=1}}day=(7+Date.parseDay(day,true)-firstDayOfWeek)%7;var currentDay=(7+this.get("day")-firstDayOfWeek)%7;return this.increment("day",day-currentDay)},getWeek:function(firstDayOfWeek){if(firstDayOfWeek==null){firstDayOfWeek=Date.getMsg("firstDayOfWeek");if(firstDayOfWeek===""){firstDayOfWeek=1}}var date=this,dayOfWeek=(7+date.get("day")-firstDayOfWeek)%7,dividend=0,firstDayOfYear;if(firstDayOfWeek==1){var month=date.get("month"),startOfWeek=date.get("date")-dayOfWeek;if(month==11&&startOfWeek>28){return 1}if(month==0&&startOfWeek<-2){date=new Date(date).decrement("day",dayOfWeek);dayOfWeek=0}firstDayOfYear=new Date(date.get("year"),0,1).get("day")||7;if(firstDayOfYear>4){dividend=-7}}else{firstDayOfYear=new Date(date.get("year"),0,1).get("day")}dividend+=date.get("dayofyear");dividend+=6-dayOfWeek;dividend+=(7+firstDayOfYear-firstDayOfWeek)%7;return(dividend/7)},getOrdinal:function(day){return Date.getMsg("ordinal",day||this.get("date"))},getTimezone:function(){return this.toString().replace(/^.*? ([A-Z]{3}).[0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3")},getGMTOffset:function(){var off=this.get("timezoneOffset");return((off>0)?"-":"+")+pad((off.abs()/60).floor(),2)+pad(off%60,2)},setAMPM:function(ampm){ampm=ampm.toUpperCase();var hr=this.get("hr");if(hr>11&&ampm=="AM"){return this.decrement("hour",12)}else{if(hr<12&&ampm=="PM"){return this.increment("hour",12)}}return this},getAMPM:function(){return(this.get("hr")<12)?"AM":"PM"},parse:function(str){this.set("time",Date.parse(str));return this},isValid:function(date){if(!date){date=this}return typeOf(date)=="date"&&!isNaN(date.valueOf())},format:function(format){if(!this.isValid()){return"invalid date"}if(!format){format="%x %X"}if(typeof format=="string"){format=formats[format.toLowerCase()]||format}if(typeof format=="function"){return format(this)}var d=this;return format.replace(/%([a-z%])/gi,function($0,$1){switch($1){case"a":return Date.getMsg("days_abbr")[d.get("day")];case"A":return Date.getMsg("days")[d.get("day")];case"b":return Date.getMsg("months_abbr")[d.get("month")];case"B":return Date.getMsg("months")[d.get("month")];case"c":return d.format("%a %b %d %H:%M:%S %Y");case"d":return pad(d.get("date"),2);case"e":return pad(d.get("date"),2," ");case"H":return pad(d.get("hr"),2);case"I":return pad((d.get("hr")%12)||12,2);case"j":return pad(d.get("dayofyear"),3);case"k":return pad(d.get("hr"),2," ");case"l":return pad((d.get("hr")%12)||12,2," ");case"L":return pad(d.get("ms"),3);case"m":return pad((d.get("mo")+1),2);case"M":return pad(d.get("min"),2);case"o":return d.get("ordinal");case"p":return Date.getMsg(d.get("ampm"));case"s":return Math.round(d/1000);case"S":return pad(d.get("seconds"),2);case"T":return d.format("%H:%M:%S");case"U":return pad(d.get("week"),2);case"w":return d.get("day");case"x":return d.format(Date.getMsg("shortDate"));case"X":return d.format(Date.getMsg("shortTime"));case"y":return d.get("year").toString().substr(2);case"Y":return d.get("year");case"z":return d.get("GMTOffset");case"Z":return d.get("Timezone")}return $1})},toISOString:function(){return this.format("iso8601")}}).alias({toJSON:"toISOString",compare:"diff",strftime:"format"});var rfcDayAbbr=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],rfcMonthAbbr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var formats={db:"%Y-%m-%d %H:%M:%S",compact:"%Y%m%dT%H%M%S","short":"%d %b %H:%M","long":"%B %d, %Y %H:%M",rfc822:function(date){return rfcDayAbbr[date.get("day")]+date.format(", %d ")+rfcMonthAbbr[date.get("month")]+date.format(" %Y %H:%M:%S %Z")},rfc2822:function(date){return rfcDayAbbr[date.get("day")]+date.format(", %d ")+rfcMonthAbbr[date.get("month")]+date.format(" %Y %H:%M:%S %z")},iso8601:function(date){return(date.getUTCFullYear()+"-"+pad(date.getUTCMonth()+1,2)+"-"+pad(date.getUTCDate(),2)+"T"+pad(date.getUTCHours(),2)+":"+pad(date.getUTCMinutes(),2)+":"+pad(date.getUTCSeconds(),2)+"."+pad(date.getUTCMilliseconds(),3)+"Z")}};var parsePatterns=[],nativeParse=Date.parse;var parseWord=function(type,word,num){var ret=-1,translated=Date.getMsg(type+"s");switch(typeOf(word)){case"object":ret=translated[word.get(type)];break;case"number":ret=translated[word];if(!ret){throw new Error("Invalid "+type+" index: "+word)}break;case"string":var match=translated.filter(function(name){return this.test(name)},new RegExp("^"+word,"i"));if(!match.length){throw new Error("Invalid "+type+" string")}if(match.length>1){throw new Error("Ambiguous "+type)}ret=match[0]}return(num)?translated.indexOf(ret):ret};var startCentury=1900,startYear=70;Date.extend({getMsg:function(key,args){return Locale.get("Date."+key,args)},units:{ms:Function.from(1),second:Function.from(1000),minute:Function.from(60000),hour:Function.from(3600000),day:Function.from(86400000),week:Function.from(608400000),month:function(month,year){var d=new Date;return Date.daysInMonth(month!=null?month:d.get("mo"),year!=null?year:d.get("year"))*86400000},year:function(year){year=year||new Date().get("year");return Date.isLeapYear(year)?31622400000:31536000000}},daysInMonth:function(month,year){return[31,Date.isLeapYear(year)?29:28,31,30,31,30,31,31,30,31,30,31][month]},isLeapYear:function(year){return((year%4===0)&&(year%100!==0))||(year%400===0)},parse:function(from){var t=typeOf(from);if(t=="number"){return new Date(from)}if(t!="string"){return from}from=from.clean();if(!from.length){return null}var parsed;parsePatterns.some(function(pattern){var bits=pattern.re.exec(from);return(bits)?(parsed=pattern.handler(bits)):false});if(!(parsed&&parsed.isValid())){parsed=new Date(nativeParse(from));if(!(parsed&&parsed.isValid())){parsed=new Date(from.toInt())}}return parsed},parseDay:function(day,num){return parseWord("day",day,num)},parseMonth:function(month,num){return parseWord("month",month,num)},parseUTC:function(value){var localDate=new Date(value);var utcSeconds=Date.UTC(localDate.get("year"),localDate.get("mo"),localDate.get("date"),localDate.get("hr"),localDate.get("min"),localDate.get("sec"),localDate.get("ms"));return new Date(utcSeconds)},orderIndex:function(unit){return Date.getMsg("dateOrder").indexOf(unit)+1},defineFormat:function(name,format){formats[name]=format;return this},parsePatterns:parsePatterns,defineParser:function(pattern){parsePatterns.push((pattern.re&&pattern.handler)?pattern:build(pattern));return this},defineParsers:function(){Array.flatten(arguments).each(Date.defineParser);return this},define2DigitYearStart:function(year){startYear=year%100;startCentury=year-startYear;return this}}).extend({defineFormats:Date.defineFormat.overloadSetter()});var regexOf=function(type){return new RegExp("(?:"+Date.getMsg(type).map(function(name){return name.substr(0,3)}).join("|")+")[a-z]*")};var replacers=function(key){switch(key){case"T":return"%H:%M:%S";case"x":return((Date.orderIndex("month")==1)?"%m[-./]%d":"%d[-./]%m")+"([-./]%y)?";case"X":return"%H([.:]%M)?([.:]%S([.:]%s)?)? ?%p? ?%z?"}return null};var keys={d:/[0-2]?[0-9]|3[01]/,H:/[01]?[0-9]|2[0-3]/,I:/0?[1-9]|1[0-2]/,M:/[0-5]?\d/,s:/\d+/,o:/[a-z]*/,p:/[ap]\.?m\.?/,y:/\d{2}|\d{4}/,Y:/\d{4}/,z:/Z|[+-]\d{2}(?::?\d{2})?/};keys.m=keys.I;keys.S=keys.M;var currentLanguage;var recompile=function(language){currentLanguage=language;keys.a=keys.A=regexOf("days");keys.b=keys.B=regexOf("months");parsePatterns.each(function(pattern,i){if(pattern.format){parsePatterns[i]=build(pattern.format)}})};var build=function(format){if(!currentLanguage){return{format:format}}var parsed=[];var re=(format.source||format).replace(/%([a-z])/gi,function($0,$1){return replacers($1)||$0}).replace(/\((?!\?)/g,"(?:").replace(/ (?!\?|\*)/g,",? ").replace(/%([a-z%])/gi,function($0,$1){var p=keys[$1];if(!p){return $1}parsed.push($1);return"("+p.source+")"}).replace(/\[a-z\]/gi,"[a-z\\u00c0-\\uffff;&]");return{format:format,re:new RegExp("^"+re+"$","i"),handler:function(bits){bits=bits.slice(1).associate(parsed);var date=new Date().clearTime(),year=bits.y||bits.Y;if(year!=null){handle.call(date,"y",year)}if("d" in bits){handle.call(date,"d",1)}if("m" in bits||bits.b||bits.B){handle.call(date,"m",1)}for(var key in bits){handle.call(date,key,bits[key])}return date}}};var handle=function(key,value){if(!value){return this}switch(key){case"a":case"A":return this.set("day",Date.parseDay(value,true));case"b":case"B":return this.set("mo",Date.parseMonth(value,true));case"d":return this.set("date",value);case"H":case"I":return this.set("hr",value);case"m":return this.set("mo",value-1);case"M":return this.set("min",value);case"p":return this.set("ampm",value.replace(/\./g,""));case"S":return this.set("sec",value);case"s":return this.set("ms",("0."+value)*1000);case"w":return this.set("day",value);case"Y":return this.set("year",value);case"y":value=+value;if(value<100){value+=startCentury+(value<startYear?100:0)}return this.set("year",value);case"z":if(value=="Z"){value="+00"}var offset=value.match(/([+-])(\d{2}):?(\d{2})?/);offset=(offset[1]+"1")*(offset[2]*60+(+offset[3]||0))+this.getTimezoneOffset();return this.set("time",this-offset*60000)}return this};Date.defineParsers("%Y([-./]%m([-./]%d((T| )%X)?)?)?","%Y%m%d(T%H(%M%S?)?)?","%x( %X)?","%d%o( %b( %Y)?)?( %X)?","%b( %d%o)?( %Y)?( %X)?","%Y %b( %d%o( %X)?)?","%o %b %d %X %z %Y","%T","%H:%M( ?%p)?");Locale.addEvent("change",function(language){if(Locale.get("Date")){recompile(language)}}).fireEvent("change",Locale.getCurrent())})();


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1