/** * checks and sets the number of invoices that should have * been generated until $today * * @param sfDate the date until the function checks * @return void **/ public function checkMustOccurrences(sfDate $today = null) { if (!$today) { $today = new sfDate(); } $starting_date = new sfDate($this->getStartingDate()); $finishing_date = new sfDate($this->getFinishingDate()); if ($today->cmp($starting_date) > 0) { // check only until the finishing_date, or until today if finishing_date has not yet come $check_date = $today->cmp($finishing_date) > 0 ? $finishing_date : $today; switch ($this->getPeriodType()) { case 'year': $unit = sfTime::YEAR; break; case 'month': $unit = sfTime::MONTH; break; case 'week': $unit = sfTime::WEEK; break; case 'day': $unit = sfTime::DAY; break; } $difference = $check_date->diff($starting_date, $unit); $must_occurrences = floor($difference / $this->getPeriod()) + 1; // if there is a max_occurrences set and is greater, then set this as the must occurrences if ($this->getMaxOccurrences() && $must_occurrences > $this->getMaxOccurrences()) { $must_occurrences = $this->getMaxOccurrences(); } $this->setMustOccurrences($must_occurrences); } else { $this->setMustOccurrences(0); } }
/** * Gets the difference of two date values in sfTime::YEAR * * @param $other mixed timestamp, string, or sfDate object * @return int the difference in the unit * @author Enrique Martinez <*****@*****.**> **/ public function diffYear($other) { $other_date = self::getInstance($other); $diff = $this->getYear() - $other_date->getYear(); $date_compare = new sfDate($other_date); $date_compare->addYear($diff); if ($diff > 0 && $date_compare->cmp($this) > 0) { $diff--; } if ($diff < 0 && $date_compare->cmp($this) < 0) { $diff++; } return $diff; }