diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/transactions/mt940/Mt940Parser.kt index 2f2d0502..490edb8d 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/transactions/mt940/Mt940Parser.kt @@ -463,6 +463,10 @@ open class Mt940Parser( year -= 100 } + if (month == 2 && (day > 29 || (day > 28 && year % 4 != 0))) { + return LocalDate(year, 3, 1) + } + return LocalDate(year , month, day) } catch (e: Exception) { logError("Could not parse dateString '$dateString'", e) diff --git a/fints4k/src/commonTest/kotlin/net/codinux/banking/fints/transactions/Mt940ParserTest.kt b/fints4k/src/commonTest/kotlin/net/codinux/banking/fints/transactions/Mt940ParserTest.kt index 69d02491..53820a60 100644 --- a/fints4k/src/commonTest/kotlin/net/codinux/banking/fints/transactions/Mt940ParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/codinux/banking/fints/transactions/Mt940ParserTest.kt @@ -330,6 +330,20 @@ class Mt940ParserTest : FinTsTestBase() { assertEquals(LocalDate(1999, 5, 7), result) } + @Test + fun parseDate_FixSparkasse29thOFFebruaryInNonLeapYearBug() { + val result = underTest.parseMt940Date("230229") + + assertEquals(LocalDate(2023, 3, 1), result) + } + + @Test + fun parseDate_FixSparkasse30thOfFebruaryBug() { + val result = underTest.parseMt940Date("230229") + + assertEquals(LocalDate(2023, 3, 1), result) + } + private fun assertBalance(balance: Balance, isCredit: Boolean, bookingDate: LocalDate, amount: Amount) { assertEquals(isCredit, balance.isCredit)