Skip to content

Commit

Permalink
Add function for short ssn format
Browse files Browse the repository at this point in the history
  • Loading branch information
hugokallstrom committed Dec 11, 2023
1 parent 795c18e commit 41c6227
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ fun formatSsn(ssn: String): String {
}
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.Snapshot
import arrow.core.raise.either
import com.hedvig.android.core.common.formatShortSsn
import com.hedvig.android.core.common.safeCast
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.feature.editcoinsured.data.CoInsured
Expand Down Expand Up @@ -187,7 +188,7 @@ internal class EditCoInsuredPresenter(
addBottomSheetState = addBottomSheetState.copy(errorMessage = null)
val ssn = addBottomSheetState.ssn
if (ssn != null) {
val paddedSsn = getPaddedSsn(ssn)
val paddedSsn = formatShortSsn(ssn)
either {
val result = fetchCoInsuredPersonalInformationUseCase.invoke(paddedSsn).bind()
addBottomSheetState = addBottomSheetState.copy(
Expand Down Expand Up @@ -319,12 +320,6 @@ internal class EditCoInsuredPresenter(
} else {
(listState.coInsured + coInsured).toImmutableList()
}

private fun getPaddedSsn(ssn: String) = if (ssn.length == 10) {
"19$ssn" // Need to add century if not included in SSN
} else {
ssn
}
}

internal sealed interface EditCoInsuredEvent {
Expand Down

0 comments on commit 41c6227

Please sign in to comment.