public function testDateInterval31() { $date_begins = '2016-08-01'; $date_end = '2016-12-31'; $interval_unit = 'D'; $interval_num = 31; if (!isset($DateInterval)) { $DateInterval = new \Rundiz\DateInterval\DateInterval(); $DateInterval->date_begins = $date_begins; $DateInterval->date_end = $date_end; $DateInterval->setInterval($interval_num, $interval_unit); } $list_dates = $DateInterval->getTheDates(); $expected_results = array('2016-08-01', '2016-09-01', '2016-10-02', '2016-11-02', '2016-12-03'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated date interval does not match the expected results. %s', var_export($list_dates, true))); unset($expected_results, $list_dates); $date_start = '2016-09-01'; $date_stop = '2016-11-30'; $list_dates = $DateInterval->getTheDates($date_start, $date_stop); $expected_results = array('2016-09-01', '2016-10-02', '2016-11-02'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated date interval does not match the expected results. %s', var_export($list_dates, true))); unset($date_start, $date_stop, $expected_results, $list_dates); $date_start = '2016-10-01'; $date_stop = '2016-11-30'; $list_dates = $DateInterval->getTheDates($date_start, $date_stop); $expected_results = array('2016-10-02', '2016-11-02'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated date interval does not match the expected results. %s', var_export($list_dates, true))); unset($date_start, $date_stop, $expected_results, $list_dates); unset($date_begins, $date_end, $DateInterval, $interval_num, $interval_unit); }
public function testYearInterval5() { $date_begins = '1974-06-01'; $date_end = '2016-12-31'; $interval_unit = 'Y'; $interval_num = 5; if (!isset($DateInterval)) { $DateInterval = new \Rundiz\DateInterval\DateInterval(); $DateInterval->date_begins = $date_begins; $DateInterval->date_end = $date_end; $DateInterval->setInterval($interval_num, $interval_unit); } $list_dates = $DateInterval->getTheDates(); $expected_results = array('1974-06-01', '1979-06-01', '1984-06-01', '1989-06-01', '1994-06-01', '1999-06-01', '2004-06-01', '2009-06-01', '2014-06-01'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated year interval does not match the expected results. %s', var_export($list_dates, true))); unset($expected_results, $list_dates); $date_start = '1977-06-01'; $date_stop = '2016-11-30'; $list_dates = $DateInterval->getTheDates($date_start, $date_stop); $expected_results = array('1979-06-01', '1984-06-01', '1989-06-01', '1994-06-01', '1999-06-01', '2004-06-01', '2009-06-01', '2014-06-01'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated year interval does not match the expected results. %s', var_export($list_dates, true))); unset($date_start, $date_stop, $expected_results, $list_dates); $date_start = '1979-06-01'; $date_stop = '2016-11-30'; $list_dates = $DateInterval->getTheDates($date_start, $date_stop); $expected_results = array('1979-06-01', '1984-06-01', '1989-06-01', '1994-06-01', '1999-06-01', '2004-06-01', '2009-06-01', '2014-06-01'); $this->assertArraySubset($expected_results, $list_dates, '', sprintf('Generated year interval does not match the expected results. %s', var_export($list_dates, true))); unset($date_start, $date_stop, $expected_results, $list_dates); unset($date_begins, $date_end, $DateInterval, $interval_num, $interval_unit); }
// end functions for use in this page. ------------------------------------------------------------------------------------- $date_begins = date('Y-04-01'); $date_end = date('Y-12-31'); $interval_num = 3; $interval_unit = 'W'; echo 'begins date: ' . $date_begins . ' end date: ' . $date_end . '<br>' . "\n"; echo 'interval: ' . $interval_num . ' ' . $interval_unit . ' (D = days, W = weeks, M = months, Y = years)<br>' . "\n"; echo '<hr>' . "\n\n"; $okvdint = new \Rundiz\DateInterval\DateInterval(); $okvdint->date_begins = $date_begins; $okvdint->date_end = $date_end; $okvdint->setInterval($interval_num, $interval_unit); // list all dates from begins to end. --------------------------------------------------------------------------------------- echo '<div style="float:left; margin-right: 20px; width: 300px;">' . "\n"; echo 'start list dates from begins until end.<br>' . "\n"; $list_dates = $okvdint->getTheDates(); listDates($list_dates); unset($list_dates); echo '</div>' . "\n"; // set start displaying date and stop displaying date 1 and list all dates from start within interval range. ---------- $date_start = date('Y-06-01'); $date_stop = date('Y-11-30'); $list_dates = $okvdint->getTheDates($date_start, $date_stop); echo '<div style="float:left; margin-right: 20px; width: 430px;">' . "\n"; echo 'list start date (' . $date_start . ') until stop date (' . $date_stop . ').<br>' . "\n"; listDates($list_dates); unset($list_dates); echo '</div>' . "\n"; // set start displaying date and stop displaying date 2 and list all dates from start within interval range. ---------- $date_start = date('Y-08-01'); $date_stop = date('Y-12-30');