Skip to content

Commit

Permalink
fix: calculate personnummer correctly before annual birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
flennic authored and Johannestegner committed Oct 4, 2024
1 parent 21f99e4 commit bd6d979
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Personnummer/Personnummer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ public Options()

public DateTime Date { get; private set; }

public int Age => DateTime.Now.Year - Date.Year;
public int Age
{
get
{
var now = DateTime.Now;
var age = now.Year - Date.Year;

if (now.Month >= Date.Month && now.Day > Date.Day)
{
age--;
}

return age;
}
}

public string Separator => Age >= 100 ? "+" : "-";

Expand Down

0 comments on commit bd6d979

Please sign in to comment.