Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/desktop-client/src/hooks/useFormulaExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a breaking change as non-US dates are used by default, but for the future we should look at using the user date pref to set this if possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that using locales + the Actual format would be best.

});

// Add a sheet and set the formula in cell A1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/rules/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -336,7 +337,6 @@ export class Action {
}
hfInstance.addNamedExpression(key, cellValue);
}

hfInstance.setCellContents({ sheet: sheetId, col: 0, row: 0 }, [
[formula],
]);
Expand Down
5 changes: 4 additions & 1 deletion packages/loot-core/src/server/rules/formula-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/7373.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfixes
authors: [youngcw]
---

Fix date variable in rule formulas
Loading