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:
Jay Sheen
2025-10-31 18:29:11 +09:00
parent 3fd7b7c058
commit d9af3ef407

View File

@@ -44,13 +44,21 @@ const NiceCalendarMonth = ({
if(calendarType === CalendarType.Start){
setMinMonth(undefined);
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));
}
else if(calendarType === CalendarType.End){
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());
setValueYear(endMonth?.substring(0, 4));