File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -268,6 +268,27 @@ public void TestSeparator(PersonnummerData ssn)
268268 Assert . Equal ( sep , Personnummer . Parse ( ssn . SeparatedFormat , new Personnummer . Options { AllowCoordinationNumber = true } ) . Separator ) ;
269269 // Getting the separator from a short formatted none-separated person number is not actually possible if it is intended to be a +.
270270 }
271+
272+ [ Theory ]
273+ [ ClassData ( typeof ( ValidSsnDataProvider ) ) ]
274+ [ ClassData ( typeof ( ValidCnDataProvider ) ) ]
275+ public void TestIgnoreSeparatorWhenFormatting ( PersonnummerData ssn )
276+ {
277+ var separators = "+-" . ToCharArray ( ) ;
278+
279+ var ps1 = Personnummer . Parse ( ssn . LongFormat , new Personnummer . Options { AllowCoordinationNumber = true } ) ;
280+ var ps2 = Personnummer . Parse ( ssn . SeparatedLong , new Personnummer . Options { AllowCoordinationNumber = true } ) ;
281+ var ps3 = Personnummer . Parse ( ssn . SeparatedFormat ,
282+ new Personnummer . Options { AllowCoordinationNumber = true } ) ;
283+
284+ Assert . True ( ps1 . Format ( false , true ) . IndexOfAny ( separators ) == - 1 ) ;
285+ Assert . True ( ps2 . Format ( false , true ) . IndexOfAny ( separators ) == - 1 ) ;
286+ Assert . True ( ps3 . Format ( false , true ) . IndexOfAny ( separators ) == - 1 ) ;
287+
288+ Assert . True ( ps1 . Format ( ) . IndexOfAny ( separators ) >= 0 ) ;
289+ Assert . True ( ps2 . Format ( ) . IndexOfAny ( separators ) >= 0 ) ;
290+ Assert . True ( ps3 . Format ( ) . IndexOfAny ( separators ) >= 0 ) ;
291+ }
271292
272293 [ Theory ]
273294 [ ClassData ( typeof ( OrgNumberDataProvider ) ) ]
Original file line number Diff line number Diff line change @@ -126,10 +126,11 @@ public Personnummer(string ssn, Options? options = null)
126126 /// If longFormat is true, it will include the century (YYYYMMDD-/+XXXX)
127127 /// </summary>
128128 /// <param name="longFormat">If century should be included.</param>
129+ /// <param name="ignoreSeparator">Whether the separator should be ignored.</param>
129130 /// <returns>Formatted personal identity number.</returns>
130- public string Format ( bool longFormat = false )
131+ public string Format ( bool longFormat = false , bool ignoreSeparator = false )
131132 {
132- return $ "{ ( longFormat ? FullYear : Year ) } { Month } { Day } { Separator } { Numbers } ";
133+ return ignoreSeparator ? $ " { ( longFormat ? FullYear : Year ) } { Month } { Day } { Numbers } " : $ "{ ( longFormat ? FullYear : Year ) } { Month } { Day } { Separator } { Numbers } ";
133134 }
134135
135136 /// <summary>
You can’t perform that action at this time.
0 commit comments