Logo Search packages:      
Sourcecode: davical version File versions  Download package

& RRule::GetNext (  )

This is most of the meat of the RRULE processing, where we find the next date. We maintain an

If we have already found some dates we may just be able to return one of those.

Definition at line 819 of file RRule.php.

References WithinScope().

                       {

    if ( $this->_current < 0 ) {
      $next = new iCalDate($this->_first);
      $this->_current++;
    }
    else {
      $next = new iCalDate($this->_dates[$this->_current]);
      $this->_current++;

      /**
      * If we have already found some dates we may just be able to return one of those.
      */
      if ( isset($this->_dates[$this->_current]) ) {
        dbg_error_log( "RRule", " GetNext: Returning %s, (%d'th)", $this->_dates[$this->_current]->Render(), $this->_current );
        return $this->_dates[$this->_current];
      }
      else {
        if ( isset($this->_part['COUNT']) && $this->_current >= $this->_part['COUNT'] ) // >= since _current is 0-based and COUNT is 1-based
          $this->_finished = true;
      }
    }

    if ( $this->_finished ) {
      $next = null;
      return $next;
    }

    $days = array();
    if ( isset($this->_part['WKST']) ) $next->SetWeekStart($this->_part['WKST']);
    if ( $this->_part['FREQ'] == "MONTHLY" ) {
      dbg_error_log( "RRule", " GetNext: Calculating more dates for MONTHLY rule" );
      $limit = 200;
      do {
        $limit--;
        do {
          $limit--;
          if ( $this->_started ) {
            $next->AddMonths($this->_part['INTERVAL']);
          }
          else {
            $this->_started = true;
          }
        }
        while ( isset($this->_part['BYMONTH']) && $limit > 0 && ! $next->TestByMonth($this->_part['BYMONTH']) );

        if ( isset($this->_part['BYDAY']) ) {
          $days = $next->GetMonthByDay($this->_part['BYDAY']);
        }
        else if ( isset($this->_part['BYMONTHDAY']) ) {
          $days = $next->GetMonthByMonthDay($this->_part['BYMONTHDAY']);
        }
        else
          $days[$next->_dd] = $next->_dd;

        if ( isset($this->_part['BYSETPOS']) ) {
          $days = $next->ApplyBySetpos($this->_part['BYSETPOS'], $days);
        }

        $days = $this->WithinScope( $next, $days);
      }
      while( $limit && count($days) < 1 && ! $this->_finished );
      dbg_error_log( "RRule", " GetNext: Found %d days for MONTHLY rule", count($days) );

    }
    else if ( $this->_part['FREQ'] == "WEEKLY" ) {
      dbg_error_log( "RRule", " GetNext: Calculating more dates for WEEKLY rule" );
      $limit = 200;
      do {
        $limit--;
        if ( $this->_started ) {
          $next->AddDays($this->_part['INTERVAL'] * 7);
        }
        else {
          $this->_started = true;
        }

        if ( isset($this->_part['BYDAY']) ) {
          $days = $next->GetWeekByDay($this->_part['BYDAY'], false );
        }
        else
          $days[$next->_dd] = $next->_dd;

        if ( isset($this->_part['BYSETPOS']) ) {
          $days = $next->ApplyBySetpos($this->_part['BYSETPOS'], $days);
        }

        $days = $this->WithinScope( $next, $days);
      }
      while( $limit && count($days) < 1 && ! $this->_finished );

      dbg_error_log( "RRule", " GetNext: Found %d days for WEEKLY rule", count($days) );
    }
    else if ( $this->_part['FREQ'] == "DAILY" ) {
      dbg_error_log( "RRule", " GetNext: Calculating more dates for DAILY rule" );
      $limit = 100;
      do {
        $limit--;
        if ( $this->_started ) {
          $next->AddDays($this->_part['INTERVAL']);
        }

        if ( isset($this->_part['BYDAY']) ) {
          $days = $next->GetWeekByDay($this->_part['BYDAY'], $this->_started );
        }
        else
          $days[$next->_dd] = $next->_dd;

        if ( isset($this->_part['BYSETPOS']) ) {
          $days = $next->ApplyBySetpos($this->_part['BYSETPOS'], $days);
        }

        $days = $this->WithinScope( $next, $days);
        $this->_started = true;
      }
      while( $limit && count($days) < 1 && ! $this->_finished );

      dbg_error_log( "RRule", " GetNext: Found %d days for DAILY rule", count($days) );
    }

    $ptr = $this->_current;
    foreach( $days AS $k => $v ) {
      $this->_dates[$ptr++] = $v;
    }

    if ( isset($this->_dates[$this->_current]) ) {
      dbg_error_log( "RRule", " GetNext: Returning %s, (%d'th)", $this->_dates[$this->_current]->Render(), $this->_current );
      return $this->_dates[$this->_current];
    }
    else {
      dbg_error_log( "RRule", " GetNext: Returning null date" );
      $next = null;
      return $next;
    }
  }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index