-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Øyvind Hatland
committed
Oct 13, 2023
1 parent
a0b7262
commit c1dd6ec
Showing
8 changed files
with
78 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func FindBirthYear(fnr string) string { | ||
thisYear := time.Now().Year() | ||
birthYear, _ := strconv.Atoi("20" + fnr[4:6]) | ||
|
||
// check if person is born in the 1900 or 2000 | ||
// limit: persons over 100 years old wil be 1 year old with this function | ||
if birthYear >= thisYear { | ||
return "19" + fnr[4:6] | ||
} else { | ||
return fmt.Sprint(birthYear) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package utils_test | ||
|
||
import ( | ||
"brok/navnetjener/utils" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test50YearOldPerson(t *testing.T) { | ||
birthYear := utils.FindBirthYear("11117300000") | ||
|
||
assert.Equal(t, "1973", birthYear) | ||
} | ||
|
||
func Test10YearOldPerson(t *testing.T) { | ||
birthYear := utils.FindBirthYear("11111300000") | ||
|
||
assert.Equal(t, "2013", birthYear) | ||
} | ||
|
||
func Test120YearOldPerson(t *testing.T) { | ||
birthYear := utils.FindBirthYear("11110300000") | ||
|
||
assert.Equal(t, "2003", birthYear) | ||
} |