Skip to content

swedish ssn symbol depends on birthday date of person#1458

Merged
asolntsev merged 4 commits intodatafaker-net:mainfrom
TrueJacobG:swedish-ssn-fix-nonexistent-date-gen
Dec 6, 2024
Merged

swedish ssn symbol depends on birthday date of person#1458
asolntsev merged 4 commits intodatafaker-net:mainfrom
TrueJacobG:swedish-ssn-fix-nonexistent-date-gen

Conversation

@TrueJacobG
Copy link
Copy Markdown
Contributor

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

…older than 100 years than she/he has + in ssn
@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Dec 3, 2024

PR Summary

  • Enhancements to SwedenIdNumber class:
    • Streamlined Code Imports: The gender import statement has been reorganized for better code readability.
    • Improved Date Formating: A new element, FULL_DATE_FORMATTER, has been added to handle full-date formatting tasks more efficiently.
    • Technique for ID Generation Updated: The 'PLUS_MINUS' feature has been removed. Instead, a new generateSymbol method has been created. This method will identify which symbol (+ or -) to use depending on the year.
    • Method Name & Logic Change: The parseDate function is now called isDateIncorrect. It has been enhanced for clearer and more reliable date verification.
    • Introduction of Age Verification: The new isYearOver100YearsAgo method can verify if a given year is more than a century ago.
  • Additions to SwedishIdNumberTest:
    • Expanded Testing: We've incorporated additional test cases to validate ID checking functionality. This includes tests for both valid and invalid Social Security Numbers (SSNs).

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 3, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 69.23077% with 8 lines in your changes missing coverage. Please review.

Project coverage is 92.40%. Comparing base (ab1c267) to head (bd8589b).

Files with missing lines Patch % Lines
...n/java/net/datafaker/idnumbers/SwedenIdNumber.java 69.23% 5 Missing and 3 partials ⚠️

❗ 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.
📢 Have feedback on the report? Share it here.

@asolntsev asolntsev self-requested a review December 3, 2024 22:44
@asolntsev asolntsev self-assigned this Dec 3, 2024
@asolntsev asolntsev added the bug Something isn't working label Dec 3, 2024
@asolntsev asolntsev added this to the 2.4.3 milestone Dec 3, 2024
char symbol = ssn.charAt(6);

if (symbol == '+') {
dateString = "19" + dateString;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the initial problem really solved here?
Now you generate the right symbol (- or +), but the date still may be **0229+*****.

Copy link
Copy Markdown
Contributor Author

@TrueJacobG TrueJacobG Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Method isYearOver100YearsAgo expects year number in the first argument. But it's named date (not year), and you pass dateString in 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@asolntsev asolntsev self-requested a review December 5, 2024 18:51
@asolntsev asolntsev merged commit 4721557 into datafaker-net:main Dec 6, 2024
@asolntsev
Copy link
Copy Markdown
Collaborator

@TrueJacobG Thank you, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants