koblas / stdnum-js

A JavaScript library to provide functions to handle, parse and validate standard numbers.
MIT License
39 stars 26 forks source link

feat: add belgian national number #20

Closed mikeryancodes closed 2 years ago

mikeryancodes commented 2 years ago

This work adds the Belgian National Number, based on this work in the Python library with some additions.

This code works for all examples given in the Wikipedia article.

This work accounts for ambiguous numbers that could go with someone very young or someone over 100. For example, an identifier that starts with '19' will be validated for both someone born in 1919 and someone born in 2019 and considered valid if the validation passes for either.

commit-lint[bot] commented 2 years ago

Contributors

mikeryancodes

Commit-Lint commands
You can trigger Commit-Lint actions by commenting on this PR: - `@Commit-Lint merge patch` will merge dependabot PR on "patch" versions (X.X.Y - Y change) - `@Commit-Lint merge minor` will merge dependabot PR on "minor" versions (X.Y.Y - Y change) - `@Commit-Lint merge major` will merge dependabot PR on "major" versions (Y.Y.Y - Y change) - `@Commit-Lint merge disable` will desactivate merge dependabot PR - `@Commit-Lint review` will approve dependabot PR - `@Commit-Lint stop review` will stop approve dependabot PR
mikeryancodes commented 2 years ago

I thought of some additional edge/corner cases. The Wikipedia article says that 000001xxx corresponds to a completely unknown birthday. But according to other rules, it could also correspond to a birthday where only the year is known, the year is 1900 or 2000 (these would start with 000000 and then the next three digits would be the count) and the count overflows. The validation in the Wikipedia article checks it as a 'pre-2000' birthday only, this code will check it as both pre and post 2000 birthdays.

In general, this validation treats the birthday portion as valid if it corresponds to at least one valid date in the past when trying 19yy and 20yy. It treats a birthdate with digits for the year, digits for the day and zeros for the month as specifying an unknown date of birth. This allows for ~100000 people with unknown birthdays for a given year prefix (which could correspond to two different, valid years), including ~100000 people whose birthdays are completely unknown or born in 1900 or 2000 with the month and day unknown.

mikeryancodes commented 2 years ago

That's fair, I did not really consult the original implementation and I do not know Python.