/** @test */
 public function getDatePeriod()
 {
     $range = new DateRange([$this->start, $this->end]);
     $periodEnd = clone $this->end;
     $periodEnd->modify('+1 sec');
     $expected = new DatePeriod($this->start, new DateInterval('P1D'), $periodEnd);
     $this->assertEquals($expected, $range->getDatePeriod());
 }
Exemple #2
0
// 2015-12-01
// 2015-12-02
// 2015-12-03
// 2015-12-04
// ...
// 2015-12-28
// 2015-12-29
// 2015-12-30
// 2015-12-31
## if you want to change interval, use setInterval()
$start = new DateTime('2012-12-01');
$end = new DateTime('2020-12-31');
$range = new DateRange([$start, $end]);
$range->setInterval(new DateInterval('P1Y'));
// change from 'P1D' (Default)
foreach ($range->getDatePeriod() as $d) {
    echo $d->format('Y-m-d') . PHP_EOL;
}
// 2012-12-01
// 2013-12-01
// 2014-12-01
// 2015-12-01
// 2016-12-01
// 2017-12-01
// 2018-12-01
// 2019-12-01
// 2020-12-01
## try - catch
try {
    $range = new DateRange(['tomorrow', 'today']);
} catch (\InvalidArgumentException $e) {