You are here

function DateRRuleCalc::__construct in Date 8

Compute dates that match the requested rule, within a specified date range.

Parameters

string $rrule: A string RRULE, in the standard iCal format.

object $start: A date object to start the series.

object $end: A date object to end the series, if not ended earlier by UNTIL or COUNT. Requred unless a COUNT is provided.

array $this->exceptions: Optional array of exception dates, each in the standard ISO format of YYYY-MM-DD.

array $additions: Optional array of additional dates, each in the standard ISO format of YYYY-MM-DD.

File

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

Class

DateRRuleCalc

Namespace

Drupal\date_repeat

Code

function __construct($rrule, $start, $end = NULL, $exceptions = array(), $additions = array()) {

  // Get the parsed array of rule values.
  $this->rrule = DateiCalParse::parse_rrule($rrule);

  // Create a date object for the start and end dates, if valid.
  $this->start_date = $start;
  $this->end_date = $end;
  $this->timezone_name = $this->start_date
    ->getTimezone()
    ->getName();

  // Make sure we have something we can work with.
  if (!$this
    ->isValid()) {
    return FALSE;
  }

  // If the rule has an UNTIL, see if that is earlier than the end date.
  if (!empty($this->rrule['UNTIL'])) {
    $until_date = DateiCalParse::ical_date($this->rrule['UNTIL'], $this->timezone_name);
    if (empty($this->end_date) || $until_date < $this->end_date) {
      $this->end_date = $until_date;
    }
  }

  // Versions of PHP greater than PHP 5.3.5 require that we set an
  // explicit time when using date_modify() or the time may not match
  // the original value. Adding this modifier gives us the same
  // results in both older and newer versions of PHP.
  $this->time_string = ' ' . $this->start_date
    ->format('g:ia');
  $this->max_count = isset($this->rrule['COUNT']) ? $this->rrule['COUNT'] : NULL;
  $this->exceptions = $exceptions;
  $this->additions = $additions;
}