Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5731)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5737)
@@ -107,13 +107,20 @@
 	  $end = $criteria['filter'][2][2];
 
-         $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", calendar_object.dtstart as "startTime", calendar_object.summary as "summary", calendar_object.description as "description", calendar_object.dtend as "endTime" , calendar_object.location as "location", calendar_object.allday as "allDay", calendar_object.transp as "transparent", calendar_object.class_id as "class", calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart",calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence",  calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as calendar FROM calendar_to_calendar_object , calendar_object WHERE (range_start >= \''.$start.'\' AND range_end <= \''.$end.'\' AND calendar_to_calendar_object.calendar_id IN (\''.  implode('\',\'', $criteria['filter'][3][2]).'\')) AND calendar_to_calendar_object.calendar_object_id = calendar_object.id';
-         
+	  $ids = array();
+	  $occ = array();
+
+	  if( $occurrences = self::checkOccurrences( $start, $end, intval($criteria['deepness']) + 1 ) )
+	      foreach( $occurrences as $id => $occurrence )
+	      {
+		  $ids[] = $id;
+		  $occ[] = $occurrence;
+	      }
+
+         $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", calendar_object.dtstart as "startTime", calendar_object.summary as "summary", calendar_object.description as "description", calendar_object.dtend as "endTime" , calendar_object.location as "location", calendar_object.allday as "allDay", calendar_object.transp as "transparent", calendar_object.class_id as "class", calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart",calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence",  calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as calendar FROM calendar_to_calendar_object , calendar_object WHERE (range_start >= \''.$start.'\' AND range_end <= \''.$end.'\' AND calendar_to_calendar_object.calendar_id IN (\''.  implode('\',\'', $criteria['filter'][3][2]).'\')) AND calendar_to_calendar_object.calendar_object_id = calendar_object.id'.( !empty($ids) ? ' AND calendar_object.id NOT IN (\'' .implode( '\',\'', $ids ). '\')' : '');
+
 	 $params = Controller::service('PostgreSQL')->execResultSql($sql);
          $params = self::deepnessFindEvent( &$uri , &$params , &$criteria , $original);
-
-	 $occ = self::checkOccurrences( $criteria['filter'][1][2], $criteria['filter'][2][2], intval($criteria['deepness']) + 1 );
-
-	 if( $occ )
-	    $params = array_merge( $params, $occ );
+ 
+	 $params = array_merge( $params, $occ );
 
          return false;
@@ -252,21 +259,17 @@
 	      {
 		    $result[ $currentId ] = $ret['repeat']['schedulable'];
+		    $result[ $currentId ]['repeat']['schedulable'] = $currentId;
+
 		    $result[ $currentId ][ 'occurrences' ] = array();
-  
+
 		    $calendarToCalendarObj = self::schedulable2calendarToObject( $currentId );
 
-		    $result[ $currentId ]['calendar'] = $calendarToCalendarObj[0]['calendar_id'];
-
-		    unset( $result[ $currentId ]['repeat'] );
+		    $result[ $currentId ]['calendar'] = $calendarToCalendarObj[0]['calendar_id'];  
 	      }
       
 	      $result[ $currentId  ][ 'occurrences' ][] = $ret['occurrence'];
-
 	}
 
-	foreach( $result as $id => $res )
-	    $params[] = $res;
-
-	return( $params );
+	return( $result );
     }
 
Index: /trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5729)
+++ /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5737)
@@ -687,5 +687,5 @@
 	var formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat;
 
-	var date = Date.parseExact( form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).add( { days: 1 } ).toString('yyyy-MM-dd HH:mm:00');
+	var date = Date.parseExact( form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00');
 	
 	patati['startTime'] = date.toString('yyyy-MM-dd HH:mm:00');
@@ -979,5 +979,5 @@
 		var duration = parseInt( evt.endTime ) - parseInt( evt.startTime ), isRepeat = false;
 		
-		var occurrences = [ evt.startTime ];
+		var occurrences = [];
 		
 		if( evt.occurrences )
@@ -986,4 +986,8 @@
 		    occurrences = evt.occurrences;
 		}
+
+		occurrences[ occurrences.length ] = evt.startTime;
+
+		occurrences = DataLayer.unique( occurrences );
 		  
 		for( var i = 0; i < occurrences.length; i++ )
