From 3424ae43afd77184d7206cfabfa140757009d24e Mon Sep 17 00:00:00 2001 From: paranoiq Date: Wed, 17 Feb 2021 16:15:33 +0100 Subject: [PATCH] Add invert() on all interval sets --- src/Math/Interval/FloatIntervalSet.php | 5 +++++ src/Math/Interval/IntIntervalSet.php | 5 +++++ src/Time/Interval/DateIntervalSet.php | 5 +++++ src/Time/Interval/NightIntervalSet.php | 5 +++++ src/Time/Interval/TimeIntervalSet.php | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/src/Math/Interval/FloatIntervalSet.php b/src/Math/Interval/FloatIntervalSet.php index 7e9c5aed..60dd40c7 100644 --- a/src/Math/Interval/FloatIntervalSet.php +++ b/src/Math/Interval/FloatIntervalSet.php @@ -190,6 +190,11 @@ public function subtractIntervals(FloatInterval ...$intervals): self return new static($results); } + public function invert(): self + { + return (new static([FloatInterval::all()]))->subtract($this); + } + /** * Intersect with another set of intervals. * @param self $set diff --git a/src/Math/Interval/IntIntervalSet.php b/src/Math/Interval/IntIntervalSet.php index b4940166..0bfefd88 100644 --- a/src/Math/Interval/IntIntervalSet.php +++ b/src/Math/Interval/IntIntervalSet.php @@ -190,6 +190,11 @@ public function subtractIntervals(IntInterval ...$intervals): self return new static($results); } + public function invert(): self + { + return (new static([IntInterval::all()]))->subtract($this); + } + /** * Intersect with another set of intervals. * @param self $set diff --git a/src/Time/Interval/DateIntervalSet.php b/src/Time/Interval/DateIntervalSet.php index 4290c497..c3ce1176 100644 --- a/src/Time/Interval/DateIntervalSet.php +++ b/src/Time/Interval/DateIntervalSet.php @@ -249,6 +249,11 @@ public function subtractIntervals(DateInterval ...$intervals): self return new static($results); } + public function invert(): self + { + return (new static([DateInterval::all()]))->subtract($this); + } + /** * Intersect with another set of intervals. * @param self $set diff --git a/src/Time/Interval/NightIntervalSet.php b/src/Time/Interval/NightIntervalSet.php index 75e9a00e..2a87afe6 100644 --- a/src/Time/Interval/NightIntervalSet.php +++ b/src/Time/Interval/NightIntervalSet.php @@ -258,6 +258,11 @@ public function subtractIntervals(NightInterval ...$intervals): self return new static($results); } + public function invert(): self + { + return (new static([NightInterval::all()]))->subtract($this); + } + /** * Intersect with another set of intervals. * @param self $set diff --git a/src/Time/Interval/TimeIntervalSet.php b/src/Time/Interval/TimeIntervalSet.php index a4be2245..0870ec62 100644 --- a/src/Time/Interval/TimeIntervalSet.php +++ b/src/Time/Interval/TimeIntervalSet.php @@ -208,6 +208,11 @@ public function subtractIntervals(TimeInterval ...$intervals): self return new static($results); } + public function invert(): self + { + return (new static([TimeInterval::all()]))->subtract($this); + } + /** * Intersect with another set of intervals. * @param self $set