python-stdnum branch master updated. 1.13-7-g4500881
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.13-7-g4500881
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org, python-stdnum-commits [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.13-7-g4500881
- Date: Sun, 1 Mar 2020 20:41:44 +0100 (CET)
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 4500881cf6aad1ddd1ad8b3bcc1495f5a48c45cf (commit)
from f5e04567fd4196ef1f559f6d570baca618186662 (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=4500881cf6aad1ddd1ad8b3bcc1495f5a48c45cf
commit 4500881cf6aad1ddd1ad8b3bcc1495f5a48c45cf
Author: Leon Sandøy <leon.haland@gmail.com>
Date: Fri Jan 31 17:55:09 2020 +0100
Improve birth date validation for dk.cpr
This adds a check to validate that the birth date information in a
personnummer is not set in the future, resolving a TODO from this file.
It also improves exception messages for certain validation fail
conditions.
diff --git a/stdnum/dk/cpr.py b/stdnum/dk/cpr.py
index b6d636b..97eaf2b 100644
--- a/stdnum/dk/cpr.py
+++ b/stdnum/dk/cpr.py
@@ -1,6 +1,8 @@
# cpr.py - functions for handling Danish CPR numbers
+# coding: utf-8
#
# Copyright (C) 2012-2019 Arthur de Jong
+# Copyright (C) 2020 Leon Sandøy
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -44,10 +46,12 @@ More information:
Traceback (most recent call last):
...
InvalidComponent: ...
+>>> validate('2110525629')
+Traceback (most recent call last):
+ ...
+InvalidComponent: The birth date information is valid, but this person has not
been born yet.
>>> get_birth_date('2110620629')
datetime.date(1962, 10, 21)
->>> get_birth_date('2110525629')
-datetime.date(2052, 10, 21)
>>> format('2110625629')
'211062-5629'
"""
@@ -86,7 +90,7 @@ def get_birth_date(number):
try:
return datetime.date(year, month, day)
except ValueError:
- raise InvalidComponent()
+ raise InvalidComponent('The number does not contain valid birth date
information.')
def validate(number):
@@ -97,9 +101,9 @@ def validate(number):
raise InvalidFormat()
if len(number) != 10:
raise InvalidLength()
- # check if birth date is valid
- get_birth_date(number)
- # TODO: check that the birth date is not in the future
+ if get_birth_date(number) > datetime.date.today():
+ raise InvalidComponent(
+ 'The birth date information is valid, but this person has not been
born yet.')
return number
-----------------------------------------------------------------------
Summary of changes:
stdnum/dk/cpr.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 1.13-7-g4500881,
Commits of the python-stdnum project