From 66d0bbd6daaeaa59d41a16483dd1d0d37022a8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sun, 8 Oct 2023 21:25:44 +0200 Subject: [PATCH] Simplified education term day counting --- .../presenters/EducationPresenter.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php index 82f2c100a..6eae9b9ea 100644 --- a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php @@ -112,27 +112,17 @@ private function countDays(array $terms): int $days = []; foreach ($terms as $term) { - $date = $term->startDate; - $days[] = $date; + $date = $term->startDate; - // Could be while(true), but don't want to risk infinite loop - for ($i = 0; $i < 50; ++$i) { - $date = $date->addDay(); + while($date->lessThanOrEquals($term->endDate)) { $days[] = $date; - if ($date->eq($term->endDate)) { - break; - } + $date = $date->addDay(); } } return count( array_unique( - array_map( - static function ($date) { - return $date->__toString(); - }, - $days, - ), + $days, ), ); }