diff --git a/src/app-gocardless/banks/lhv-lhvbee22.js b/src/app-gocardless/banks/lhv-lhvbee22.js index 43e7e075..f8d34bc2 100644 --- a/src/app-gocardless/banks/lhv-lhvbee22.js +++ b/src/app-gocardless/banks/lhv-lhvbee22.js @@ -1,3 +1,5 @@ +import d from 'date-fns'; + import Fallback from './integration-bank.js'; /** @type {import('./bank.interface.js').IBank} */ @@ -20,15 +22,17 @@ export default { ); if (cardTxMatch) { + const extractedDate = d.parse(cardTxMatch[2], 'yyyy-MM-dd', new Date()); + transaction = { ...transaction, creditorName: cardTxMatch[4].split('\\')[0].trim(), }; - if (booked) { + if (booked && d.isValid(extractedDate)) { transaction = { ...transaction, - bookingDate: cardTxMatch[2], + bookingDate: d.format(extractedDate, 'yyyy-MM-dd'), }; } } diff --git a/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js b/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js index 571bdeb8..72e61fb3 100644 --- a/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js +++ b/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js @@ -37,6 +37,7 @@ describe('#normalizeTransaction', () => { ['regular text', 'Some info'], ['partial card text', 'PIRKUMS xxx'], ['null value', null], + ['invalid date', '(..1234) 2025-13-45 09:32 Merchant\\Address'], ])('normalizes non-card transaction with %s', (_, remittanceInfo) => { const transaction = { ...bookedCardTransaction,