Example #1
0
 /**
  * Compute dates that match the requested rule, within a specified
  * date range.
  *
  * @param string $rrule
  *   A string RRULE, in the standard iCal format.
  * @param object $start
  *   A date object to start the series.
  * @param object $end
  *   A date object to end the series, if not ended earlier by UNTIL
  *   or COUNT. Requred unless a COUNT is provided.
  * @param array $this->exceptions
  *   Optional array of exception dates, each in the standard ISO format
  *   of YYYY-MM-DD.
  * @param array $additions
  *   Optional array of additional dates, each in the standard ISO format
  *   of YYYY-MM-DD.
  */
 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;
 }