Index: trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7660)
+++ trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7680)
@@ -82,6 +82,11 @@
     	
 
-        if (isset($params['due']) && $params['due'] != '' && !is_numeric($params['due']))
+        if (isset($params['due']) && $params['due'] != '' && !is_numeric($params['due'])){
             $params['due'] = self::parseTimeDate($params['due'], $params['timezone']);
+
+            if ($params['allDay'])
+                $params['due'] = $params['due'] + 86400000;
+        }
+
 
     	///////////////////////////////////////////////////////////////////
@@ -535,9 +540,19 @@
     	    }
     	    $params['rangeEnd'] = $params['endTime'];
+
+            if($event['type'] == '2'){
+
+                if(!isset($params['due']) && $params['endTime'] != $event['endTime'])
+                    $params['due'] = $params['endTime'];
+
+            }
     	}
 
-
-        if (isset($params['due']) && $params['due'] != '' && !is_numeric($params['due']))
+        if (isset($params['due']) && $params['due'] != '' && !is_numeric($params['due'])){
             $params['due'] = self::parseTimeDate($params['due'], $event['timezone']);
+
+            if ((isset($params['allDay']) && $params['allDay']) || ( !isset($params['allDay']) && $event['allDay']))
+                $params['due'] = $params['due'] + 86400000;
+        }
 
         if($event['type'] == '2'){
@@ -550,51 +565,51 @@
                 unset($criteria['historic']['due']);
 
-		//necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada
-		if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){
-			$taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'task', $uri['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
-			if(!empty($taskToActivity)){
-				$activity = Controller::read(array('concept' => 'schedulable', 'id' => $taskToActivity[0]['activity']), array('startTime', 'endTime', 'rangeStart', 'rangeEnd', 'allDay'));
-				$isAllDay = 1;
-
-				if(!empty($activity)){
-					$start = $params['startTime'];
-					$end = $params['endTime'];
-					foreach($taskToActivity as $t){
-					 if($t['task']['id'] != $params['id']){
-						$start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;
-						$end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;
-						$isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0; 
-					 }
-					}
-
-					if($event['allDay'] == '0' || (isset($params['allDay']) && $params['allDay'] == '0'))
-						$isAllDay = 0;
-
-					$toUpdate = array();
-
-					if($start != $activity['startTime'])
-						$toUpdate['startTime'] = $start;
-
-					if($end != $activity['endTime']){
-						$toUpdate['endTime'] = $end;
-						$toUpdate['due'] = $end;
-					}
-
-					if($isAllDay != $activity['allDay'])
-						$toUpdate['allDay'] = $isAllDay;
-
-					if(!empty($toUpdate))
-						Controller::update(array('concept' => 'schedulable', 'id' => $taskToActivity[0]['activity']), $toUpdate);
-				}
-			}
-		}
-
-		unset($criteria['historic']['endTime']);
-		unset($criteria['historic']['rangeEnd']);
-		unset($criteria['historic']['rangeStart']);
-		unset($criteria['historic']['class']);
-		unset($criteria['historic']['type']);
-		unset($criteria['historic']['allDay']);
-		unset($criteria['historic']['id']);            
+            //necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada
+            if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){
+                $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'task', $uri['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
+                if(!empty($taskToActivity)){
+                    $activity = Controller::read(array('concept' => 'schedulable', 'id' => $taskToActivity[0]['activity']), array('startTime', 'endTime', 'rangeStart', 'rangeEnd', 'allDay'));
+                    $isAllDay = 1;
+
+                    if(!empty($activity)){
+                        $start = $params['startTime'];
+                        $end = $params['endTime'];
+                        foreach($taskToActivity as $t){
+                         if($t['task']['id'] != $params['id']){
+                            $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;
+                            $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;
+                            $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0;
+                         }
+                        }
+
+                        if($event['allDay'] == '0' || (isset($params['allDay']) && $params['allDay'] == '0'))
+                            $isAllDay = 0;
+
+                        $toUpdate = array();
+
+                        if($start != $activity['startTime'])
+                            $toUpdate['startTime'] = $start;
+
+                        if($end != $activity['endTime']){
+                            $toUpdate['endTime'] = $end;
+                            $toUpdate['due'] = $end;
+                        }
+
+                        if($isAllDay != $activity['allDay'])
+                            $toUpdate['allDay'] = $isAllDay;
+
+                        if(!empty($toUpdate))
+                            Controller::update(array('concept' => 'schedulable', 'id' => $taskToActivity[0]['activity']), $toUpdate);
+                    }
+                }
+            }
+
+            unset($criteria['historic']['endTime']);
+            unset($criteria['historic']['rangeEnd']);
+            unset($criteria['historic']['rangeStart']);
+            unset($criteria['historic']['class']);
+            unset($criteria['historic']['type']);
+            unset($criteria['historic']['allDay']);
+            unset($criteria['historic']['id']);
         }
     }
@@ -847,4 +862,12 @@
                 $date->setTimezone( new DateTimeZone($currentTimezone));
                 $DayLigth['event']['endTime'] = ($date->getTimestamp() + $date->getOffset()).'000';
+
+                if(isset($v['due']) && $v['due'] != '0'){
+                    $date->setTimestamp((int) ($v['due'] / 1000));
+                    $DayLigth['event']['due'] = ($date->getTimestamp() + $date->getOffset()).'000';
+                }else{
+                    $DayLigth['event']['due'] = $v['due'];
+                }
+
 
                 $date->setTimezone( new DateTimeZone($currentTimezone));
