Index: trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7519)
+++ trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7579)
@@ -93,5 +93,5 @@
 
     static function parseTimeDate($time, $timezone) {
-	return strtotime($time . ' ' . $timezone) . '000';
+	    return strtotime($time . ' ' . $timezone) . '000';
     }
 
@@ -822,74 +822,81 @@
     //TODO: Remover apos suporte a deepness na api 
     public function deepnessFindEvent(&$uri, &$result, &$criteria, $original) {
-	if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) {
-	    $Time = new DateTime('now', new DateTimeZone('UTC'));
-	    $DayLigth = array();
-	    foreach ($result as $i => $v) {
-
-		if ( isset($v['calendar']) && (!isset($currentTimezone) || $currentTimezone != $original['criteria']['timezones'][$v['calendar']]))  {
-		    $currentTimezone = isset($original['criteria']['timezones'][$v['calendar']]) ? $original['criteria']['timezones'][$v['calendar']] : $v['timezone'];
-		    $Time->setTimezone(new DateTimeZone($currentTimezone));
-		}
-
-		$Time->setTimestamp((int) ($v['startTime'] / 1000));
-		$DayLigth['calendar']['startTime'] = $Time->format('I') ? 1 : 0;
-
-		$Time->setTimestamp((int) ($v['endTime'] / 1000));
-		$DayLigth['calendar']['endTime'] = $Time->format('I') ? 1 : 0;
-
-		if (!isset($currentTimezone) || ($currentTimezone != $v['timezone'])) {
-		    $currentTimezone = $v['timezone'];
-		    $Time->setTimezone(new DateTimeZone($v['timezone']));
-
-		    $Time->setTimestamp((int) ($v['startTime'] / 1000));
-		    $DayLigth['event']['startTime'] = $Time->format('I') ? 1 : 0;
-
-		    $Time->setTimestamp((int) ($v['endTime'] / 1000));
-		    $DayLigth['event']['endTime'] = $Time->format('I') ? 1 : 0;
-		}else
-		    $DayLigth['event'] = $DayLigth['calendar'];
-
-
-		$result[$i]['DayLigth'] = $DayLigth;
-
-        if(((int)$v['type']) == 2){
-
-            $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $v['id']), array('=','owner', Config::me('uidNumber'))) , 'deepness' => 2));
-
-            if($taskToActivity)
-                $result[$i]['taskToActivity'] = $taskToActivity;
-
-            $result[$i]['historic'] = Controller::find(array('concept' => 'calendarHistoric'), false, array('filter' => array('=', 'schedulable', $v['id']) , 'deepness' => 2));
-
+        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) {
+
+            $date = new DateTime('now', new DateTimeZone('UTC'));
+            $DayLigth = array();
+
+            foreach ($result as $i => $v) {
+
+                $currentTimezone = isset($original['criteria']['timezones'][$v['calendar']]) ? $original['criteria']['timezones'][$v['calendar']] : $v['timezone'];
+
+                $date->setTimestamp((int) ($v['startTime'] / 1000));
+                $date->setTimezone( new DateTimeZone( $v['timezone'] ));
+                $DayLigth['event']['startTime'] = ($date->getTimestamp() + $date->getOffset()).'000';
+
+                $date->setTimezone( new DateTimeZone($currentTimezone));
+                $DayLigth['calendar']['startTime'] = ($date->getTimestamp() + $date->getOffset()).'000';
+
+                $date->setTimestamp((int) ($v['endTime'] / 1000));
+                $date->setTimezone( new DateTimeZone($currentTimezone));
+                $DayLigth['event']['endTime'] = ($date->getTimestamp() + $date->getOffset()).'000';
+
+                $date->setTimezone( new DateTimeZone($currentTimezone));
+                $DayLigth['calendar']['endTime'] = ($date->getTimestamp() + $date->getOffset()).'000';
+
+
+                $result[$i]['DayLigth'] = $DayLigth;
+
+                if(((int)$v['type']) == 2){
+
+                    $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $v['id']), array('=','owner', Config::me('uidNumber'))) , 'deepness' => 2));
+
+                    if($taskToActivity)
+                        $result[$i]['taskToActivity'] = $taskToActivity;
+
+                    $result[$i]['historic'] = Controller::find(array('concept' => 'calendarHistoric'), false, array('filter' => array('=', 'schedulable', $v['id']) , 'deepness' => 2));
+
+                }
+
+                if (isset($v['id'])) {
+                    $data = self::decodeParticipantsEvent($uri, $v, $criteria, $original);
+
+                    $result[$i]['statusAttendees'] = isset($data['statusAttendees']) ? $data['statusAttendees'] : false;
+                    $result[$i]['sizeAttendees'] = isset($data['sizeAttendees']) ? $data['sizeAttendees'] : false;
+                    $result[$i]['participants'] = $data['attendees'];
+
+                    $attachmentRelation = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'schedulable', $v['id'])));
+                    if (is_array($attachmentRelation)) {
+                    $attachments = array();
+                    foreach ($attachmentRelation as $key => $value)
+                        if (isset($value['attachment']) || !!$value['attachment'])
+                        $attachments[$key] = $value['attachment'];
+                    //Pega os anexos sem source
+                    $result[$i]['attachments'] = Controller::find(array('concept' => 'attachment'), array('id', 'name', 'type', 'size'), array('filter' => array('IN', 'id', $attachments)));
+                    }
+
+                    $repeat = Controller::find(array('concept' => 'repeat'), false, array('filter' => array('=', 'schedulable', $v['id'])));
+
+                    unset($result[$i]['repeat']);
+
+                    if (is_array($repeat))
+                    $result[$i]['repeat'] = $repeat[0];
+                }
+            }
         }
 
