diff --git a/src/Core/Europe/Finland/FinlandCitizenInformationExtractor.php b/src/Core/Europe/Finland/FinlandCitizenInformationExtractor.php index 9b92a87..495ad06 100644 --- a/src/Core/Europe/Finland/FinlandCitizenInformationExtractor.php +++ b/src/Core/Europe/Finland/FinlandCitizenInformationExtractor.php @@ -37,15 +37,17 @@ private function getDateOfBirth(string $id): DateTime $dateDigits = substr($id, 0, 6); [$day, $month, $year] = str_split($dateDigits, 2); - $century = $id[6]; + $separator = $id[6]; - $year += match ($century) { + $century = match ($separator) { '+' => 1800, - '-' => 1900, - 'A' => 2000, - default => throw new InvalidArgumentException("Unrecognised character $century in ID."), + '-', 'Y', 'X', 'W', 'V', 'U' => 1900, + 'A', 'B', 'C', 'D', 'E', 'F' => 2000, + default => throw new InvalidArgumentException("Unrecognised character $separator in ID."), }; + $year += $century; + return new DateTime("$year-$month-$day"); } } diff --git a/tests/Feature/Europe/FinlandTest.php b/tests/Feature/Europe/FinlandTest.php index b13e1a0..e895c27 100644 --- a/tests/Feature/Europe/FinlandTest.php +++ b/tests/Feature/Europe/FinlandTest.php @@ -47,7 +47,19 @@ protected function setUp(): void 'gender' => Gender::Male, 'dob' => new DateTime('2003-04-04'), 'age' => $this->calculateAge(new DateTime('2003-04-04')), - ] + ], + 'enni' => [ + 'hetu' => '250581X948M', + 'gender' => Gender::Female, + 'dob' => new DateTime('1981-05-25'), + 'age' => $this->calculateAge(new DateTime('1981-05-25')), + ], + 'kalle' => [ + 'hetu' => '311005F9511', + 'gender' => Gender::Male, + 'dob' => new DateTime('2005-10-31'), + 'age' => $this->calculateAge(new DateTime('2005-10-31')), + ], ]; $this->invalidIds = [