1 line
6.7 KiB
JavaScript
1 line
6.7 KiB
JavaScript
Type.registerNamespace("Sys.Extended.UI"),Sys.Extended.UI.TimeSpan=function(){if(0==arguments.length)this._ctor$0.apply(this,arguments);else if(1==arguments.length)this._ctor$1.apply(this,arguments);else if(3==arguments.length)this._ctor$2.apply(this,arguments);else if(4==arguments.length)this._ctor$3.apply(this,arguments);else{if(5!=arguments.length)throw Error.parameterCount();this._ctor$4.apply(this,arguments)}},Sys.Extended.UI.TimeSpan.prototype={_ctor$0:function(){this._ticks=0},_ctor$1:function(e){this._ctor$0(),this._ticks=e},_ctor$2:function(e,t,n){this._ctor$0(),this._ticks=e*Sys.Extended.UI.TimeSpan.TicksPerHour+t*Sys.Extended.UI.TimeSpan.TicksPerMinute+n*Sys.Extended.UI.TimeSpan.TicksPerSecond},_ctor$3:function(e,t,n,i){this._ctor$0(),this._ticks=e*Sys.Extended.UI.TimeSpan.TicksPerDay+t*Sys.Extended.UI.TimeSpan.TicksPerHour+n*Sys.Extended.UI.TimeSpan.TicksPerMinute+i*Sys.Extended.UI.TimeSpan.TicksPerSecond},_ctor$4:function(e,t,n,i,s){this._ctor$0(),this._ticks=e*Sys.Extended.UI.TimeSpan.TicksPerDay+t*Sys.Extended.UI.TimeSpan.TicksPerHour+n*Sys.Extended.UI.TimeSpan.TicksPerMinute+i*Sys.Extended.UI.TimeSpan.TicksPerSecond+s*Sys.Extended.UI.TimeSpan.TicksPerMillisecond},getDays:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerDay)},getHours:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerHour)%24},getMinutes:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerMinute)%60},getSeconds:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerSecond)%60},getMilliseconds:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerMillisecond)%1e3},getDuration:function(){return new Sys.Extended.UI.TimeSpan(Math.abs(this._ticks))},getTicks:function(){return this._ticks},getTotalDays:function(){Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerDay)},getTotalHours:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerHour)},getTotalMinutes:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerMinute)},getTotalSeconds:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerSecond)},getTotalMilliseconds:function(){return Math.floor(this._ticks/Sys.Extended.UI.TimeSpan.TicksPerMillisecond)},add:function(e){return new Sys.Extended.UI.TimeSpan(this._ticks+e.getTicks())},subtract:function(e){return new Sys.Extended.UI.TimeSpan(this._ticks-e.getTicks())},negate:function(){return new Sys.Extended.UI.TimeSpan((-this._ticks))},equals:function(e){return this._ticks==e.getTicks()},compareTo:function(e){return this._ticks>e.getTicks()?1:this._ticks<e.getTicks()?-1:0},toString:function(){return this.format("F")},format:function(e){if(e||(e="F"),1==e.length)switch(e){case"t":e=Sys.Extended.UI.TimeSpan.ShortTimeSpanPattern;break;case"T":e=Sys.Extended.UI.TimeSpan.LongTimeSpanPattern;break;case"F":e=Sys.Extended.UI.TimeSpan.FullTimeSpanPattern;break;default:throw Error.createError(String.format(Sys.Extended.UI.Resources.Common_DateTime_InvalidTimeSpan,e))}var t=/dd|d|hh|h|mm|m|ss|s|nnnn|nnn|nn|n/g,n=new Sys.StringBuilder,i=this._ticks;for(i<0&&(n.append("-"),i=-i);;){var s=t.lastIndex,r=t.exec(e);if(n.append(e.slice(s,r?r.index:e.length)),!r)break;switch(r[0]){case"dd":case"d":n.append($common.padLeft(Math.floor(i/Sys.Extended.UI.TimeSpan.TicksPerDay,r[0].length,"0")));break;case"hh":case"h":n.append($common.padLeft(Math.floor(i/Sys.Extended.UI.TimeSpan.TicksPerHour)%24,r[0].length,"0"));break;case"mm":case"m":n.append($common.padLeft(Math.floor(i/Sys.Extended.UI.TimeSpan.TicksPerMinute)%60,r[0].length,"0"));break;case"ss":case"s":n.append($common.padLeft(Math.floor(i/Sys.Extended.UI.TimeSpan.TicksPerSecond)%60,r[0].length,"0"));break;case"nnnn":case"nnn":case"nn":case"n":n.append($common.padRight(Math.floor(i/Sys.Extended.UI.TimeSpan.TicksPerMillisecond)%1e3,r[0].length,"0",!0));break;default:Sys.Debug.assert(!1)}}return n.toString()}},Sys.Extended.UI.TimeSpan.parse=function(e){var t=e.split(":"),n=0,i=0,s=0,r=0,a=0,d=0;switch(t.length){case 1:if(t[0].indexOf(".")!=-1){var c=t[0].split(".");r=parseInt(c[0]),a=parseInt(c[1])}else d=parseInt(t[0]);break;case 2:i=parseInt(t[0]),s=parseInt(t[1]);break;case 3:if(i=parseInt(t[0]),s=parseInt(t[1]),t[2].indexOf(".")!=-1){var c=t[2].split(".");r=parseInt(c[0]),a=parseInt(c[1])}else r=parseInt(t[2]);break;case 4:if(n=parseInt(t[0]),i=parseInt(t[1]),s=parseInt(t[2]),t[3].indexOf(".")!=-1){var c=t[3].split(".");r=parseInt(c[0]),a=parseInt(c[1])}else r=parseInt(t[3])}if(d+=n*Sys.Extended.UI.TimeSpan.TicksPerDay+i*Sys.Extended.UI.TimeSpan.TicksPerHour+s*Sys.Extended.UI.TimeSpan.TicksPerMinute+r*Sys.Extended.UI.TimeSpan.TicksPerSecond+a*Sys.Extended.UI.TimeSpan.TicksPerMillisecond,!isNaN(d))return new Sys.Extended.UI.TimeSpan(d);throw Error.create(Sys.Extended.UI.Resources.Common_DateTime_InvalidFormat)},Sys.Extended.UI.TimeSpan.fromTicks=function(e){return new Sys.Extended.UI.TimeSpan(e)},Sys.Extended.UI.TimeSpan.fromDays=function(e){return new Sys.Extended.UI.TimeSpan(e*Sys.Extended.UI.TimeSpan.TicksPerDay)},Sys.Extended.UI.TimeSpan.fromHours=function(e){return new Sys.Extended.UI.TimeSpan(e*Sys.Extended.UI.TimeSpan.TicksPerHour)},Sys.Extended.UI.TimeSpan.fromMinutes=function(e){return new Sys.Extended.UI.TimeSpan(e*Sys.Extended.UI.TimeSpan.TicksPerMinute)},Sys.Extended.UI.TimeSpan.fromSeconds=function(e){return new Sys.Extended.UI.TimeSpan(minutes*Sys.Extended.UI.TimeSpan.TicksPerSecond)},Sys.Extended.UI.TimeSpan.fromMilliseconds=function(e){return new Sys.Extended.UI.TimeSpan(minutes*Sys.Extended.UI.TimeSpan.TicksPerMillisecond)},Sys.Extended.UI.TimeSpan.TicksPerDay=864e9,Sys.Extended.UI.TimeSpan.TicksPerHour=36e9,Sys.Extended.UI.TimeSpan.TicksPerMinute=6e8,Sys.Extended.UI.TimeSpan.TicksPerSecond=1e7,Sys.Extended.UI.TimeSpan.TicksPerMillisecond=1e4,Sys.Extended.UI.TimeSpan.FullTimeSpanPattern="dd:hh:mm:ss.nnnn",Sys.Extended.UI.TimeSpan.ShortTimeSpanPattern="hh:mm",Sys.Extended.UI.TimeSpan.LongTimeSpanPattern="hh:mm:ss",Date.prototype.getTimeOfDay=function(){return new Sys.Extended.UI.TimeSpan(0,this.getHours(),this.getMinutes(),this.getSeconds(),this.getMilliseconds())},Date.prototype.getDateOnly=function(){var e=new Date(this.getFullYear(),this.getMonth(),this.getDate());return this.getMonth()===e.getMonth()&&this.getDate()===e.getDate()||e.setMinutes(120),e},Date.prototype.add=function(e){return new Date(this.getTime()+e.getTotalMilliseconds())},Date.prototype.subtract=function(e){return this.add(e.negate())},Date.prototype.getTicks=function(){return this.getTime()*Sys.Extended.UI.TimeSpan.TicksPerMillisecond},Sys.Extended.UI.FirstDayOfWeek=function(){},Sys.Extended.UI.FirstDayOfWeek.prototype={Sunday:0,Monday:1,Tuesday:2,Wednesday:3,Thursday:4,Friday:5,Saturday:6,Default:7},Sys.Extended.UI.FirstDayOfWeek.registerEnum("Sys.Extended.UI.FirstDayOfWeek"); |