-		if (isset($v['id'])) {
-		    $data = self::decodeParticipantsEvent($uri, $v, $criteria, $original);
-
-		    $result[$i]['statusAttendees'] = isset($data['statusAttendees']) ? $data['statusAttendees'] : false;
-		    $result[$i]['sizeAttendees'] = isset($data['sizeAttendees']) ? $data['sizeAttendees'] : false;
-		    $result[$i]['participants'] = $data['attendees'];
-
-		    $attachmentRelation = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'schedulable', $v['id'])));
-		    if (is_array($attachmentRelation)) {
-			$attachments = array();
-			foreach ($attachmentRelation as $key => $value)
-			    if (isset($value['attachment']) || !!$value['attachment'])
-				$attachments[$key] = $value['attachment'];
-			//Pega os anexos sem source
-			$result[$i]['attachments'] = Controller::find(array('concept' => 'attachment'), array('id', 'name', 'type', 'size'), array('filter' => array('IN', 'id', $attachments)));
-		    }
-
-		    $repeat = Controller::find(array('concept' => 'repeat'), false, array('filter' => array('=', 'schedulable', $v['id'])));
-
-		    unset($result[$i]['repeat']);
-
-		    if (is_array($repeat))
-			$result[$i]['repeat'] = $repeat[0];
-		}
-	    }
-	}
-
-	return $result;
+        return $result;
+    }
+
+    public function diffOffset( $from, $to ){
+
+        if(($from < 0 && $to < 0) || ($from > 0 && $to > 0) ){
+
+            return ($from - $to);
+
+        }else{
+            return ( $from > 0 ? ($to - $from) : ($from - $to));
+        }
+
     }
     
@@ -1175,5 +1182,4 @@
             $uri['id'] = $idSchedulable;
 
-
             if(isset($criteria['type']) && $criteria['type'] == '2'){
 
Index: trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7397)
+++ trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7579)
@@ -605,8 +605,8 @@
 		timezone: objEvent.timezone,
 		timezones: Timezone.timezones,
