TimeZone.js 3.82 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
//Require CscBase.js ,CscCalendarV3.js
		function TimeZone( beginZone , endingZone ){
			if(!beginZone instanceof CscCalendar && !endingZone instanceof CscCalendar){
				this._destroy();
				return false;
			}
			this.setBeginZone( beginZone );  
			this.setEndingZone( endingZone );
			/*this._options = {
				beginzone : beginZone,
				endingzone : endingZone
			}*/
		}

		TimeZone.prototype = $.extend({} , Csc.prototype , {
			getKeyZone : function(){
				return this.getBeginZone().getYYYYMMDDHHMM().replace(/-/g,"").replace(/ /g,"").replace(/\./g,"");
			},

			getBeginZone : function(){
				return this._getOption("beginzone");
			},

			getEndingZone : function(){
				return this._getOption("endingzone");
			},

			getDiffTimeZone : function(){
				var b = this.getBeginZone() , e = this.getEndingZone() , r; 
				if(b && e)
					return e.getDiffTime( b );
				return r;
			},

			setBeginZone : function( beginZone ){
				//Force CscCalendar ҹ
				if(beginZone instanceof CscCalendar){
					var ez = this.getEndingZone();
					if( !$.isEmptyObject( ez ) && ez instanceof CscCalendar && ez.beforeDateTime( beginZone )){
						console.log("can't setBeginZone By endzone befor beginzone ");
						return false;
					}else{
						this._setOption( "beginzone" , beginZone);
						return true;
					}
				}
			},

			setEndingZone : function( endingzone ){
				//Force CscCalendar ҹ
				if(endingzone instanceof CscCalendar){
					var bg = this.getBeginZone();
					if( !$.isEmptyObject( bg ) && bg instanceof CscCalendar && endingzone.beforeDateTime( bg )){
						console.log("can't setBeginZone By endzone befor beginzone "); 
						return false;
					}else{
						this._setOption( "endingzone" , endingzone);
						return true;
					}
				}
			},

			// ǧ  shift  еͧ shift ҹ  ǧ  㴢˹ش͡͡ shift ö
			TimeZoneInnerTimeZone : function( tz ){
				if( !this.isTimeZone.call( tz ) )
					return false;
				return ( this.timeInTimeZone( tz.getBeginZone() ) && this.timeInTimeZone( tz.getEndingZone() ));
			},

			timeInTimeZone : function( time ){
				//Force CscCalendar ҹ
				return time instanceof CscCalendar && this.getBeginZone() && this.getEndingZone() && ( time.getTimeInMillis() >= this.getBeginZone().getTimeInMillis() && time.getTimeInMillis() <= this.getEndingZone().getTimeInMillis() );
			},
			
			/* еͧբŷͧâͧ TimeZone ú 
				¡ (instanceof TimeZone) ҡ fix ҵͧ new TimeZone ҹ Ҩա extend  class   property ú ö
			*/
			isTimeZone : function(){
				return (this.getBeginZone && this.getEndingZone) && (this.getBeginZone() && this.getEndingZone());
			},

			intersectTimeZone : function( tz ){
				if( !this.isTimeZone.call( tz ) )
					return false;			
				return ( ( this.getBeginZone().getTimeInMillis() >= tz.getBeginZone().getTimeInMillis() && this.getBeginZone().getTimeInMillis() <= tz.getEndingZone().getTimeInMillis() ) ||
					( this.getEndingZone().getTimeInMillis() >= tz.getBeginZone().getTimeInMillis() && this.getEndingZone().getTimeInMillis() <= tz.getEndingZone().getTimeInMillis() ) ||
					( this.getBeginZone().getTimeInMillis() <= tz.getBeginZone().getTimeInMillis() && this.getEndingZone().getTimeInMillis() >=  tz.getEndingZone().getTimeInMillis()) );
			},

			isJoinTime : function( tz ){
				if( !this.isTimeZone.call( tz ) )
					return false;
				return ( this.getBeginZone().equalsDateTime( tz.getEndingZone() ) ) || ( this.getEndingZone().equalsDateTime( tz.getBeginZone() ) );
			},
			
			setType : function( type ){
				this._setOption( "eventgrp" , type );
			},

			getType : function(){
				return this._getOption( "eventgrp" );
			},

			isType : function( t ){
				return this.getType() == t;
			}
		});