-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1918 from HedvigInsurance/fix/ssn-format
String builders for name and ssn
- Loading branch information
Showing
7 changed files
with
104 additions
and
48 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...ommon-public/src/main/kotlin/com/hedvig/android/core/common/PersonalInfoStringBuilders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.hedvig.android.core.common | ||
|
||
fun formatSsn(ssn: String): String { | ||
return if (ssn.length == 12) { | ||
buildString { | ||
append(ssn.substring(0..7)) | ||
append("-") | ||
append(ssn.substring(8..11)) | ||
} | ||
} else { | ||
ssn | ||
} | ||
} | ||
|
||
fun formatShortSsn(ssn: String): String { | ||
val formattedSSN = ssn.replace("-", "") | ||
if (formattedSSN.length == 10) { | ||
val ssnLastTwoDigitsOfYear = formattedSSN.substring(0, 2) | ||
val currentYear = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR) | ||
val firstTwoDigitsOfTheYear = currentYear / 100 | ||
val lastTwoDigitsOfTheYear = currentYear % 100 | ||
|
||
val ssnLastTwoDigits = ssnLastTwoDigitsOfYear.toIntOrNull() | ||
|
||
return if (ssnLastTwoDigits != null && ssnLastTwoDigits > lastTwoDigitsOfTheYear) { | ||
"${firstTwoDigitsOfTheYear - 1}$ssn" | ||
} else { | ||
"$firstTwoDigitsOfTheYear$ssn" | ||
} | ||
} else { | ||
return ssn | ||
} | ||
} | ||
|
||
fun formatName(firstName: String?, lastName: String?): String { | ||
return buildString { | ||
if (firstName != null) { | ||
append(firstName) | ||
} | ||
if (firstName != null && lastName != null) { | ||
append(" ") | ||
} | ||
if (lastName != null) { | ||
append(lastName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
...re-edit-coinsured/src/main/kotlin/com/hedvig/android/feature/editcoinsured/data/Member.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
package com.hedvig.android.feature.editcoinsured.data | ||
|
||
import com.hedvig.android.core.common.formatName | ||
import com.hedvig.android.core.common.formatSsn | ||
|
||
internal data class Member( | ||
val firstName: String, | ||
val lastName: String, | ||
val ssn: String?, | ||
) { | ||
val displayName: String = "$firstName $lastName" | ||
val displayName: String = formatName(firstName, lastName) | ||
|
||
fun identifier(): String? { | ||
return if (ssn != null) { | ||
formatSsn(ssn) | ||
} else { | ||
null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters