Skip to content

Commit

Permalink
fix: date handlebar functions (actualbudget#3749)
Browse files Browse the repository at this point in the history
* fix: date handlebar functions

* chore: release note

* chore: tests
  • Loading branch information
UnderKoen authored Oct 28, 2024
1 parent b349edd commit 59835a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/loot-core/src/server/accounts/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ describe('Action', () => {
testHelper('{{month "2002-07-25"}}', '7');
testHelper('{{year "2002-07-25"}}', '2002');
testHelper('{{format "2002-07-25" "MM yyyy d"}}', '07 2002 25');
testHelper('{{day undefined}}', '');
testHelper('{{month undefined}}', '');
testHelper('{{year undefined}}', '');
testHelper('{{format undefined undefined}}', '');
});

test('{{debug}} should log the item', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ function registerHandlebarsHelpers() {
min: mathHelper((a, b) => Math.min(a, b)),
max: mathHelper((a, b) => Math.max(a, b)),
fixed: (a: unknown, digits: unknown) => Number(a).toFixed(Number(digits)),
day: (date: string) => format(date, 'd'),
month: (date: string) => format(date, 'M'),
year: (date: string) => format(date, 'yyyy'),
format: (date: string, f: string) => format(date, f),
day: (date?: string) => date && format(date, 'd'),
month: (date?: string) => date && format(date, 'M'),
year: (date?: string) => date && format(date, 'yyyy'),
format: (date?: string, f?: string) => date && f && format(date, f),
debug: (value: unknown) => {
console.log(value);
},
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3749.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [UnderKoen]
---

Fix usage of date functions in action rule templating.

0 comments on commit 59835a3

Please sign in to comment.