wip: insurance booking
This commit is contained in:
@@ -35,6 +35,10 @@ class ServiceAgeEvaluator
|
||||
* constraint requirements. Returns false if the participant doesn't
|
||||
* meet the age requirements or if no birth date is provided.
|
||||
*
|
||||
* Age constraints are evaluated at the travel start date to ensure
|
||||
* that services are appropriately filtered based on the participant's
|
||||
* age at the time of travel, not their current age.
|
||||
*
|
||||
* @param Service $service The service to evaluate
|
||||
* @param BookingDtoInterface $bookingDto The booking containing participant data
|
||||
* @param int $participantIndex The index of the participant to evaluate
|
||||
@@ -49,26 +53,30 @@ class ServiceAgeEvaluator
|
||||
return false; // Cannot evaluate without birth date
|
||||
}
|
||||
|
||||
// Use travel start date as reference for absolute age calculations
|
||||
$travelStartDate = $bookingDto->travel->dateFrom;
|
||||
|
||||
return match ($service->ageConstraintType) {
|
||||
'absolute_age' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth),
|
||||
'absolute_age' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth, $travelStartDate),
|
||||
'birth_year' => $this->evaluateBirthYear($service, $participant->dateOfBirth),
|
||||
'mixed' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth)
|
||||
'mixed' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth, $travelStartDate)
|
||||
&& $this->evaluateBirthYear($service, $participant->dateOfBirth),
|
||||
default => true, // No constraints or unknown type
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates absolute age constraints against participant's current age.
|
||||
* Evaluates absolute age constraints against participant's age at travel date.
|
||||
*
|
||||
* @param Service $service The service with age constraints
|
||||
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
|
||||
* @param Service $service The service with age constraints
|
||||
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
|
||||
* @param \DateTimeImmutable|null $referenceDate The reference date for age calculation (travel start date)
|
||||
*
|
||||
* @return bool True if the participant meets the absolute age requirements
|
||||
*/
|
||||
private function evaluateAbsoluteAge(Service $service, \DateTimeImmutable $dateOfBirth): bool
|
||||
private function evaluateAbsoluteAge(Service $service, \DateTimeImmutable $dateOfBirth, ?\DateTimeImmutable $referenceDate = null): bool
|
||||
{
|
||||
$age = $this->calculateAge($dateOfBirth);
|
||||
$age = $this->calculateAge($dateOfBirth, $referenceDate);
|
||||
|
||||
if (null !== $service->ageFrom && $age < $service->ageFrom) {
|
||||
return false;
|
||||
@@ -105,20 +113,21 @@ class ServiceAgeEvaluator
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates age in years from a date of birth.
|
||||
* Calculates age in years from a date of birth at a reference date.
|
||||
*
|
||||
* Uses DateTimeImmutable to ensure accurate age calculations accounting
|
||||
* for leap years and exact birth date anniversaries.
|
||||
*
|
||||
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
|
||||
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
|
||||
* @param \DateTimeImmutable|null $referenceDate The reference date for age calculation (defaults to today)
|
||||
*
|
||||
* @return int The calculated age in complete years
|
||||
*/
|
||||
private function calculateAge(\DateTimeImmutable $dateOfBirth): int
|
||||
private function calculateAge(\DateTimeImmutable $dateOfBirth, ?\DateTimeImmutable $referenceDate = null): int
|
||||
{
|
||||
$today = new \DateTimeImmutable();
|
||||
$referenceDate = $referenceDate ?? new \DateTimeImmutable();
|
||||
|
||||
return $dateOfBirth->diff($today)->y;
|
||||
return $dateOfBirth->diff($referenceDate)->y;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user