Skip to content

Commit

Permalink
Ignore date/time records, that cannot be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Nov 9, 2024
1 parent e5c4181 commit 454c855
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object QifUtils {
fun parseDate(sDateTime: String, format: QifDateFormat): Date {
return try {
parseDateInternal(sDateTime, format).time
} catch (e: IllegalArgumentException) {
} catch (_: IllegalArgumentException) {
val dateTimeChunks = WHITESPACE_PATTERN.split(sDateTime)
if (dateTimeChunks.size > 1) {
try {
Expand Down
29 changes: 20 additions & 9 deletions myExpenses/src/main/java/org/totschnig/myexpenses/io/CSVParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CSVParser(
).abs() else BigDecimal(0)
income.subtract(expense)
}
} catch (e: IllegalArgumentException) {
} catch (_: IllegalArgumentException) {
BigDecimal.ZERO
}
)
Expand Down Expand Up @@ -132,15 +132,26 @@ class CSVParser(
)
}
if (timeRecord != null) {
val cal = dateRecord?.let { QifUtils.parseDateInternal(dateRecord, dateFormat) }
val cal = dateRecord?.let {
try {
QifUtils.parseDateInternal(dateRecord, dateFormat)
} catch (_: Exception) {
null
}
}
?: Calendar.getInstance()
val time = LocalTime.parse(
timeRecord,
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
)
cal[Calendar.HOUR_OF_DAY] = time.hour
cal[Calendar.MINUTE] = time.minute
cal[Calendar.SECOND] = time.second
try {
LocalTime.parse(
timeRecord,
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
)
} catch (_: Exception) {
null
}?.let {
cal[Calendar.HOUR_OF_DAY] = it.hour
cal[Calendar.MINUTE] = it.minute
cal[Calendar.SECOND] = it.second
}
transaction.date(cal.time)
}
if (columnIndexValueDate != -1) {
Expand Down

0 comments on commit 454c855

Please sign in to comment.