Added tests for parsing date
This commit is contained in:
parent
dae6084ebb
commit
c5432883ef
|
@ -53,7 +53,7 @@ open class Mt940Parser(
|
|||
|
||||
val DateFormatter = DateFormatter("yyMMdd") // TODO: replace with LocalDate.Format { }
|
||||
|
||||
val CurrentYearTwoDigit = LocalDate.todayAtEuropeBerlin().year - 2000
|
||||
val CurrentYearTwoDigit = LocalDate.todayAtEuropeBerlin().year
|
||||
|
||||
val CreditDebitCancellationRegex = Regex("C|D|RC|RD")
|
||||
|
||||
|
@ -455,7 +455,7 @@ open class Mt940Parser(
|
|||
// this really simple date format on my own
|
||||
if (dateString.length == 6) {
|
||||
try {
|
||||
var year = dateString.substring(0, 2).toInt()
|
||||
var year = dateString.substring(0, 2).toInt() + 2000
|
||||
val month = dateString.substring(2, 4).toInt()
|
||||
val day = dateString.substring(4, 6).toInt()
|
||||
|
||||
|
@ -463,7 +463,7 @@ open class Mt940Parser(
|
|||
year -= 100
|
||||
}
|
||||
|
||||
return LocalDate(year + 2000, month, day) // java.util.Date years start at 1900 at month at 0 not at 1
|
||||
return LocalDate(year , month, day)
|
||||
} catch (e: Exception) {
|
||||
logError("Could not parse dateString '$dateString'", e)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,11 @@ class Mt940ParserTest : FinTsTestBase() {
|
|||
val AccountStatement1With2TransactionsClosingBalanceAmount = Amount("13148,13")
|
||||
}
|
||||
|
||||
private val underTest = Mt940Parser()
|
||||
private val underTest = object : Mt940Parser() {
|
||||
public override fun parseMt940Date(dateString: String): LocalDate {
|
||||
return super.parseMt940Date(dateString)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
@ -312,6 +316,21 @@ class Mt940ParserTest : FinTsTestBase() {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun parseDate() {
|
||||
val result = underTest.parseMt940Date("240507")
|
||||
|
||||
assertEquals(LocalDate(2024, 5, 7), result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseDateBeforeYear2000() {
|
||||
val result = underTest.parseMt940Date("990507")
|
||||
|
||||
assertEquals(LocalDate(1999, 5, 7), result)
|
||||
}
|
||||
|
||||
|
||||
private fun assertBalance(balance: Balance, isCredit: Boolean, bookingDate: LocalDate, amount: Amount) {
|
||||
assertEquals(isCredit, balance.isCredit)
|
||||
assertEquals(bookingDate, balance.bookingDate)
|
||||
|
|
Loading…
Reference in New Issue