File tree Expand file tree Collapse file tree 4 files changed +113
-1
lines changed
Expand file tree Collapse file tree 4 files changed +113
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This file is part of Zee Project.
4+ *
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ *
8+ * @see https://github.com/zee/
9+ */
10+
11+ namespace Zee \DateRange ;
12+
13+ /**
14+ * Date range provider.
15+ *
16+ * Interface for builders for predefined ranges.
17+ */
18+ interface DateRangeProvider
19+ {
20+ public function getDateRange (): DateRangeInterface ;
21+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This file is part of Zee Project.
4+ *
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ *
8+ * @see https://github.com/zee/
9+ */
10+
11+ namespace Zee \DateRange \Providers ;
12+
13+ use DateTimeInterface ;
14+ use Zee \DateRange \DateRange ;
15+ use Zee \DateRange \DateRangeInterface ;
16+ use Zee \DateRange \DateRangeProvider ;
17+
18+ /**
19+ * Finite date range provider.
20+ */
21+ final class FiniteDateRangeProvider implements DateRangeProvider
22+ {
23+ /**
24+ * @var DateTimeInterface
25+ */
26+ private $ startDate ;
27+
28+ /**
29+ * @var DateTimeInterface
30+ */
31+ private $ endDate ;
32+
33+ /**
34+ * @param DateTimeInterface $startDate
35+ * @param DateTimeInterface $endDate
36+ */
37+ public function __construct (DateTimeInterface $ startDate , DateTimeInterface $ endDate )
38+ {
39+ $ this ->startDate = $ startDate ;
40+ $ this ->endDate = $ endDate ;
41+ }
42+
43+ /**
44+ * {@inheritdoc}
45+ */
46+ public function getDateRange (): DateRangeInterface
47+ {
48+ return new DateRange ($ this ->startDate , $ this ->endDate );
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This file is part of Zee Project.
4+ *
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ *
8+ * @see https://github.com/zee/
9+ */
10+
11+ namespace Zee \DateRange ;
12+
13+ use DateTimeImmutable ;
14+ use PHPUnit \Framework \TestCase ;
15+ use Zee \DateRange \Providers \FiniteDateRangeProvider ;
16+
17+ /**
18+ * Class DateRangeProviderTest.
19+ */
20+ final class DateRangeProviderTest extends TestCase
21+ {
22+ /**
23+ * @test
24+ */
25+ public function usingBuilder ()
26+ {
27+ $ yesterday = new DateTimeImmutable ('-1 day ' );
28+ $ tomorrow = new DateTimeImmutable ('+1 day ' );
29+ $ calculator = function (FiniteDateRangeProvider $ dateRangeProvider ) {
30+ $ range = $ dateRangeProvider ->getDateRange ();
31+ $ interval = $ range ->getDateInterval ();
32+
33+ return $ interval ->days ;
34+ };
35+
36+ $ dateRangeProvider = new FiniteDateRangeProvider ($ yesterday , $ tomorrow );
37+ $ result = $ calculator ($ dateRangeProvider );
38+
39+ self ::assertSame (2 , $ result );
40+ }
41+ }
Original file line number Diff line number Diff line change 1717/**
1818 * Class DateRangeTest.
1919 */
20- class DateRangeTest extends TestCase
20+ final class DateRangeTest extends TestCase
2121{
2222 /**
2323 * @test
You can’t perform that action at this time.
0 commit comments