Created
January 6, 2021 11:49
-
-
Save tobiashm/fe08e4eeb07e1df87e9cd45679edd0a4 to your computer and use it in GitHub Desktop.
Determine birth year from CPR-nummer (Danish personal identifier)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cpr = '0101374000' | |
def match = (cpr =~ /^\d{4}(\d{\d}2})(\d)\d{3}$/)[0] | |
def year = match[1] as Integer | |
def x = match[2] as Integer | |
switch (x) { | |
case 0..3: year += 1900; break; | |
case [4, 9]: year += year <= 36 ? 2000 : 1900; break; | |
case 5..8: year += year <= 57 ? 2000 : 1800; break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment