personnummer / js

Validate Swedish personal identity numbers
https://www.npmjs.com/package/personnummer
MIT License
51 stars 9 forks source link

[BUG] - Wrong century when older than 100 years is parsing #722

Closed fredrikmork closed 2 months ago

fredrikmork commented 2 months ago

Context and Results

OS is macOS Sonoma 14.5 VS Code version 1.92.0

I am expecting personnummer above 100 years to have correct century and date when invoking Personnummer.parse(number).getDate()and Personnummer.parse(number).century.

I am using the swedish personnummer generator to generate a personnummer that is above 100 years. When I am parsing Personnummer.parse('2005281528').getDate() i get the year 2020 instead of 1920.

Disclaimer: I dont know if these numbers are correct from "tedeh.com" when above 100 years.

Skjermbilde 2024-08-06 kl  11 53 45

Test case

Example on codeSandbox

Skjermbilde 2024-08-13 kl  09 52 18
Johannestegner commented 2 months ago

Hi!

When using an input without either separator (+/-) or century, the code have to guess, and we have decided to take the closest century in the parser.

So to be able to get the age/date of birth with accuracy, you would either have to use the long format (192005281528) or use a separator (200528+1528), where the separator version is the actual personnummer standard.

fredrikmork commented 2 months ago

Hi! Ok, thanks for the quick response 🙏