fix: calculate personnummer correctly before annual birthday #104
+15
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Description
Fixes an issue where the age is one year too much, if the person did not have had their birthday in the current year.
Related issue
Motivation
Less bugs, more happy people :)
Checklist
Notes
DateTime.Now
which will make the tests for this test case break depending on if the birth date has already taken place during the current year or not. The proper fix would be to use TimeProvider introduced in .NET 8, but I do not know the implications of that when targeting specific .NET versions and I do not have the time to look into it.DateTime.Now
has another issue, as it takes the local time of the computer running on. Personal Numbers are given according to the Swedish time zone, so there might be some edge cases when a computer runs in a time zone which is considered a different day than in Sweden. Still, this PR improves the accuracy from up to 366 days of error to 1 day.var
. If you prefer the type instead, let me know and I will adjust the coding style.