From bdd2d6f8b245c986e60bd4b1a967d29e204f7bb3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 21 Jul 2016 10:03:37 +0200 Subject: [PATCH] Improved DateRange to check if both wrapped dates are empty --- module/Common/src/Util/DateRange.php | 8 ++++++++ module/Core/src/Repository/VisitRepository.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/module/Common/src/Util/DateRange.php b/module/Common/src/Util/DateRange.php index 8e156a20..c87f402a 100644 --- a/module/Common/src/Util/DateRange.php +++ b/module/Common/src/Util/DateRange.php @@ -33,4 +33,12 @@ class DateRange { return $this->endDate; } + + /** + * @return bool + */ + public function isEmpty() + { + return is_null($this->startDate) && is_null($this->endDate); + } } diff --git a/module/Core/src/Repository/VisitRepository.php b/module/Core/src/Repository/VisitRepository.php index 7b98c5d5..743427f6 100644 --- a/module/Core/src/Repository/VisitRepository.php +++ b/module/Core/src/Repository/VisitRepository.php @@ -29,7 +29,7 @@ class VisitRepository extends EntityRepository implements VisitRepositoryInterfa $shortUrl = $shortUrl instanceof ShortUrl ? $shortUrl : $this->getEntityManager()->find(ShortUrl::class, $shortUrl); - if (! isset($dateRange)) { + if (! isset($dateRange) || $dateRange->isEmpty()) { $startDate = $shortUrl->getDateCreated(); $endDate = clone $startDate; $endDate->add(new \DateInterval('P2D'));