You are here

protected function DateRRuleCalc::get_relative_bydays in Date 8

Get results for relative BYDAY values.

BYDAYs with parameters like -1SU (last Sun) or 2TH (second Thur) need to be processed one month or year at a time.

1 call to DateRRuleCalc::get_relative_bydays()
DateRRuleCalc::get_byday_results in date_repeat/lib/Drupal/date_repeat/DateRRuleCalc.php
Processing for BYDAY values.

File

date_repeat/lib/Drupal/date_repeat/DateRRuleCalc.php, line 454
Code to compute the dates that match an iCal RRULE.

Class

DateRRuleCalc

Namespace

Drupal\date_repeat

Code

protected function get_relative_bydays($relative_days) {
  $finished = FALSE;
  $this->current_day = clone $this->start_date;
  while (!$finished) {
    foreach ($relative_days as $day) {

      // Find the BYDAY date in the current period.
      switch ($this->rrule['FREQ']) {
        case 'MONTHLY':
          if ($this
            ->set_month_day($day['day'], $day['direction_count'], $day['direction'])) {
            $this
              ->add_current_day();
          }
          break;
        case 'YEARLY':
          if ($this
            ->set_year_day($day['day'], $day['direction_count'], $day['direction'])) {
            $this
              ->add_current_day();
          }
          break;
      }
    }
    $finished = $this
      ->is_finished();

    // Reset to beginning of period before jumping to next period.
    // Needed especially when working with values like 'last
    // Saturday' to be sure we don't skip months like February.
    $year = $this->current_day
      ->format('Y');
    $month = $this->current_day
      ->format('n');
    switch ($this->rrule['FREQ']) {
      case 'MONTHLY':
        date_date_set($this->current_day, $year, $month, 1);
        break;
      case 'YEARLY':
        date_date_set($this->current_day, $year, 1, 1);
        break;
    }

    // Jump to the next period.
    $this->current_day
      ->add($this->jump);
  }
}