From fde162738816e1affa03dc07dc43fd6fbfc6193d Mon Sep 17 00:00:00 2001 From: Maximilian Pfundstein Date: Fri, 4 Oct 2024 18:58:53 +0200 Subject: [PATCH] fix: calculate personnummer correctly before annual birthday --- Personnummer/Personnummer.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Personnummer/Personnummer.cs b/Personnummer/Personnummer.cs index af4689c..31230c3 100644 --- a/Personnummer/Personnummer.cs +++ b/Personnummer/Personnummer.cs @@ -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 ? "+" : "-";