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

Add get_birth_date to no.fodselsnummer #187

Closed lemonsaurus closed 4 years ago

lemonsaurus commented 4 years ago

This PR adds the ability to get the birth date from a Norwegian fødselsnummer, and also makes minor changes to the Swedish and Danish personal identity numbers (which share many similarities) in order to improve consistency between these three files.

This has the side effect of making validation of all three of these personal identity numbers stricter than it was before, because the validator will now check that the birth date is valid. This appears to be a fairly established convention in the repository already, and makes the validator far more precise.

Changes

arthurdejong commented 4 years ago

Hi Leon, Thanks for providing this PR. Here are a few points for improvement:

lemonsaurus commented 4 years ago

Can you explain why the numbers in test_no_fodselsnummer.doctest that were found online (they should have been real numbers at the time) are no longer valid?

They cannot have been real numbers. The dates from these numbers were invalid. That is to say, they could have been otherwise valid numbers with impossible birthdates, but such a fødselsnummer would never be assigned a person in Norway. Technically valid isn't as useful as valid.

They did not fail previously because the is_valid check did not check birthdates until this PR.

I'll make the requested changes ASAP, didn't realize I needed to ensure compatibility with Python 2, my bad.

lemonsaurus commented 4 years ago

Oops, my apologies for the multiple force pushes messing up this PR, thought I had a branch checked out.

lemonsaurus commented 4 years ago

@arthurdejong I think I've addressed your feedback now. If I've forgotten or misunderstood something, let me know and I'll get it sorted out.

arthurdejong commented 4 years ago

Hi @lemonsaurus, I've merged your changes as f5e0456, 4500881 and df9f922. I only made some minor formatting changes and I've combined a few commits.

Thanks!