Skip to content

Commit

Permalink
Fix for short format when older than 100 years (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusbe authored and frozzare committed Mar 5, 2018
1 parent 08ab0f0 commit 2ac438e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Personnummer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ protected static function getParts($str) {
$check = $match[7];

if (!in_array($sep, array('-', '+'))) {
$sep = '-';
if (empty($century) || date('Y') - intval(strval($century) . strval($year)) < 100) {
$sep = '-';
} else {
$sep = '+';
}
}

if (empty($century)) {
Expand Down
1 change: 1 addition & 0 deletions tests/PersonnummerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function testFormat()
$this->assertEquals('640823-3234', Personnummer::format('196408233234'));
$this->assertEquals('000101-0107', Personnummer::format('0001010107'));
$this->assertEquals('000101-0107', Personnummer::format('000101-0107'));
$this->assertEquals('130401+2931', Personnummer::format('191304012931'));

$this->assertEquals('196403273813', Personnummer::format(6403273813, true));
$this->assertEquals('195108189167', Personnummer::format('510818-9167', true));
Expand Down

0 comments on commit 2ac438e

Please sign in to comment.