public function testFindNthDayOfMonth() { //Returns the right object $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertInstanceOf('DateTime', $this->object->findNthDayOfMonth(1)); //First day of Nov 2011 $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertEquals(1320192000, $this->object->findNthDayOfMonth(2)->getTimestamp()); //Last day of Nov 2011 $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertEquals(1322611200, $this->object->findNthDayOfMonth(-1)->getTimestamp()); }
/** * Constructor */ public function __construct() { $this->_setName('Fundraiser'); $this->_setReoccurent(true); $this->_setMonthlyPattern(array(2, 8)); $this->_setMonthlyDayPattern(-1); $this->_setMonthlyExceptionCallback(function ($rendered_date) { if ($rendered_date->isWeekDay()) { $result = $rendered_date; } else { $alt_date = new Application_Model_ReoccurenceTemplate($rendered_date->format('Y-m-01')); $result = $alt_date->findNthWeekdayInMonth(3, 1, true); } return $result; }); }
/** * Monthly day pattern entries getter * * @param integer $year * @param integer $month * @return Application_Model_AppDateTime */ private function _getMonthlyDayPatternEntries($year, $month) { $rt = new Application_Model_ReoccurenceTemplate("{$year}-{$month}-01"); $rendered_date = $rt->findNthDayOfMonth($this->_monthly_day_pattern); if ($this->_monthly_exception_callback) { $callback = $this->_monthly_exception_callback; $rendered_date = $callback($rendered_date); } return $rendered_date; }