Skip to content

Commit

Permalink
Ported 66d0bbd to EducationTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Oct 8, 2023
1 parent 034733b commit 3b6e26b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,6 @@ private function getCashbookId(int $skautisEducationId): CashbookId
return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($skautisEducationId)));
}

/** @param array<EducationTerm> $terms */
private function countDays(array $terms): int
{
$days = [];

foreach ($terms as $term) {
$date = $term->startDate;

while ($date->lessThanOrEquals($term->endDate)) {
$days[] = $date;
$date = $date->addDay();
}
}

return count(
array_unique(
$days,
),
);
}

/**
* @param array<T> $arr
*
Expand Down
11 changes: 3 additions & 8 deletions app/model/Event/EducationTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ public static function countTotalDays(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) {
while ($date->lessThanOrEquals($term->endDate)) {
$days[] = $date;
$date = $date->addDay();
$days[] = $date->__toString();
if ($date->eq($term->endDate)) {
break;
}
}
}

Expand Down

0 comments on commit 3b6e26b

Please sign in to comment.