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 committed Oct 4, 2024
1 parent 21f99e4 commit fde1627
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Personnummer/Personnummer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ 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 differenceInTotalMonth = 12 * (now.Year - Date.Year) + now.Month - Date.Month;
return differenceInTotalMonth / 12;
}
}

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

Expand Down

0 comments on commit fde1627

Please sign in to comment.