organisationsnummer / csharp

Validate Swedish organization numbers
https://organisationsnummer.dev/
MIT License
2 stars 2 forks source link

[Q] - If the organisationsnummer is a personnummer and the person in question is above 100 years old, Shouldn't the Format function return a + separator? #38

Closed torenius closed 8 months ago

torenius commented 9 months ago

First of all, this is a greate package :)

We have a few rows in our database that have a personnummer as there organisationsnummer and are above 100 years old. If I use your personnummer library it respects the + in the number. But when parsing with this library and calling Format it will return with - instead.

Is there any specific reason why you whent with that solution? It seems intended, so Im woundering if there is any good reason for not returning a + in does occasions?

Why do this?

public string Format(bool separator = true)
{
    var num = ShortString;
    return separator ? $"{num!.Substring(0, 6)}-{num!.Substring(6)}" : num!;
}

private string ShortString => ((IsPersonnummer ? _personnummer!.Format(false) : _number)!)
        .Replace("-", "")
        .Replace("+", "");

Instead of just?

public string Format(bool separator = true)
{
   if (IsPersonnummer) return _personnummer!.Format(false, !separator);

    return separator ? $"{_number!.Substring(0, 6)}-{_number!.Substring(6)}" : _number!;
}
Johannestegner commented 9 months ago

This is likely something we have missed and I'd say that it's a bug and not intentional. As you say, the check if it is a personnummer should be added and the formatting should be passed to the Personnummer library instead.

Will take it up with the team and make sure this is how we handle it in all packages.

Thank you for the report!

Johannestegner commented 9 months ago

Further research makes me think that I was wrong in that it is a bug and that it actually is intentional. I will do some more research and get back to you here when I get a clear answer, but it seems like org-nr for "enskild firma" always makes use of - and never +.

Johannestegner commented 9 months ago

Small update on this issue. I asked Bolagsverket, whom had no answer and redirected me to Skatteverket. Currently awaiting an answer from them. Bolagsverket said that there are no active EF:s with an owner above 100 years though, but we do ofcourse want to handle it correctly. I'll update here with more info :)

torenius commented 9 months ago

Thank you :)

Johannestegner commented 8 months ago

I finally got a response from Skatteverket (that took a while!), and they say that for enskild firma, it's supposed to be formatted as with a standard personnummer (that is, with a + if its older than 100 years).

I will correct this asap (or you may open up a pull request if you wish!) in this and the other repos :)

Johannestegner commented 8 months ago

Fixed in latest release (1.2.0).

Thank you again!

torenius commented 8 months ago

Thank you :)