From 32defa20f71833061c3e4145060c36a3a2d10f1b Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 26 Aug 2024 23:46:48 +0200 Subject: [PATCH] Fixed that Sparkasse returns 30th of February or 29th of February also in non leap years --- .../fints/transactions/mt940/Mt940Parser.kt | 4 ++++ .../banking/fints/transactions/Mt940ParserTest.kt | 14 ++++++++++++++ 2 files changed, 18 insertions(+) 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)