From 126c1983429f55be0d61fdd06b0901323b801e3e Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 28 May 2026 09:39:28 +0200 Subject: [PATCH 01/10] allow several date formats for CSV company cards --- src/libs/actions/CompanyCards.ts | 16 +++++- src/libs/actions/ImportTransactions.ts | 77 +------------------------- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 8d55d77397ca..9b149de6ad01 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -18,6 +18,7 @@ import type { import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as CardUtils from '@libs/CardUtils'; import {getCardFeedWithDomainID} from '@libs/CardUtils'; +import {parseCSVDate} from '@libs/CSVDateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import {rand64} from '@libs/NumberUtils'; @@ -104,6 +105,7 @@ function buildOptimisticCompanyCardCSVTransactions( const cardNumberColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.CARD_NUMBER); const postedDateColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.POSTED_DATE); + const originalTransactionDateColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.ORIGINAL_TRANSACTION_DATE); const merchantColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.MERCHANT); const amountColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.AMOUNT); const currencyColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.CURRENCY); @@ -117,7 +119,8 @@ function buildOptimisticCompanyCardCSVTransactions( row[externalIDColumnIndex] = transactionID; const cardName = row.at(cardNumberColumnIndex)?.trim(); - const created = row.at(postedDateColumnIndex)?.trim(); + const rawPostedDate = row.at(postedDateColumnIndex)?.trim(); + const created = rawPostedDate ? parseCSVDate(rawPostedDate) : null; const merchant = row.at(merchantColumnIndex)?.trim() ?? ''; const currency = row.at(currencyColumnIndex)?.trim(); const amountValue = row.at(amountColumnIndex) ?? ''; @@ -127,6 +130,17 @@ function buildOptimisticCompanyCardCSVTransactions( continue; } + // The backend expects yyyy-MM-dd dates, so write the normalized values back into + // the row before it gets serialized and sent to Auth/Scrapers. + row[postedDateColumnIndex] = created; + if (originalTransactionDateColumnIndex >= 0) { + const rawOriginalDate = row.at(originalTransactionDateColumnIndex)?.trim(); + const parsedOriginalDate = rawOriginalDate ? parseCSVDate(rawOriginalDate) : null; + if (parsedOriginalDate) { + row[originalTransactionDateColumnIndex] = parsedOriginalDate; + } + } + const category = categoryColumnIndex >= 0 ? (row.at(categoryColumnIndex)?.trim() ?? '') : ''; const tag = tagColumnIndex >= 0 ? (row.at(tagColumnIndex)?.trim() ?? '') : ''; const comment = commentColumnIndex >= 0 ? (row.at(commentColumnIndex)?.trim() ?? '') : ''; diff --git a/src/libs/actions/ImportTransactions.ts b/src/libs/actions/ImportTransactions.ts index ba577dd2bd50..147987498d0b 100644 --- a/src/libs/actions/ImportTransactions.ts +++ b/src/libs/actions/ImportTransactions.ts @@ -1,10 +1,10 @@ -import {addDays, format, isValid, parse} from 'date-fns'; import type {OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; import type {ImportCSVTransactionsParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; import {generateCardID} from '@libs/CardUtils'; +import {parseCSVDate} from '@libs/CSVDateUtils'; import DateUtils from '@libs/DateUtils'; import {rand64} from '@libs/NumberUtils'; import CONST from '@src/CONST'; @@ -23,81 +23,6 @@ type TransactionFromCSV = { category?: string; }; -// Common date formats to try when parsing CSV dates -// Order matters - more specific/common formats first -const CSV_DATE_FORMATS = [ - 'yyyy-MM-dd', // ISO format: 2025-11-02 - 'MM/dd/yyyy', // US format: 11/02/2025 - 'dd/MM/yyyy', // European format: 02/11/2025 - 'M/d/yyyy', // US short: 1/2/2025 - 'd/M/yyyy', // European short: 2/1/2025 - 'MM-dd-yyyy', // US with dashes: 11-02-2025 - 'dd-MM-yyyy', // European with dashes: 02-11-2025 - 'yyyy/MM/dd', // Alternative ISO: 2025/11/02 - 'MMM d, yyyy', // Month name: Nov 2, 2025 - 'MMMM d, yyyy', // Full month: November 2, 2025 - 'd MMM yyyy', // European with month name: 2 Nov 2025 - 'dd MMM yyyy', // European with month name: 02 Nov 2025 - 'yyyyMMdd', // Compact: 20251102 -]; - -/** - * Parses a date string from various formats and returns it in yyyy-MM-dd format - */ -function parseCSVDate(input: string): string | null { - if (!input || typeof input !== 'string') { - return null; - } - - const trimmedInput = input.trim(); - - // Try native Date parsing first (handles ISO and some other formats) - let date = new Date(trimmedInput); - if (isValid(date) && !Number.isNaN(date.getTime())) { - return format(date, CONST.DATE.FNS_FORMAT_STRING); - } - - // Try parsing with common date formats using date-fns - for (const dateFormat of CSV_DATE_FORMATS) { - const parsedDate = parse(trimmedInput, dateFormat, new Date()); - if (isValid(parsedDate)) { - return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); - } - } - - // If the date didn't parse, try taking just the first 10 characters - if (trimmedInput.length > 10) { - const shortInput = trimmedInput.substring(0, 10); - date = new Date(shortInput); - if (isValid(date) && !Number.isNaN(date.getTime())) { - return format(date, CONST.DATE.FNS_FORMAT_STRING); - } - // Also try format parsing on the shortened input - for (const dateFormat of CSV_DATE_FORMATS) { - const parsedDate = parse(shortInput, dateFormat, new Date()); - if (isValid(parsedDate)) { - return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); - } - } - } - - // If it didn't parse, maybe it's an Excel date number - // Excel stores dates serialized from January 1st, 1900 (with 1/1/1900 being 1) - // Excel thinks that 1900 was a leap year and adds an extra day to account for that - if (/^\d+$/.test(trimmedInput)) { - const inputInt = parseInt(trimmedInput, 10); - if (inputInt > 0 && inputInt < 100000) { - const excelEpoch = new Date(1900, 0, 1); // January 1, 1900 - const parsedDate = addDays(excelEpoch, inputInt - 2); - if (isValid(parsedDate)) { - return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); - } - } - } - - return null; -} - type ColumnIndexes = { date: number; merchant: number; From 7926d9d71586b4e0511b6bf725e0f3fa11e8486f Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 28 May 2026 12:40:37 +0200 Subject: [PATCH 02/10] dependencies --- src/libs/CSVDateUtils.ts | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/libs/CSVDateUtils.ts diff --git a/src/libs/CSVDateUtils.ts b/src/libs/CSVDateUtils.ts new file mode 100644 index 000000000000..da661438aadb --- /dev/null +++ b/src/libs/CSVDateUtils.ts @@ -0,0 +1,79 @@ +import {addDays, format, isValid, parse} from 'date-fns'; +import CONST from '@src/CONST'; + +// Common date formats to try when parsing CSV dates +// Order matters - more specific/common formats first +const CSV_DATE_FORMATS = [ + 'yyyy-MM-dd', // ISO format: 2025-11-02 + 'MM/dd/yyyy', // US format: 11/02/2025 + 'dd/MM/yyyy', // European format: 02/11/2025 + 'M/d/yyyy', // US short: 1/2/2025 + 'd/M/yyyy', // European short: 2/1/2025 + 'MM-dd-yyyy', // US with dashes: 11-02-2025 + 'dd-MM-yyyy', // European with dashes: 02-11-2025 + 'yyyy/MM/dd', // Alternative ISO: 2025/11/02 + 'MMM d, yyyy', // Month name: Nov 2, 2025 + 'MMMM d, yyyy', // Full month: November 2, 2025 + 'd MMM yyyy', // European with month name: 2 Nov 2025 + 'dd MMM yyyy', // European with month name: 02 Nov 2025 + 'yyyyMMdd', // Compact: 20251102 +]; + +/** + * Parses a date string from various formats and returns it in yyyy-MM-dd format + */ +function parseCSVDate(input: string): string | null { + if (!input || typeof input !== 'string') { + return null; + } + + const trimmedInput = input.trim(); + + // Try native Date parsing first (handles ISO and some other formats) + let date = new Date(trimmedInput); + if (isValid(date) && !Number.isNaN(date.getTime())) { + return format(date, CONST.DATE.FNS_FORMAT_STRING); + } + + // Try parsing with common date formats using date-fns + for (const dateFormat of CSV_DATE_FORMATS) { + const parsedDate = parse(trimmedInput, dateFormat, new Date()); + if (isValid(parsedDate)) { + return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); + } + } + + // If the date didn't parse, try taking just the first 10 characters + if (trimmedInput.length > 10) { + const shortInput = trimmedInput.substring(0, 10); + date = new Date(shortInput); + if (isValid(date) && !Number.isNaN(date.getTime())) { + return format(date, CONST.DATE.FNS_FORMAT_STRING); + } + // Also try format parsing on the shortened input + for (const dateFormat of CSV_DATE_FORMATS) { + const parsedDate = parse(shortInput, dateFormat, new Date()); + if (isValid(parsedDate)) { + return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); + } + } + } + + // If it didn't parse, maybe it's an Excel date number + // Excel stores dates serialized from January 1st, 1900 (with 1/1/1900 being 1) + // Excel thinks that 1900 was a leap year and adds an extra day to account for that + if (/^\d+$/.test(trimmedInput)) { + const inputInt = parseInt(trimmedInput, 10); + if (inputInt > 0 && inputInt < 100000) { + const excelEpoch = new Date(1900, 0, 1); // January 1, 1900 + const parsedDate = addDays(excelEpoch, inputInt - 2); + if (isValid(parsedDate)) { + return format(parsedDate, CONST.DATE.FNS_FORMAT_STRING); + } + } + } + + return null; +} + +export {CSV_DATE_FORMATS, parseCSVDate}; From 703b07e32aa839bc53a767151654188279c4c8d1 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 28 May 2026 13:55:05 +0200 Subject: [PATCH 03/10] Add tests --- tests/unit/ImportTransactions.test.ts | 52 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/unit/ImportTransactions.test.ts b/tests/unit/ImportTransactions.test.ts index 411d57a55f68..8af6efdafd35 100644 --- a/tests/unit/ImportTransactions.test.ts +++ b/tests/unit/ImportTransactions.test.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ import Onyx from 'react-native-onyx'; +import * as API from '@libs/API'; import {applySavedColumnMappings, getImportFinalModalOnyxData} from '@libs/actions/ImportSpreadsheet'; -import {buildColumnLayout, buildTransactionListFromSpreadsheet, getColumnIndexes} from '@libs/actions/ImportTransactions'; +import importTransactionsFromCSV, {buildColumnLayout, buildTransactionListFromSpreadsheet, getColumnIndexes} from '@libs/actions/ImportTransactions'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type ImportedSpreadsheet from '@src/types/onyx/ImportedSpreadsheet'; @@ -760,4 +761,53 @@ describe('ImportTransactions', () => { expect(Onyx.merge).not.toHaveBeenCalled(); }); }); + + describe('importTransactionsFromCSV', () => { + const validSpreadsheet = { + data: [ + ['Date', '2024-01-15', '2024-01-20'], + ['Merchant', 'Coffee Shop', 'Restaurant'], + ['Amount', '5.50', '25.00'], + ], + columns: { + 0: 'date', + 1: 'merchant', + 2: 'amount', + }, + containsHeader: true, + } as Partial as ImportedSpreadsheet; + + it('returns the failed-import modal and skips the API call when no transactions are parsed', async () => { + const apiWriteSpy = jest.spyOn(API, 'write'); + + const result = await importTransactionsFromCSV({...validSpreadsheet, data: []}); + + expect(result).toEqual({titleKey: 'spreadsheet.importFailedTitle', promptKey: 'spreadsheet.invalidFileMessage'}); + expect(apiWriteSpy).not.toHaveBeenCalled(); + }); + + it('calls API.write with an optimistic card when no existingCardID is passed', async () => { + const apiWriteSpy = jest.spyOn(API, 'write').mockRejectedValue(new Error('forced')); + + await importTransactionsFromCSV(validSpreadsheet); + + expect(apiWriteSpy).toHaveBeenCalledTimes(1); + const [command, , onyxData] = apiWriteSpy.mock.calls.at(0) ?? []; + expect(command).toBe('ImportCSVTransactions'); + const optimisticCardEntry = (onyxData as {optimisticData: Array<{key: string}>}).optimisticData.find((entry) => entry.key === ONYXKEYS.CARD_LIST); + expect(optimisticCardEntry).toBeDefined(); + }); + + it('reuses an existingCardID without queuing an optimistic card', async () => { + const apiWriteSpy = jest.spyOn(API, 'write').mockRejectedValue(new Error('forced')); + const existingCardID = 987654321; + + await importTransactionsFromCSV(validSpreadsheet, existingCardID); + + const [, params, onyxData] = apiWriteSpy.mock.calls.at(0) ?? []; + expect((params as {cardID: number}).cardID).toBe(existingCardID); + const optimisticCardEntry = (onyxData as {optimisticData: Array<{key: string}>}).optimisticData.find((entry) => entry.key === ONYXKEYS.CARD_LIST); + expect(optimisticCardEntry).toBeUndefined(); + }); + }); }); From 4d2d87977af1a9fafd8f1966bf1e0c13458152cf Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 28 May 2026 14:29:42 +0200 Subject: [PATCH 04/10] prettier --- tests/unit/ImportTransactions.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ImportTransactions.test.ts b/tests/unit/ImportTransactions.test.ts index 8af6efdafd35..5629ef0085c3 100644 --- a/tests/unit/ImportTransactions.test.ts +++ b/tests/unit/ImportTransactions.test.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ import Onyx from 'react-native-onyx'; -import * as API from '@libs/API'; import {applySavedColumnMappings, getImportFinalModalOnyxData} from '@libs/actions/ImportSpreadsheet'; import importTransactionsFromCSV, {buildColumnLayout, buildTransactionListFromSpreadsheet, getColumnIndexes} from '@libs/actions/ImportTransactions'; +import * as API from '@libs/API'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type ImportedSpreadsheet from '@src/types/onyx/ImportedSpreadsheet'; From bcec5e1ec3d5efbeb24badd8d88695bf8b3d2562 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 28 May 2026 15:55:56 +0200 Subject: [PATCH 05/10] lint --- tests/unit/ImportTransactions.test.ts | 31 +++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/unit/ImportTransactions.test.ts b/tests/unit/ImportTransactions.test.ts index 5629ef0085c3..736fa595205a 100644 --- a/tests/unit/ImportTransactions.test.ts +++ b/tests/unit/ImportTransactions.test.ts @@ -777,37 +777,40 @@ describe('ImportTransactions', () => { containsHeader: true, } as Partial as ImportedSpreadsheet; - it('returns the failed-import modal and skips the API call when no transactions are parsed', async () => { - const apiWriteSpy = jest.spyOn(API, 'write'); + let writeSpy: jest.SpyInstance; + + beforeEach(() => { + writeSpy = jest.spyOn(API, 'write').mockRejectedValue(new Error('forced')); + }); + afterEach(() => { + writeSpy.mockRestore(); + }); + + it('returns the failed-import modal and skips the API call when no transactions are parsed', async () => { const result = await importTransactionsFromCSV({...validSpreadsheet, data: []}); expect(result).toEqual({titleKey: 'spreadsheet.importFailedTitle', promptKey: 'spreadsheet.invalidFileMessage'}); - expect(apiWriteSpy).not.toHaveBeenCalled(); + expect(writeSpy).not.toHaveBeenCalled(); }); it('calls API.write with an optimistic card when no existingCardID is passed', async () => { - const apiWriteSpy = jest.spyOn(API, 'write').mockRejectedValue(new Error('forced')); - await importTransactionsFromCSV(validSpreadsheet); - expect(apiWriteSpy).toHaveBeenCalledTimes(1); - const [command, , onyxData] = apiWriteSpy.mock.calls.at(0) ?? []; + expect(writeSpy).toHaveBeenCalledTimes(1); + const [command, , onyxData] = writeSpy.mock.calls.at(0) as [string, unknown, {optimisticData: Array<{key: string}>}]; expect(command).toBe('ImportCSVTransactions'); - const optimisticCardEntry = (onyxData as {optimisticData: Array<{key: string}>}).optimisticData.find((entry) => entry.key === ONYXKEYS.CARD_LIST); - expect(optimisticCardEntry).toBeDefined(); + expect(onyxData.optimisticData.some((entry) => entry.key === ONYXKEYS.CARD_LIST)).toBe(true); }); it('reuses an existingCardID without queuing an optimistic card', async () => { - const apiWriteSpy = jest.spyOn(API, 'write').mockRejectedValue(new Error('forced')); const existingCardID = 987654321; await importTransactionsFromCSV(validSpreadsheet, existingCardID); - const [, params, onyxData] = apiWriteSpy.mock.calls.at(0) ?? []; - expect((params as {cardID: number}).cardID).toBe(existingCardID); - const optimisticCardEntry = (onyxData as {optimisticData: Array<{key: string}>}).optimisticData.find((entry) => entry.key === ONYXKEYS.CARD_LIST); - expect(optimisticCardEntry).toBeUndefined(); + const [, params, onyxData] = writeSpy.mock.calls.at(0) as [string, {cardID: number}, {optimisticData: Array<{key: string}>}]; + expect(params.cardID).toBe(existingCardID); + expect(onyxData.optimisticData.some((entry) => entry.key === ONYXKEYS.CARD_LIST)).toBe(false); }); }); }); From caf0a6bd3e3eaef7c50cf93ff86cf0ee32184dd8 Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 9 Jun 2026 17:35:22 +0200 Subject: [PATCH 06/10] lint --- tests/unit/ImportTransactions.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/ImportTransactions.test.ts b/tests/unit/ImportTransactions.test.ts index 736fa595205a..4fa7f5b06fb2 100644 --- a/tests/unit/ImportTransactions.test.ts +++ b/tests/unit/ImportTransactions.test.ts @@ -763,6 +763,7 @@ describe('ImportTransactions', () => { }); describe('importTransactionsFromCSV', () => { + const CURRENT_USER_ACCOUNT_ID = 12345; const validSpreadsheet = { data: [ ['Date', '2024-01-15', '2024-01-20'], @@ -788,14 +789,14 @@ describe('ImportTransactions', () => { }); it('returns the failed-import modal and skips the API call when no transactions are parsed', async () => { - const result = await importTransactionsFromCSV({...validSpreadsheet, data: []}); + const result = await importTransactionsFromCSV({...validSpreadsheet, data: []}, CURRENT_USER_ACCOUNT_ID); expect(result).toEqual({titleKey: 'spreadsheet.importFailedTitle', promptKey: 'spreadsheet.invalidFileMessage'}); expect(writeSpy).not.toHaveBeenCalled(); }); it('calls API.write with an optimistic card when no existingCardID is passed', async () => { - await importTransactionsFromCSV(validSpreadsheet); + await importTransactionsFromCSV(validSpreadsheet, CURRENT_USER_ACCOUNT_ID); expect(writeSpy).toHaveBeenCalledTimes(1); const [command, , onyxData] = writeSpy.mock.calls.at(0) as [string, unknown, {optimisticData: Array<{key: string}>}]; @@ -806,7 +807,7 @@ describe('ImportTransactions', () => { it('reuses an existingCardID without queuing an optimistic card', async () => { const existingCardID = 987654321; - await importTransactionsFromCSV(validSpreadsheet, existingCardID); + await importTransactionsFromCSV(validSpreadsheet, CURRENT_USER_ACCOUNT_ID, existingCardID); const [, params, onyxData] = writeSpy.mock.calls.at(0) as [string, {cardID: number}, {optimisticData: Array<{key: string}>}]; expect(params.cardID).toBe(existingCardID); From 6a87dc33ce27a2eac24fb6e77e370eea7a7792ba Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 9 Jun 2026 17:56:59 +0200 Subject: [PATCH 07/10] knip --- src/libs/CSVDateUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/CSVDateUtils.ts b/src/libs/CSVDateUtils.ts index da661438aadb..fdf5da818aef 100644 --- a/src/libs/CSVDateUtils.ts +++ b/src/libs/CSVDateUtils.ts @@ -76,4 +76,4 @@ function parseCSVDate(input: string): string | null { return null; } -export {CSV_DATE_FORMATS, parseCSVDate}; +export {parseCSVDate}; From 6257f01df01f5c843ffd1e8ed509a66ef3349994 Mon Sep 17 00:00:00 2001 From: alberto Date: Wed, 10 Jun 2026 15:49:31 +0200 Subject: [PATCH 08/10] lint --- src/libs/CSVDateUtils.ts | 2 +- src/libs/actions/CompanyCards.ts | 2 +- src/libs/actions/ImportTransactions.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/CSVDateUtils.ts b/src/libs/CSVDateUtils.ts index fdf5da818aef..9005901367a2 100644 --- a/src/libs/CSVDateUtils.ts +++ b/src/libs/CSVDateUtils.ts @@ -76,4 +76,4 @@ function parseCSVDate(input: string): string | null { return null; } -export {parseCSVDate}; +export default parseCSVDate; diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 21ab73f5e087..9e13eff4397d 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -18,7 +18,7 @@ import type { import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as CardUtils from '@libs/CardUtils'; import {getCardFeedWithDomainID} from '@libs/CardUtils'; -import {parseCSVDate} from '@libs/CSVDateUtils'; +import parseCSVDate from '@libs/CSVDateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import {rand64} from '@libs/NumberUtils'; diff --git a/src/libs/actions/ImportTransactions.ts b/src/libs/actions/ImportTransactions.ts index 0f73505f8b92..9665dc6a389b 100644 --- a/src/libs/actions/ImportTransactions.ts +++ b/src/libs/actions/ImportTransactions.ts @@ -4,7 +4,7 @@ import * as API from '@libs/API'; import type {ImportCSVTransactionsParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; import {generateCardID} from '@libs/CardUtils'; -import {parseCSVDate} from '@libs/CSVDateUtils'; +import parseCSVDate from '@libs/CSVDateUtils'; import DateUtils from '@libs/DateUtils'; import {rand64} from '@libs/NumberUtils'; import CONST from '@src/CONST'; From d6bc79913fedeb7aa89bb315fa207767a2cd9eec Mon Sep 17 00:00:00 2001 From: alberto Date: Wed, 17 Jun 2026 17:10:29 +0200 Subject: [PATCH 09/10] fix some warnings --- tests/unit/ImportTransactions.test.ts | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/unit/ImportTransactions.test.ts b/tests/unit/ImportTransactions.test.ts index 4fa7f5b06fb2..a61342b84a00 100644 --- a/tests/unit/ImportTransactions.test.ts +++ b/tests/unit/ImportTransactions.test.ts @@ -109,11 +109,14 @@ describe('ImportTransactions', () => { describe('buildColumnLayout', () => { it('should build a basic layout with no column mappings', () => { - const spreadsheet = { + const spreadsheet: ImportedSpreadsheet = { data: [], columns: {}, containsHeader: true, - } as Partial as ImportedSpreadsheet; + isImportingMultiLevelTags: false, + isImportingIndependentMultiLevelTags: false, + isGLAdjacent: false, + }; const result = buildColumnLayout(spreadsheet, 'Test Card', 'USD', true, false); @@ -149,7 +152,7 @@ describe('ImportTransactions', () => { }); it('should build layout with column mappings and extract header names', () => { - const spreadsheet = { + const spreadsheet: ImportedSpreadsheet = { data: [ ['Date', '2024-01-01', '2024-01-02'], ['Merchant', 'Store A', 'Store B'], @@ -163,7 +166,10 @@ describe('ImportTransactions', () => { 3: 'category', }, containsHeader: true, - } as Partial as ImportedSpreadsheet; + isImportingMultiLevelTags: false, + isImportingIndependentMultiLevelTags: false, + isGLAdjacent: false, + }; const result = buildColumnLayout(spreadsheet, 'My Card', 'EUR', false, true); @@ -188,7 +194,7 @@ describe('ImportTransactions', () => { }); it('should handle missing headers when containsHeader is false', () => { - const spreadsheet = { + const spreadsheet: ImportedSpreadsheet = { data: [ ['2024-01-01', '2024-01-02'], ['Store A', 'Store B'], @@ -200,7 +206,10 @@ describe('ImportTransactions', () => { 2: 'amount', }, containsHeader: false, - } as Partial as ImportedSpreadsheet; + isImportingMultiLevelTags: false, + isImportingIndependentMultiLevelTags: false, + isGLAdjacent: false, + }; const result = buildColumnLayout(spreadsheet, 'Card', 'USD', true, false); @@ -222,7 +231,7 @@ describe('ImportTransactions', () => { }); it('should handle out of bounds column indexes gracefully', () => { - const spreadsheet = { + const spreadsheet: ImportedSpreadsheet = { data: [ ['Date', '2024-01-01'], ['Merchant', 'Store A'], @@ -233,7 +242,10 @@ describe('ImportTransactions', () => { 10: 'amount', // Out of bounds }, containsHeader: true, - } as Partial as ImportedSpreadsheet; + isImportingMultiLevelTags: false, + isImportingIndependentMultiLevelTags: false, + isGLAdjacent: false, + }; const result = buildColumnLayout(spreadsheet, 'Card', 'USD', true, false); From fb0f8c99505ab6240b75a7110ef398fbcac32b4b Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez-Cela Date: Mon, 22 Jun 2026 17:42:07 +0200 Subject: [PATCH 10/10] Update src/libs/CSVDateUtils.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lucien Akchoté --- src/libs/CSVDateUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/CSVDateUtils.ts b/src/libs/CSVDateUtils.ts index 9005901367a2..ddf5759eb242 100644 --- a/src/libs/CSVDateUtils.ts +++ b/src/libs/CSVDateUtils.ts @@ -50,6 +50,7 @@ function parseCSVDate(input: string): string | null { if (isValid(date) && !Number.isNaN(date.getTime())) { return format(date, CONST.DATE.FNS_FORMAT_STRING); } + // Also try format parsing on the shortened input for (const dateFormat of CSV_DATE_FORMATS) { const parsedDate = parse(shortInput, dateFormat, new Date());