/** * @see sfValidatorBase */ protected function doClean($values) { // Convert to Timestamps foreach ($values as &$value) { if (!is_numeric($value)) { $value = strtotime($value); } } // Exclusive Or == Awesome if ($this->getOption('does_occur') ^ cfitScheduler::overlapsRange($values['range_start'], $values['range_end'], $values['item_start'], $values['item_end'])) { throw new sfValidatorError($this, 'invalid', array('range' => $this->formatDateRange($values['range_start'], $values['range_end']), 'item' => $this->formatDateRange($values['item_start'], $values['item_end']), 'does_occur' => $this->getOption('does_occur') ? 'must' : 'cannot')); } return $values; }
public function calculateWeeks() { $weeks = $this->getOption('add_empty') ? array(null => $this->getOption('add_empty') === true ? '' : $this->getOption('add_empty')) : array(); $start = cfitScheduler::calculateNextWeekday($this->getOption('starts_on'), strtotime($this->getOption('start_date'))); if ($this->getOption('display_end')) { $diff = (7 + date('w', strtotime($this->getOption('ends_on'))) - date('w', strtotime($this->getOption('starts_on')))) % 7; } $ends = $this->getOption('end_date') ? strtotime($this->getOption('end_date')) : strtotime('+52 weeks', $start); while ($start < $ends) { $index = $this->getIndex($start); // timestamp from ISO week date format $weeks[$index] = date($this->getOption('display_format'), $start); if ($this->getOption('display_end')) { $weeks[$index] .= ' - ' . date($this->getOption('display_format'), strtotime("+{$diff} days", $start)); } $start = strtotime("+1 weeks", $start); } return $weeks; }