swedish ssn symbol depends on birthday date of person#1458
swedish ssn symbol depends on birthday date of person#1458asolntsev merged 4 commits intodatafaker-net:mainfrom
Conversation
…older than 100 years than she/he has + in ssn
PR Summary
|
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1458 +/- ##
============================================
+ Coverage 92.37% 92.40% +0.03%
- Complexity 3228 3237 +9
============================================
Files 324 324
Lines 6332 6348 +16
Branches 606 610 +4
============================================
+ Hits 5849 5866 +17
- Misses 340 341 +1
+ Partials 143 141 -2 ☔ View full report in Codecov by Sentry. |
| char symbol = ssn.charAt(6); | ||
|
|
||
| if (symbol == '+') { | ||
| dateString = "19" + dateString; |
There was a problem hiding this comment.
Do I understand correctly that "19" and "20" are hardcoded values that will not be correct after ~76 years?
Isn't it better to use LocalDate.now() instead?
There was a problem hiding this comment.
Yeah, you're right that's way better!
but, in fact this is a problem of swedish SSN itself. The format is not ready for 22 century so it will eventually break in the future (or rather ssn format will got change in the future).
| String end = generateEndPart(f); | ||
| String basePart = DATE_TIME_FORMATTER.format(birthday) | ||
| + f.options().option(PLUS_MINUS) | ||
| + generateSymbol(birthday) |
There was a problem hiding this comment.
Is the initial problem really solved here?
Now you generate the right symbol (- or +), but the date still may be **0229+*****.
There was a problem hiding this comment.
It's nothing incorrect with XX0229+XXXX, because 29th of February happend in few years. The incorrect value was 000229+XXXX, because there was no 29th of February in 1900.
There was a problem hiding this comment.
-
Method
isYearOver100YearsAgoexpects year number in the first argument. But it's nameddate(notyear), and you passdateStringin line 120 (isYearOver100YearsAgo(dateString, ...).
This code:
@RepeatedTest(1000)
void swedishSsn_containsPlus_forPersonsOlderThan100Years() {
PersonIdNumber person = new SwedenIdNumber().generateValid(new Faker(), new IdNumber.IdNumberRequest(123, 125, ANY));
assertThat(person.idNumber()).contains("+");
assertThat(SwedenIdNumber.isValidSwedishSsn(person.idNumber())).as(person.idNumber()).isTrue();
}still can generate invalid IDs, e.g. 991207+4219, 991224+0851 or 991207+5430.
There was a problem hiding this comment.
Fixed it!
also 991207+4219, 991224+0851 and 991207+5430 they are valid SSNs. For ssn validation logic I recommend using https://swedish.identityinfo.net/personalidentitynumber/validate?number=991207%2B4219
…k in the future (because of hardcoded values)
|
@TrueJacobG Thank you, merged! |
If a person is older than 100 years, their SSN should have a "+" as the separator.
I found that when I was using datafaker and it sometimes creates SSNs that look like "000229+XXXX," which is an invalid SSN because February 29 did not exist in the year 1900.
more info: https://swedish.identityinfo.net/personalidentitynumber