-		startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
-		startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat),
-		endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0)  ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
-		endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)),  objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat),
+		startDate: Timezone.getDate( (objEvent.DayLigth ? objEvent.DayLigth.event.startTime : objEvent.startTime), 'start', objEvent.allDay ),
+        startHour: objEvent.DayLigth ? Timezone.getHour( objEvent.DayLigth.event.startTime) : Timezone.formateHour( objEvent.startTime ),
+        endDate: Timezone.getDate( (objEvent.DayLigth ? objEvent.DayLigth.event.endTime : objEvent.endTime), 'end', objEvent.allDay ),
+		endHour: objEvent.DayLigth ? Timezone.getHour( objEvent.DayLigth.event.endTime) : Timezone.formateHour( objEvent.endTime ),
 		allDay: !!parseInt( objEvent.allDay ),
 		dueDate: objEvent.dueDate,
@@ -1407,5 +1407,5 @@
 			    isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0,
 			    acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '')
-			}, form.delegatedFrom[i] != '0' ? {
+			}, (form.delegatedFrom[i] != '0' && form.delegatedFrom[i] != '') ? {
 			    delegatedFrom: form.delegatedFrom[i]
 			    } : {});
@@ -1747,5 +1747,5 @@
 	    }
 
-		var duration = parseInt( evt.endTime ) - parseInt( evt.startTime ), isRepeat = false;
+		var duration = parseInt( evt.DayLigth.calendar.endTime ) - parseInt( evt.DayLigth.calendar.startTime ), isRepeat = false;
 
 		var occurrences = [];
@@ -1756,5 +1756,5 @@
 			occurrences = evt.occurrences;
 	    }else
-			occurrences[ occurrences.length ] = evt.startTime;
+			occurrences[ occurrences.length ] = evt.DayLigth.calendar.startTime;
 
 	    //occurrences = DataLayer.unique( occurrences ).sort();
@@ -1767,6 +1767,6 @@
 				id: evt.URI || evt.id+ '-' + i,
 				title: Encoder.htmlDecode(evt.summary),
-				start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone,  !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
-				end:   Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
+				start: Timezone.getDateObjCalendar( occurrences[i], 'start', evt.allDay),
+                end: Timezone.getDateObjCalendar( (parseInt( occurrences[i] ) + duration), 'end', evt.allDay),
 				allDay: parseInt( evt.allDay ),
 				isRepeat: isRepeat,
Index: trunk/prototype/modules/calendar/js/timezone.js
===================================================================
--- trunk/prototype/modules/calendar/js/timezone.js	(revision 6069)
+++ trunk/prototype/modules/calendar/js/timezone.js	(revision 7579)
@@ -5,5 +5,5 @@
 */
 
