/**
  * Apply limits (count or until)
  *
  * @access protected
  * @param object ilDateList
  * 
  */
 protected function applyLimits(ilDateList $list)
 {
     $list->sort();
     #echo "list: ";
     #echo $list;
     #echo '<br />';
     // Check valid dates before starting time
     foreach ($list->get() as $check_date) {
         if (ilDateTime::_before($check_date, $this->event->getStart(), IL_CAL_DAY)) {
             #echo 'Removed: '.$check_date.'<br/>';
             $list->remove($check_date);
         }
     }
     #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
     // Check count if given
     if ($this->recurrence->getFrequenceUntilCount()) {
         foreach ($list->get() as $res) {
             // check smaller than since the start time counts as one
             if (count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount()) {
                 $this->valid_dates->add($res);
             } else {
                 $this->limit_reached = true;
                 return false;
             }
         }
         return true;
     } elseif ($this->recurrence->getFrequenceUntilDate()) {
         #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
         $date = $this->recurrence->getFrequenceUntilDate();
         foreach ($list->get() as $res) {
             #echo 'Check date '.$res;
             if (ilDateTime::_after($res, $date, IL_CAL_DAY)) {
                 #echo 'Limit reached';
                 $this->limit_reached = true;
                 return false;
             }
             $this->valid_dates->add($res);
         }
         return true;
     }
     $this->valid_dates->merge($list);
     return true;
 }