public function recursionHappensOn($ts) { $objTestDate = new sfDate($ts); $objStartDate = new sfDate($this->ts); // Current date is before the recurring event begins. if ($objTestDate->get() < $objStartDate->get()) { return false; } elseif (in_array($objTestDate->date(), $this->exceptions)) { return false; } switch ($this->event->CustomRecursionType) { // Daily case 1: return $this->event->DailyInterval ? ($ts - $this->ts) / self::DAY % $this->event->DailyInterval == 0 : false; break; // Weekly // Weekly case 2: return ($objTestDate->firstDayOfWeek()->get() - $objStartDate->firstDayOfWeek()->get()) / self::WEEK % $this->event->WeeklyInterval == 0 && in_array($objTestDate->reset()->format('w'), $this->allowedDaysOfWeek); break; // Monthly // Monthly case 3: if (self::difference_in_months($objTestDate, $objStartDate) % $this->event->MonthlyInterval == 0) { // A given set of dates in the month e.g. 2 and 15. if ($this->event->MonthlyRecursionType1 == 1) { return in_array($objTestDate->reset()->format('j'), $this->allowedDaysOfMonth); } elseif ($this->event->MonthlyRecursionType2 == 1) { // Last day of the month? if ($this->event->MonthlyIndex == 5) { $targetDate = $objTestDate->addMonth()->firstDayOfMonth()->previousDay($this->event->MonthlyDayOfWeek)->dump(); } else { $objTestDate->subtractMonth()->finalDayOfMonth(); for ($i = 0; $i < $this->event->MonthlyIndex; $i++) { $objTestDate->nextDay($this->event->MonthlyDayOfWeek)->dump(); } $targetDate = $objTestDate->dump(); } return $objTestDate->reset()->dump() == $targetDate; } } return false; } }
protected function getNavigationOptions() { $options = new DataObjectSet(); $counter = new sfDate($this->start_date->get()); $counter->subtractMonth(6); for ($i = 0; $i < 12; $i++) { $options->push(new ArrayData(array('Link' => $this->ShowMonthLink($counter->format('Ym')), 'Selected' => $this->start_date->format('Ym') == $counter->format('Ym') ? 'selected="selected"' : '', 'Month' => CalendarUtil::i18n_date('%B, %Y', $counter->get())))); $counter->addMonth(); } unset($counter); return $options; }
public function getNextRecurringEvents($event_obj, $datetime_obj, $limit = null) { $counter = new sfDate($datetime_obj->StartDate); if ($event = $datetime_obj->Event()->DateTimes()->First()) { $end_date = strtotime($event->EndDate); } else { $end_date = false; } $counter->tomorrow(); $dates = new DataObjectSet(); while ($dates->Count() != $this->OtherDatesCount) { // check the end date if ($end_date) { if ($end_date > 0 && $end_date <= $counter->get()) { break; } } if ($event_obj->recursionHappensOn($counter->get())) { $dates->push($this->newRecursionDateTime($datetime_obj, $counter->date())); } $counter->tomorrow(); } return $dates; }