Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Core/Europe/Finland/FinlandCitizenInformationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
14 changes: 13 additions & 1 deletion tests/Feature/Europe/FinlandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down