fix(lit, angular): correct DateTimeInput month indexing [Issue #566]#568
fix(lit, angular): correct DateTimeInput month indexing [Issue #566]#568shantoislamdev wants to merge 4 commits intogoogle:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where DateTimeInput components were using 0-indexed months, causing date inputs to appear empty. The fix is applied consistently to both the Lit and Angular renderers by adding 1 to the result of date.getMonth(). The changes are clear, correct, and include explanatory comments. The code quality is good, and I have no further suggestions for improvement.
|
While this PR fixes the primary date formatting bug, it doesn’t yet address the parsing of time-only values. JavaScript's To resolve this, we should add an early exit in Suggested Changes (to be applied to both Lit and Angular components): // If it's a time-only input, return the value directly to avoid unreliable Date parsing
if (this.getInputType() === 'time' && /^\d{2}:\d{2}(:\d{2})?$/.test(value)) {
return value;
}
const date = value ? new Date(value) : null;
// ... rest of the logicWhat are your thoughts on this approach? |
Summary
Fix
DateTimeInputcomponent in both Lit and Angular renderers to use 1-indexed months (01-12) instead of 0-indexed months (00-11) for the HTML date input value.Fixes #566
Problem
The
DateTimeInputcomponent incorrectly formatted thevalueattribute for<input type="date">by usingdate.getMonth()directly (which is 0-indexed).Impact:
2025-00-01.Solution
Updated the date formatting logic in both renderers:
renderers/lit/src/0.8/ui/datetime-input.ts- Line:137-138renderers/angular/src/lib/catalog/datetime-input.ts- Line97-98Change:
Testing
Checklist