-var objTime = DataLayer.dispatch( "timezones" );
+var objTime = DataLayer.dispatch( "timezones", {teste:'123'} );
 
 Timezone = {
@@ -11,6 +11,10 @@
 	daylightSaving: isNaN(parseInt( objTime.isDaylightSaving )) ? 0 : parseInt( objTime.isDaylightSaving ),
 
+    start:false,
+    end:false,
+
 	timezones: objTime.timezones,	  
-	timezone: function( tzId ){
+
+    timezone: function( tzId ){
 
 		return this.timezones[ tzId || User.preferences.timezone ];
@@ -18,40 +22,78 @@
 	},
 	
-	getDateCalendar: function(date, tzId, isDay){
-		var timezone = this.timezone( tzId );
+	getDateCalendar: function( date, tzId, isDayLigth ){
 
-		if(!timezone)
-			return date;
+        return date;
 
-	 	date = this.normalizeDate(date, false, true);
-
-		return date.add({hours: parseInt(timezone.charAt(0) + timezone.charAt(2))  +  parseInt(isDay) });
 	},
 	
-	getDateEvent: function(date, tzId, idCalendar, isDay, type){
-		var timezone = this.timezone( tzId );
-		var timezoneCurrent = this.timezone(DataLayer.get('calendar', idCalendar).timezone);
+	getDateEvent: function(date, tzId, isDayLigth){
+        if(!tzId)
+            return date;
 
-		if(timezone == timezoneCurrent)
-			return date;
-		
-		var to = parseInt(timezone.charAt(0) + timezone.charAt(2)) + parseInt(isDay.event[type]);
-		var current = parseInt(timezoneCurrent.charAt(0) + timezoneCurrent.charAt(2)) + parseInt(isDay.calendar[type]);
-		
-		if(timezone.charAt(0) == timezoneCurrent.charAt(0))
-			hours =   (  to + (current * - 1)) ;
-		else
-			hours =  to + (( current ) * (timezone.charAt(0) ==  '+'  ? -1 : 1)) ;
-		
-		return date.add({hours: hours});
+        var timezone = this.timezone( tzId );
+
+        if(!timezone)
+            return date;
+
+        date = this.normalizeDate(date, false, true);
+
+        return date.add({hours: (parseInt(timezone.charAt(0) + timezone.charAt(2)) + Timezone.diff( isDayLigth )) });
 	},
-	
+
+    diff: function(isDayLigth){
+
+        if( !parseInt( isDayLigth ) ){
+            return 0;
+        }else{
+
+            return (parseInt( isDayLigth ) == 1 ? 1 : -1);
+        }
+
+    },
+
 	normalizeDate: function(date, current, inverse){
+
 		var offsetDate = !!current ? this.currentOffset : date.getUTCOffset();
 		return date.add({hours: (parseInt(offsetDate.charAt(0) + offsetDate.charAt(2)) * (!!inverse ? -1 : 1) )});
+
 	},
 	
 	getDateMapDisponibility: function(date){
+
 		return this.normalizeDate(date, false, true);
-	}
+
+	},
+
+    getHour: function(time){
+
+        return dateCalendar.formatDate( Timezone.normalizeDate( new Date( parseInt( time ) ), false, true) , User.preferences.hourFormat);
+
+    },
+
+    formateHour: function(time){
+
+        return dateCalendar.formatDate(  new Date( parseInt( time ) ) , User.preferences.hourFormat);
+
+    },
+
+    getDate: function( time, rang, isAllDay){
+
+        return (new Date( parseInt( time ) - ((rang == 'end' && isAllDay && parseInt(isAllDay) == 1) ? 86400000 : 0) )).toString( User.preferences.dateFormat );
+
+    },
+
+    getDateObj: function( time, rang, isAllDay){
+
+        return Timezone.normalizeDate(new Date( parseInt( time ) - ((rang == 'end' && isAllDay && parseInt(isAllDay) == 1) ? 86400000 : 0) ), false, true);
+
+    },
+
+    getDateObjCalendar: function( time, rang, isAllDay){
+
+        return  Timezone.normalizeDate(new Date( parseInt( time ) - ((rang == 'end' && isAllDay && parseInt(isAllDay) == 1) ? 86400000 : 0)), false, true);
+
+    }
+
+
 }
Index: trunk/prototype/modules/calendar/js/init.js
===================================================================
--- trunk/prototype/modules/calendar/js/init.js	(revision 7524)
+++ trunk/prototype/modules/calendar/js/init.js	(revision 7579)
@@ -349,5 +349,6 @@
 		},
 
-		eventRender: function( event, element, view ){
+
+        eventRender: function( event, element, view ){
 		    $('#calendar td.fc-year-have-event').removeClass('fc-year-have-event');
 
@@ -363,5 +364,5 @@
     	    element.find(".fc-event-inner.fc-event-skin").prepend($('<img style="width: 11px; height: 13px;" class="" src="../prototype/modules/calendar/img/' + img_icon + '"></img>'));
 		},
-		
+
 		select: function( start, end, allDay, event, view ){
 			if (view.name == "month") {
@@ -502,5 +503,7 @@
 		
 		eventAfterRender: function(event, element, view){
+
 			contentMenu();
+
 		}
 	}, dateCalendar));	
