arthurdejong / python-stdnum

A Python library to provide functions to handle, parse and validate standard numbers.
https://arthurdejong.org/python-stdnum/
GNU Lesser General Public License v2.1
498 stars 206 forks source link

Swedish personnummer are not handled correctly for centenarians #156

Closed Tjoppen closed 4 years ago

Tjoppen commented 5 years ago

For people aged 100 and up, the minus/dash in the personnummer is changed to a plus, on new year's eve the year they turn 100. See Folkbokföringslagen (1991:481), §18.

For example, 121212-1212 refers to a person born 2012-12-12, whereas 121212+1212 refers to someone born 1912-12-12. One has to be careful however, since YY > current_year % 100 means the person is another 100 years old. For example, 400606+XXXX would refer to Johanna Charlotta Johansson, born 1840-06-06, died 1947-11-02. This will remain the lowest personnummer in Sweden's records until 2040.

Some other useful notes:

Simply stripping + and - as the code does right now in compact() is not correct. format() is similarly incorrect.

One simple fix is to use the same logic as in formator.js (https://github.com/jop-io/formator.js)

arthurdejong commented 4 years ago

Thanks for the clear explanation and the fix. I've merged the change in5441f.

Tjoppen commented 4 years ago

Great!