File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ All notable changes to `period` will be documented in this file
55## 1.0.0 - 201X-XX-XX
66
77- initial release
8+
9+ ## 0.3.0 - 2018-11-30
10+
11+ - Add ` Period::contains `
12+
13+ ## 0.2.0 - 2018-11-27
14+
15+ - Initial dev release
Original file line number Diff line number Diff line change @@ -176,6 +176,19 @@ public function endsBefore(DateTimeInterface $date): bool
176176 return $ this ->end < $ date ;
177177 }
178178
179+ public function contains (DateTimeInterface $ date ): bool
180+ {
181+ if ($ date < $ this ->start ) {
182+ return false ;
183+ }
184+
185+ if ($ date > $ this ->end ) {
186+ return false ;
187+ }
188+
189+ return true ;
190+ }
191+
179192 public function equals (Period $ period ): bool
180193 {
181194 if ($ period ->start ->getTimestamp () !== $ this ->start ->getTimestamp ()) {
Original file line number Diff line number Diff line change 22
33namespace Spatie \Tests \Period ;
44
5+ use DateTimeImmutable ;
56use Spatie \Period \Period ;
67use PHPUnit \Framework \TestCase ;
78use Spatie \Period \PeriodCollection ;
@@ -120,4 +121,24 @@ public function it_can_determine_the_gaps_of_a_collection()
120121 $ this ->assertTrue ($ gaps [1 ]->equals (Period::make ('2018-01-16 ' , '2018-01-19 ' )));
121122 $ this ->assertTrue ($ gaps [2 ]->equals (Period::make ('2018-01-26 ' , '2018-01-29 ' )));
122123 }
124+
125+ /**
126+ * @test
127+ *
128+ * A [===============]
129+ * B |
130+ * C |
131+ * D |
132+ */
133+ public function it_can_determine_whether_a_period_has_a_date ()
134+ {
135+ $ period = Period::make ('2018-01-01 ' , '2018-01-31 ' );
136+
137+ $ this ->assertTrue ($ period ->contains (new DateTimeImmutable ('2018-01-01 ' )));
138+ $ this ->assertTrue ($ period ->contains (new DateTimeImmutable ('2018-01-31 ' )));
139+ $ this ->assertTrue ($ period ->contains (new DateTimeImmutable ('2018-01-10 ' )));
140+
141+ $ this ->assertFalse ($ period ->contains (new DateTimeImmutable ('2017-12-31 ' )));
142+ $ this ->assertFalse ($ period ->contains (new DateTimeImmutable ('2018-02-01 ' )));
143+ }
123144}
You can’t perform that action at this time.
0 commit comments