Skip to content

A local-first personal finance app

fix formula date variable in rules (#7373)

youngcw926f7193f99e
diff --git a/packages/desktop-client/src/hooks/useFormulaExecution.ts b/packages/desktop-client/src/hooks/useFormulaExecution.ts
index b687365ba1..d498933aa2 100644
--- a/packages/desktop-client/src/hooks/useFormulaExecution.ts
+++ b/packages/desktop-client/src/hooks/useFormulaExecution.ts
@@ -329,6 +329,7 @@ export function useFormulaExecution(
licenseKey: 'gpl-v3',
localeLang: typeof locale === 'string' ? locale : 'en-US',
language: 'enUS',
+ dateFormats: ['DD/MM/YYYY', 'YYYY-MM-DD', 'YYYY/MM/DD'],
});
// Add a sheet and set the formula in cell A1
diff --git a/packages/desktop-client/src/hooks/useTransactionFormulaExecution.ts b/packages/desktop-client/src/hooks/useTransactionFormulaExecution.ts
index 52ef8e12ff..6f49acc1c1 100644
--- a/packages/desktop-client/src/hooks/useTransactionFormulaExecution.ts
+++ b/packages/desktop-client/src/hooks/useTransactionFormulaExecution.ts
@@ -41,6 +41,7 @@ export function useTransactionFormulaExecution(
hfInstance = HyperFormula.buildEmpty({
licenseKey: 'gpl-v3',
localeLang: typeof locale === 'string' ? locale : 'en-US',
+ dateFormats: ['DD/MM/YYYY', 'YYYY-MM-DD', 'YYYY/MM/DD'],
});
// Add a sheet
diff --git a/packages/loot-core/src/server/rules/action.ts b/packages/loot-core/src/server/rules/action.ts
index e5ccdf6c57..a9620be1a6 100644
--- a/packages/loot-core/src/server/rules/action.ts
+++ b/packages/loot-core/src/server/rules/action.ts
@@ -303,6 +303,7 @@ export class Action {
hfInstance = HyperFormula.buildEmpty({
licenseKey: 'gpl-v3',
language: 'enUS',
+ dateFormats: ['DD/MM/YYYY', 'YYYY-MM-DD', 'YYYY/MM/DD'],
});
const sheetName = hfInstance.addSheet('Sheet1');
@@ -336,7 +337,6 @@ export class Action {
}
hfInstance.addNamedExpression(key, cellValue);
}
-
hfInstance.setCellContents({ sheet: sheetId, col: 0, row: 0 }, [
[formula],
]);
diff --git a/packages/loot-core/src/server/rules/formula-action.test.ts b/packages/loot-core/src/server/rules/formula-action.test.ts
index 86d8f94c1b..97aa2e9bbb 100644
--- a/packages/loot-core/src/server/rules/formula-action.test.ts
+++ b/packages/loot-core/src/server/rules/formula-action.test.ts
@@ -75,7 +75,10 @@ describe('Formula-based rule actions', () => {
it('should provide today variable', () => {
const action = new Action('set', 'date', null, {});
const transaction = { date: '2024-01-01' };
- const result = action.executeFormulaSync('=today', transaction);
+ const result = action.executeFormulaSync(
+ '=TEXT(today,"YYYY-MM-DD")',
+ transaction,
+ );
// Should be a date string in YYYY-MM-DD format
expect(typeof result).toBe('string');
diff --git a/upcoming-release-notes/7373.md b/upcoming-release-notes/7373.md
new file mode 100644
index 0000000000..a2497b9c36
--- /dev/null
+++ b/upcoming-release-notes/7373.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [youngcw]
+---
+
+Fix date variable in rule formulas