-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: date handlebar functions #3749
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged No assets were unchanged |
WalkthroughThe changes introduced in this pull request enhance the functionality and testing of several components within the rules engine. In the Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
packages/loot-core/src/server/accounts/rules.ts (1)
79-82
: LGTM! The changes address the PR objective.The updated function signatures now properly handle undefined values, fixing the
{{day today}}
handlebar function issue. The short-circuit evaluation using&&
ensures that undefined inputs return undefined instead of throwing errors.Consider adding validation for invalid date formats to provide more helpful error messages. Here's a suggested implementation:
- 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), + day: (date?: string) => { + if (!date) return ''; + try { + return format(date, 'd'); + } catch (e) { + return ''; + } + }, + month: (date?: string) => { + if (!date) return ''; + try { + return format(date, 'M'); + } catch (e) { + return ''; + } + }, + year: (date?: string) => { + if (!date) return ''; + try { + return format(date, 'yyyy'); + } catch (e) { + return ''; + } + }, + format: (date?: string, f?: string) => { + if (!date || !f) return ''; + try { + return format(date, f); + } catch (e) { + return ''; + } + },This implementation:
- Explicitly handles undefined values by returning an empty string
- Catches and handles invalid date format errors gracefully
- Maintains consistent behavior across all date helper functions
packages/loot-core/src/server/accounts/rules.test.ts (1)
409-412
: Consider adding tests for additional edge cases.While the current tests cover undefined inputs, consider adding test cases for:
null
inputs- Invalid date strings (e.g., "not-a-date")
- Empty strings
Example:
testHelper('{{day undefined}}', ''); testHelper('{{month undefined}}', ''); testHelper('{{year undefined}}', ''); testHelper('{{format undefined undefined}}', ''); + testHelper('{{day null}}', ''); + testHelper('{{month "not-a-date"}}', ''); + testHelper('{{year ""}}', ''); + testHelper('{{format null "yyyy-MM-dd"}}', '');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
upcoming-release-notes/3749.md
is excluded by!**/*.md
📒 Files selected for processing (2)
- packages/loot-core/src/server/accounts/rules.test.ts (1 hunks)
- packages/loot-core/src/server/accounts/rules.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/loot-core/src/server/accounts/rules.test.ts (1)
Learnt from: jfdoming PR: actualbudget/actual#3641 File: packages/loot-core/src/server/accounts/rules.test.ts:524-536 Timestamp: 2024-10-12T19:13:25.005Z Learning: In `packages/loot-core/src/server/accounts/rules.test.ts`, prefer explicit action definitions over refactoring similar actions into loops or helper functions, even when actions are similar.
🔇 Additional comments (1)
packages/loot-core/src/server/accounts/rules.test.ts (1)
409-412
: LGTM! Tests align with PR objectives.The added tests verify that date helper functions handle undefined inputs gracefully by returning empty strings. This directly addresses the issue with
{{day today}}
handlebar function mentioned in the PR objectives.
Fixxes an issue that
{{day today}}
wasn't working. As reported in #3606 by @IsThisThingStillOn