diff --git a/lib/src/main/java/com/basistheory/android/view/CardExpirationDateElement.kt b/lib/src/main/java/com/basistheory/android/view/CardExpirationDateElement.kt index 20f9384b..c53e1024 100644 --- a/lib/src/main/java/com/basistheory/android/view/CardExpirationDateElement.kt +++ b/lib/src/main/java/com/basistheory/android/view/CardExpirationDateElement.kt @@ -32,9 +32,12 @@ class CardExpirationDateElement @JvmOverloads constructor( monthRef: ElementValueReference, yearRef: ElementValueReference ) { - val month = monthRef.getValue().toIntString() + var month = monthRef.getValue().toIntString() val year = yearRef.getValue().toIntString() + // unique edge case not handled by beforeTextChanged since users can enter 10, 11 or 12 + if (month == "1") month = "01" + setText("${month}${year?.takeLast(2)}") } diff --git a/lib/src/test/java/com/basistheory/android/view/CardExpirationDateElementTests.kt b/lib/src/test/java/com/basistheory/android/view/CardExpirationDateElementTests.kt index 4aafa837..fc525f8a 100644 --- a/lib/src/test/java/com/basistheory/android/view/CardExpirationDateElementTests.kt +++ b/lib/src/test/java/com/basistheory/android/view/CardExpirationDateElementTests.kt @@ -154,6 +154,15 @@ class CardExpirationDateElementTests { expectThat(cardExpirationDateElement.getText()).isEqualTo("08/30") } + @Test + fun `can set value references for january as a single digit`() { + val monthRef = ElementValueReference { "1" } + val yearRef = ElementValueReference { "2030" } + cardExpirationDateElement.setValueRef(monthRef, yearRef) + + expectThat(cardExpirationDateElement.getText()).isEqualTo("01/30") + } + @Test fun `can set value references for both month and year as doubles`() { val monthRef = ElementValueReference { "8.0" }