<?php ## if you run demo, `make demo` in root dir. require __DIR__ . '/../tests/bootstrap.php'; use Brtriver\DateRange\DateRange; ## two args version $range = new DateRange('2015-12-01', '2015-12-31'); // array version $range = new DateRange(['2015-12-01', '2015-12-31']); // DateTime is OK $start = new DateTime('2012-12-01'); $end = new DateTime('2012-12-31'); $range = new DateRange([$start, $end]); ## check contains that date var_dump($range->contains('2015-12-10')); // bool(true) var_dump($range->contains('2017-01-10')); // bool(false) ## get DatePeriod for loop foreach ($range as $d) { echo $d->format('Y-m-d') . PHP_EOL; } ## or foreach ($range->getDatePeriod() as $d) { echo $d->format('Y-m-d') . PHP_EOL; } // 2015-12-01 // 2015-12-02 // 2015-12-03 // 2015-12-04 // ...
/** @test */ public function excludeEndDate() { $range = new DateRange([$this->start, $this->end]); $range->excludeEndDate(); $this->assertFalse($range->contains('2015-12-31')); $this->assertTrue($range->contains('2015-12-30')); $last = null; // dirty test.. (check the last value only) foreach ($range as $d) { $last = $d; } $this->assertEquals(new DateTime('2015-12-30'), $last); }