/** * 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; }); }
public function testFindNthWeekdayInMonth() { //Returns the right object $day, $offset, $reverse = false $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertInstanceOf('DateTime', $this->object->findNthWeekdayInMonth(3, 2)); //Second Wednesday in Nov 2011 $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertEquals(1320796800, $this->object->findNthWeekdayInMonth(3, 2)->getTimestamp(), 'wrong algorithm'); //First Tuesday in Nov 2011 $this->assertEquals(1320105600, $this->object->findNthWeekdayInMonth(2, 1)->getTimestamp(), 'wrong algorithm'); //Second Wednesday in Nov 2011 Reverse $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertEquals(1321488000, $this->object->findNthWeekdayInMonth(4, 2, true)->getTimestamp(), 'wrong algorithm'); //Last Wednesday in Nov 2011 $this->object = new Application_Model_ReoccurenceTemplate("2011-11-01"); $this->assertEquals(1322611200, $this->object->findNthWeekdayInMonth(3, 1, true)->getTimestamp(), 'wrong algorithm'); //Fifth Monday in Feb 2011 $this->object = new Application_Model_ReoccurenceTemplate("2011-02-01"); $this->assertFalse($this->object->findNthWeekdayInMonth(1, 5), 'wrong algorithm'); }
/** * Retrives generated date entries for specific year and month * * @param type $year Requested year * @param type $month Requested month * @return array */ public function getEntries($year, $month) { $this->_rendered_dates = array(); if (is_array($this->_monthly_pattern) && in_array($month, $this->_monthly_pattern) || $this->_monthly_pattern == NULL) { if ($this->_monthly_day_pattern !== NULL) { $this->_rendered_dates[] = $this->_getMonthlyDayPatternEntries($year, $month); } if (is_array($this->_weekday_pattern)) { foreach ($this->_weekday_pattern as $weekday_pattern) { $rt = new Application_Model_ReoccurenceTemplate("{$year}-{$month}-01"); //@TODO: modify if there would be a need for instance far ALL MONDAYS AND TUESDAYS within a month $rendered_date = $rt->findNthWeekdayInMonth($weekday_pattern, $this->_weekday_pattern_offset); $this->_rendered_dates[] = $rendered_date; } } } return $this->_rendered_dates; }