Skip to content

Commit

Permalink
F - Legger inn sjekk for npid
Browse files Browse the repository at this point in the history
  • Loading branch information
dskarpas committed Sep 8, 2023
1 parent d261178 commit 15850cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class Fodselsnummer private constructor(@JsonValue val value: String) {
return if(kjoenn % 2 == 0) Kjoenn.KVINNE else Kjoenn.MANN
}

//De seks første tallene i NPID er tilfeldige tall og har ingen datobetydning.
//De to første er ikke høyere enn 31. Tall på plass 3 og 4 (måned på FNR) er mellom 21 og 32.
//De to siste er kontrollsiffer.
val nPID: Boolean
get() {
val lessThen31 = value.substring(0, 2).toInt()
val between21and32 = value.substring(2, 4).toInt()
return lessThen31 in 0..31 && between21and32 in 21..32
}
val dNummer: Boolean
get() {
val dag = value[0].toString().toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ internal class FodselsnummerTest {
assertNotNull(Fodselsnummer.fra("54496214261"))
}

@Test
fun `npid fdata should be valid`() {
assertNotNull(Fodselsnummer.fra("01220049651"))
assert(Fodselsnummer.fra("01220049651")?.nPID == true)
}

@Test
fun `syntetic date and birthdate`() {
val synt = "54496214261" //KAFFI DØLL
Expand Down

0 comments on commit 15850cd

Please sign in to comment.