Skip to content

Commit

Permalink
Add containsInterval() on all sets
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Dec 16, 2019
1 parent a1054d7 commit 3070428
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Math/Interval/FloatIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public function containsValue(float $value): bool
return false;
}

public function containsInterval(FloatInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): FloatInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Math/Interval/IntIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public function containsValue(int $value): bool
return false;
}

public function containsInterval(IntInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): IntInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Time/Interval/DateIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ public function containsValue(Date $value): bool
return false;
}

public function containsInterval(DateInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): DateInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Time/Interval/DateTimeIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ public function containsValue(DateTime $value): bool
return false;
}

public function containsInterval(DateTimeInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): DateTimeInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Time/Interval/DayOfYearIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ public function containsValue(DayOfYear $value): bool
return false;
}

public function containsInterval(DayOfYearInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): DayOfYearInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Time/Interval/NightIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ public function containsValue(Date $value): bool
return false;
}

public function containsInterval(NightInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): NightInterval
{
if ($this->intervals === []) {
Expand Down
11 changes: 11 additions & 0 deletions src/Time/Interval/TimeIntervalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public function containsValue(Time $value): bool
return false;
}

public function containsInterval(TimeInterval $interval): bool
{
foreach ($this->intervals as $int) {
if ($int->contains($interval)) {
return true;
}
}

return false;
}

public function envelope(): TimeInterval
{
if ($this->intervals === []) {
Expand Down
13 changes: 13 additions & 0 deletions src/Time/Interval/WeekDayHoursSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Dogma\Pokeable;
use Dogma\StrictBehaviorMixin;
use Dogma\Time\DateTime;
use Dogma\Time\DayOfWeek;
use Dogma\Time\DaysOfWeek;
use Dogma\Time\InvalidWeekDayHoursSetException;
Expand Down Expand Up @@ -57,6 +58,18 @@ public function poke(): void
}
}

public function containsValue(DateTime $dateTime): bool
{
$date = $dateTime->getDate();

return DateTimeIntervalSet::createFromDateIntervalAndWeekDayHoursSet(new DateInterval($date, $date), $this)->containsValue($dateTime);
}

public function containsInterval(DateTimeInterval $interval): bool
{
return DateTimeIntervalSet::createFromDateIntervalAndWeekDayHoursSet($interval->toDateInterval(), $this)->containsInterval($interval);
}

/**
* @return \Dogma\Time\Interval\WeekDayHours[]
*/
Expand Down

0 comments on commit 3070428

Please sign in to comment.