Ë
    Ã?ÆiÏ  ã                  óf   — d Z ddlmZ ddlZddl­ ddlmZmZ dd„Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zy)aÞ  CPR (personnummer, the Danish citizen number).

The CPR is the national number to identify Danish citizens and is stored in
the Det Centrale Personregister (Civil Registration System). The number
consists of 10 digits in the format DDMMYY-SSSS where the first part
represents the birth date and the second a sequence number. The first digit
of the sequence number indicates the century.

The numbers used to validate using a checksum but since the sequence numbers
ran out this was abandoned in 2007. It is also not possible to use the
checksum only for numbers that have a birth date before that because the
numbers are also assigned to immigrants.

More information:

* https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
* https://da.wikipedia.org/wiki/CPR-nummer
* https://cpr.dk/

>>> validate('211062-5629')
'2110625629'
>>> checksum('2110625629')
0
>>> validate('511062-5629')  # invalid date
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)
>>> format('2110625629')
'211062-5629'
é    )ÚannotationsN)Ú*)ÚcleanÚisdigitsc                ó6   — t        | d«      j                  «       S )zˆConvert the number to the minimal representation. This strips the
    number of any valid separators and removes surrounding whitespace.z -)r   Ústrip©Únumbers    úT/var/www/html/myprovider/mon_projet_qr/lib/python3.12/site-packages/stdnum/dk/cpr.pyÚcompactr   C   s   € ô �˜Ó×$Ñ$Ó&Ð&ó    c                óD   — d}t        d„ t        || «      D «       «      dz  S )z|Calculate the checksum. Note that the checksum isn't actually used
    any more. Valid numbers used to have a checksum of 0.)
é   é   é   é   é   é   r   r   r   é   c              3  ó>   K  — | ]  \  }}|t        |«      z  –— Œ y ­w)N)Úint)Ú.0ÚwÚns      r   ú	<genexpr>zchecksum.<locals>.<genexpr>M   s   è ø€ Ò;™d˜a ˆq”3�q“6�zÑ;ùs   ‚é   )ÚsumÚzip)r
   Úweightss     r   Úchecksumr    I   s&   € ð -€GÜÑ;¤c¨'°6Ó&:Ô;Ó;¸bÑ@Ð@r   c                ó,  — t        | «      } t        | dd «      }t        | dd «      }t        | dd «      }| d   dv r|dk\  r|dz  }n| d   dv s| d   d	v r|d
k\  r|dz  }n|dz  }	 t        j                  |||«      S # t        $ r t        d«      ‚w xY w)z?Split the date parts from the number and return the birth date.r   r   r   r   Ú5678é:   i  Ú0123Ú49é%   il  iÐ  z9The number does not contain valid birth date information.)r   r   ÚdatetimeÚdateÚ
ValueErrorÚInvalidComponent)r
   ÚdayÚmonthÚyears       r   Úget_birth_dater.   P   s»   € ä�V‹_€FÜ
ˆf�Q�qˆkÓ
€CÜ��q˜�Ó€EÜˆv�a˜ˆ{Ó€DØˆa�y�FÑ˜t ršzØ�‰‰Ø	�‰�fÑ	 ¨¡¨dÑ!2°t¸r²zØ�‰‰à�‰ˆð\Ü�}‰}˜T 5¨#Ó.Ð.øÜò \ÜÐZÓ[Ð[ð\ús   Á'A> Á>Bc                óà   — t        | «      } t        | «      s
t        «       ‚t        | «      dk7  r
t	        «       ‚t        | «      t        j                  j                  «       kD  rt        d«      ‚| S )úzCheck if the number provided is a valid CPR number. This checks the
    length, formatting, embedded date and check digit.é
   zKThe birth date information is valid, but this person has not been born yet.)
r   r   ÚInvalidFormatÚlenÚInvalidLengthr.   r'   r(   Útodayr*   r	   s    r   Úvalidater6   b   sb   € ô �V‹_€FÜ�FÔÜ‹oÐÜ
ˆ6ƒ{�bÒÜ‹oÐÜ�fÓ¤§¡× 3Ñ 3Ó 5Ò5ÜØYó[ð 	[à€Mr   c                óJ   — 	 t        t        | «      «      S # t        $ r Y yw xY w)r0   F)Úboolr6   ÚValidationErrorr	   s    r   Úis_validr:   p   s)   € ðÜ”H˜VÓ$Ó%Ð%øÜò Ùðús   ‚ –	"¡"c                óJ   — t        | «      } dj                  | dd | dd f«      S )z8Reformat the number to the standard presentation format.ú-Nr   )r   Újoinr	   s    r   Úformatr>   y   s+   € ä�V‹_€FØ�8‰8�V˜B˜Q�Z ¨¨ Ð,Ó-Ð-r   )r
   ÚstrÚreturnr?   )r
   r?   r@   r   )r
   r?   r@   zdatetime.date)r
   r?   r@   r8   )Ú__doc__Ú
__future__r   r'   Ústdnum.exceptionsÚstdnum.utilr   r   r   r    r.   r6   r:   r>   © r   r   ú<module>rF      s9   ðñ,#õJ #ã ä ß 'ó'óAó\ó$óô.r   