From 3070428255b1e4f641b9a15707badc19761ccc3e Mon Sep 17 00:00:00 2001 From: Vlasta Neubauer Date: Mon, 16 Dec 2019 15:32:04 +0100 Subject: [PATCH] Add containsInterval() on all sets --- src/Math/Interval/FloatIntervalSet.php | 11 +++++++++++ src/Math/Interval/IntIntervalSet.php | 11 +++++++++++ src/Time/Interval/DateIntervalSet.php | 11 +++++++++++ src/Time/Interval/DateTimeIntervalSet.php | 11 +++++++++++ src/Time/Interval/DayOfYearIntervalSet.php | 11 +++++++++++ src/Time/Interval/NightIntervalSet.php | 11 +++++++++++ src/Time/Interval/TimeIntervalSet.php | 11 +++++++++++ src/Time/Interval/WeekDayHoursSet.php | 13 +++++++++++++ 8 files changed, 90 insertions(+) diff --git a/src/Math/Interval/FloatIntervalSet.php b/src/Math/Interval/FloatIntervalSet.php index 4eaa27ef..099acf53 100644 --- a/src/Math/Interval/FloatIntervalSet.php +++ b/src/Math/Interval/FloatIntervalSet.php @@ -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 === []) { diff --git a/src/Math/Interval/IntIntervalSet.php b/src/Math/Interval/IntIntervalSet.php index 7d174a74..804eec56 100644 --- a/src/Math/Interval/IntIntervalSet.php +++ b/src/Math/Interval/IntIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/DateIntervalSet.php b/src/Time/Interval/DateIntervalSet.php index 90142f82..29633dcb 100644 --- a/src/Time/Interval/DateIntervalSet.php +++ b/src/Time/Interval/DateIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/DateTimeIntervalSet.php b/src/Time/Interval/DateTimeIntervalSet.php index 3cec596d..5c45fdc1 100644 --- a/src/Time/Interval/DateTimeIntervalSet.php +++ b/src/Time/Interval/DateTimeIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/DayOfYearIntervalSet.php b/src/Time/Interval/DayOfYearIntervalSet.php index e9a9c2d0..82ca0a9e 100644 --- a/src/Time/Interval/DayOfYearIntervalSet.php +++ b/src/Time/Interval/DayOfYearIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/NightIntervalSet.php b/src/Time/Interval/NightIntervalSet.php index 03719889..d31c8e58 100644 --- a/src/Time/Interval/NightIntervalSet.php +++ b/src/Time/Interval/NightIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/TimeIntervalSet.php b/src/Time/Interval/TimeIntervalSet.php index c5f1326d..27a3d238 100644 --- a/src/Time/Interval/TimeIntervalSet.php +++ b/src/Time/Interval/TimeIntervalSet.php @@ -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 === []) { diff --git a/src/Time/Interval/WeekDayHoursSet.php b/src/Time/Interval/WeekDayHoursSet.php index 40472905..8c7eea3e 100644 --- a/src/Time/Interval/WeekDayHoursSet.php +++ b/src/Time/Interval/WeekDayHoursSet.php @@ -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; @@ -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[] */