Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created January 6, 2021 11:49
Show Gist options
  • Save tobiashm/fe08e4eeb07e1df87e9cd45679edd0a4 to your computer and use it in GitHub Desktop.
Save tobiashm/fe08e4eeb07e1df87e9cd45679edd0a4 to your computer and use it in GitHub Desktop.
Determine birth year from CPR-nummer (Danish personal identifier)
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