Fix invalid date error with better date parsing
Improved date parsing in setMinMaxValueDate: - Use moment with multiple format support: ['YYYY.MM', 'YYYYMM'] - Add strict parsing mode with true parameter - Validate date with isValid() before setting - Handles both 'YYYY.MM' and 'YYYYMM' input formats This resolves the invalid date error when selecting year/month. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -44,13 +44,21 @@ const NiceCalendarMonth = ({
|
|||||||
if(calendarType === CalendarType.Start){
|
if(calendarType === CalendarType.Start){
|
||||||
setMinMonth(undefined);
|
setMinMonth(undefined);
|
||||||
if(!!endMonth){
|
if(!!endMonth){
|
||||||
setMaxMonth(moment(endMonth + '.01', 'YYYY.MM.DD').toDate());
|
// Parse endMonth with moment, handling both YYYY.MM and YYYYMM formats
|
||||||
|
const endDate = moment(endMonth, ['YYYY.MM', 'YYYYMM'], true);
|
||||||
|
if (endDate.isValid()) {
|
||||||
|
setMaxMonth(endDate.toDate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setValueYear(startMonth?.substring(0, 4));
|
setValueYear(startMonth?.substring(0, 4));
|
||||||
}
|
}
|
||||||
else if(calendarType === CalendarType.End){
|
else if(calendarType === CalendarType.End){
|
||||||
if(!!startMonth){
|
if(!!startMonth){
|
||||||
setMinMonth(moment(startMonth + '.01', 'YYYY.MM.DD').toDate());
|
// Parse startMonth with moment, handling both YYYY.MM and YYYYMM formats
|
||||||
|
const startDate = moment(startMonth, ['YYYY.MM', 'YYYYMM'], true);
|
||||||
|
if (startDate.isValid()) {
|
||||||
|
setMinMonth(startDate.toDate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setMaxMonth(new Date());
|
setMaxMonth(new Date());
|
||||||
setValueYear(endMonth?.substring(0, 4));
|
setValueYear(endMonth?.substring(0, 4));
|
||||||
|
|||||||
Reference in New Issue
Block a user