Skip to content

Commit

Permalink
Simplified education term day counting
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Oct 8, 2023
1 parent 1434f7c commit 66d0bbd
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
Expand Down

0 comments on commit 66d0bbd

Please sign in to comment.