From eb0bf54317159de4ffad608ad2c4741e1320effd Mon Sep 17 00:00:00 2001 From: Sigfus Oddsson Date: Wed, 3 Jan 2018 10:04:51 +0000 Subject: [PATCH] Ensure non-person kennitala is valid even though its corresponding date does not exist --- kennitala/__init__.py | 5 +++++ tests/test_kennitala.py | 1 + 2 files changed, 6 insertions(+) diff --git a/kennitala/__init__.py b/kennitala/__init__.py index 34a61e9..c78bea1 100644 --- a/kennitala/__init__.py +++ b/kennitala/__init__.py @@ -140,6 +140,11 @@ def validate(self): try: date(year, month, day) + except ValueError: + if int(kennitala[0]) <= 3 or 1 > day > 31: + return False + + try: checkdigit = Kennitala._compute_checkdigit(kennitala) return kennitala[-2] == checkdigit except ValueError: diff --git a/tests/test_kennitala.py b/tests/test_kennitala.py index 8194d14..43c1d0f 100644 --- a/tests/test_kennitala.py +++ b/tests/test_kennitala.py @@ -9,6 +9,7 @@ '140543-3229', # kennitala of Icelandic president '1203753509', # kennitala of Icelandic prime minister '6503760649', # kennitala of Þjóðskrá Íslands (Registry Iceland) + '7102692709', # kennitala of Þjóðleikhúsið (National Theatre) ) birth_dates = (date(1943, 5, 14), date(1975, 3, 12))