diff --git a/src/DateRange.php b/src/DateRange.php index 2a66ddf..849e6a4 100644 --- a/src/DateRange.php +++ b/src/DateRange.php @@ -193,9 +193,9 @@ public function subtract($b) } if ( - ($b->from && $this->includes($b->from)) + ($b->from && $this->from != $b->from && $this->includes($b->from)) || - ($this->to && $b->includes($this->to)) + ($this->to && $this->to != $b->to && $b->includes($this->to)) ) { $from = $this->from; $to = (clone $b->from)->modify('-1 day'); diff --git a/tests/DateRange/Subtract.phpt b/tests/DateRange/Subtract.phpt index e947258..c03c6f4 100644 --- a/tests/DateRange/Subtract.phpt +++ b/tests/DateRange/Subtract.phpt @@ -8,6 +8,7 @@ $range2 = \Danoha\DateRange::wrap([NULL, new \DateTime('2017-12-01'),]); $range3 = \Danoha\DateRange::wrap([new \DateTime('2017-01-01'), NULL,]); $range4 = \Danoha\DateRange::wrap([new \DateTime('2016-06-01'), new \DateTime('2017-05-31'),]); $range5 = \Danoha\DateRange::wrap([new \DateTime('2017-06-01'), new \DateTime('2018-05-31'),]); +$range6 = \Danoha\DateRange::wrap([new \DateTime('2017-01-01'), new \DateTime('2017-05-31'),]); Assert::equal([ ['from' => new \DateTime('2017-12-02'), 'to' => NULL,], @@ -34,4 +35,8 @@ Assert::same([], $range1->subtract($range1)->unwrap()); Assert::equal([ ['from' => new \DateTime('2016-06-01'), 'to' => new \DateTime('2017-05-31'),], -], $range4->subtract($range5)->unwrap()); \ No newline at end of file +], $range4->subtract($range5)->unwrap()); + +Assert::equal([ + ['from' => new \DateTime('2017-06-01'), 'to' => NULL,], +], $range3->subtract($range6)->unwrap()); \ No newline at end of file