lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.18-16-g42d2792

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.18-16-g42d2792



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  42d2792bcac8692b2c081dead7a5061a4540abe6 (commit)
      from  cf14a9ff079b53da57c7e17e7a5686734795285e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=42d2792bcac8692b2c081dead7a5061a4540abe6

commit 42d2792bcac8692b2c081dead7a5061a4540abe6
Author: Jeff Horemans <jeff.horemans@vortex-financials.be>
Date:   Thu Jan 5 13:27:29 2023 +0100

    Add functionality to get gender from Belgian National Number
    
    This also extends the documentation for the number.
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/347/files

diff --git a/stdnum/be/nn.py b/stdnum/be/nn.py
index bada9b9..fd6c627 100644
--- a/stdnum/be/nn.py
+++ b/stdnum/be/nn.py
@@ -18,13 +18,21 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""NN, NISS (Belgian national number).
+"""NN, NISS, RRN (Belgian national number).
 
-The national number is a unique identifier of Belgian. The number consists of
-11 digits.
+The national registration number (Rijksregisternummer, Numéro de registre
+national, Nationalregisternummer) is a unique identification number of
+natural persons who are registered in Belgium.
+
+The number consists of 11 digits and includes the person's date of birth and
+gender. It encodes the date of birth in the first 6 digits in the format
+YYMMDD. The following 3 digits represent a counter of people born on the same
+date, seperated by sex (odd for male and even for females respectively). The
+final 2 digits form a check number based on the 9 preceding digits.
 
 More information:
 
+* https://nl.wikipedia.org/wiki/Rijksregisternummer
 * https://fr.wikipedia.org/wiki/Numéro_de_registre_national
 
 >>> compact('85.07.30-033 28')
@@ -41,6 +49,8 @@ InvalidChecksum: ...
 '85.07.30-033.28'
 >>> get_birth_date('85.07.30-033 28')
 datetime.date(1985, 7, 30)
+>>> get_gender('85.07.30-033 28')
+'M'
 """
 
 import datetime
@@ -68,7 +78,7 @@ def _checksum(number):
 
 
 def validate(number):
-    """Check if the number if a valid National Number."""
+    """Check if the number is a valid National Number."""
     number = compact(number)
     if not isdigits(number) or int(number) <= 0:
         raise InvalidFormat()
@@ -96,7 +106,7 @@ def format(number):
 
 
 def get_birth_date(number):
-    """Return the date of birth"""
+    """Return the date of birth."""
     number = compact(number)
     century = _checksum(number)
     if not century:
@@ -106,3 +116,11 @@ def get_birth_date(number):
             str(century) + number[:6], '%Y%m%d').date()
     except ValueError:
         raise InvalidComponent()
+
+
+def get_gender(number):
+    """Get the person's gender ('M' or 'F')."""
+    number = compact(number)
+    if int(number[6:9]) % 2:
+        return 'M'
+    return 'F'
diff --git a/tests/test_be_nn.doctest b/tests/test_be_nn.doctest
index 287ba05..492218d 100644
--- a/tests/test_be_nn.doctest
+++ b/tests/test_be_nn.doctest
@@ -40,3 +40,9 @@ InvalidChecksum: ...
 Traceback (most recent call last):
     ...
 InvalidComponent: ...
+
+
+Extra tests for getting gender
+
+>>> nn.get_gender('75.06.08-980.09')
+'F'

-----------------------------------------------------------------------

Summary of changes:
 stdnum/be/nn.py          | 28 +++++++++++++++++++++++-----
 tests/test_be_nn.doctest |  6 ++++++
 2 files changed, 29 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
python-stdnum