olssonm / identity-number

Validator for Swedish personal identity numbers (personnummer). For use "standalone" or with Laravel.
MIT License
17 stars 2 forks source link

Incorrectly adds 19 to all PIN #25

Closed danielstalenbring closed 3 years ago

danielstalenbring commented 3 years ago

The IdentityNumberFormatter adds 19 before all 10 number PINs, meaning if you're born in 2002, it would mistakenly be formatted as 1902. This only applies if you provide a 10 digit PIN and want it formatted as 12 digits.

olssonm commented 3 years ago

@danielstalenbring – Yes, completely true. You're right that that's a bad assumption nowadays. Will look into a fix.

olssonm commented 3 years ago

@danielstalenbring I've looked into the issue; and sadly you can never extract the century from a 10-digit number, unless you have the correct hyphen to start with ("-" = younger than 100 years, "+" = older than 100 years). The Luhn-algorithm/sum check only looks at the 10 digit variant.

The only "improvement" we can do here is to assume that the user is always under 100 years old if no hyphen is supplied.

danielstalenbring commented 3 years ago

Agree, it's a tricky situation. But I guess you have to assume that the correct hyphen is used, even though most people don't know about + :)

olssonm commented 3 years ago

It was time for a rewrite anyway 🙂, released a new package; olssonm/swedish-entity that will replace this one.

Please look into it – should solve your issue here too.