날짜 필터 캘린더 Invalid Date 오류 수정
react-calendar에 전달되는 날짜 문자열('YYYY.MM.DD' 형식)을 moment를 사용하여 명시적으로 파싱하도록 수정하여 Invalid Date 에러 해결
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -29,7 +29,7 @@ const NiceCalendar = ({
|
|||||||
minDate: propMinDate,
|
minDate: propMinDate,
|
||||||
maxDate: propMaxDate
|
maxDate: propMaxDate
|
||||||
}: NiceCalendarProps) => {
|
}: NiceCalendarProps) => {
|
||||||
const [valueDate, setValueDate] = useState<string>();
|
const [valueDate, setValueDate] = useState<Date | undefined>();
|
||||||
const [minDate, setMinDate] = useState<Date | undefined>();
|
const [minDate, setMinDate] = useState<Date | undefined>();
|
||||||
const [maxDate, setMaxDate] = useState<Date | undefined>();
|
const [maxDate, setMaxDate] = useState<Date | undefined>();
|
||||||
const onchangeToDate = (selectedDate: any) => {
|
const onchangeToDate = (selectedDate: any) => {
|
||||||
@@ -44,21 +44,21 @@ const NiceCalendar = ({
|
|||||||
if(calendarType === CalendarType.Start){
|
if(calendarType === CalendarType.Start){
|
||||||
setMinDate(propMinDate || undefined);
|
setMinDate(propMinDate || undefined);
|
||||||
if(!!endDate){
|
if(!!endDate){
|
||||||
setMaxDate(new Date(endDate));
|
setMaxDate(moment(endDate, 'YYYY.MM.DD').toDate());
|
||||||
}
|
}
|
||||||
setValueDate(startDate);
|
setValueDate(startDate ? moment(startDate, 'YYYY.MM.DD').toDate() : undefined);
|
||||||
}
|
}
|
||||||
else if(calendarType === CalendarType.End){
|
else if(calendarType === CalendarType.End){
|
||||||
if(!!startDate){
|
if(!!startDate){
|
||||||
setMinDate(new Date(startDate));
|
setMinDate(moment(startDate, 'YYYY.MM.DD').toDate());
|
||||||
}
|
}
|
||||||
setMaxDate(propMaxDate || new Date());
|
setMaxDate(propMaxDate || new Date());
|
||||||
setValueDate(endDate);
|
setValueDate(endDate ? moment(endDate, 'YYYY.MM.DD').toDate() : undefined);
|
||||||
}
|
}
|
||||||
else if(calendarType === CalendarType.Single){
|
else if(calendarType === CalendarType.Single){
|
||||||
setMinDate(propMinDate || undefined);
|
setMinDate(propMinDate || undefined);
|
||||||
setMaxDate(propMaxDate || undefined);
|
setMaxDate(propMaxDate || undefined);
|
||||||
setValueDate(singleDate);
|
setValueDate(singleDate ? moment(singleDate, 'YYYY.MM.DD').toDate() : undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -74,12 +74,12 @@ export const FilterCalendar = ({
|
|||||||
|
|
||||||
const setNewDate = (date: string) => {
|
const setNewDate = (date: string) => {
|
||||||
if(calendarType === CalendarType.Start){
|
if(calendarType === CalendarType.Start){
|
||||||
setStartDate(moment(date).format('YYYYMMDD'));
|
setStartDate(moment(date, 'YYYY.MM.DD').format('YYYYMMDD'));
|
||||||
setNewStartDate(moment(date).format('YYYY.MM.DD'));
|
setNewStartDate(moment(date, 'YYYY.MM.DD').format('YYYY.MM.DD'));
|
||||||
}
|
}
|
||||||
else if(calendarType === CalendarType.End){
|
else if(calendarType === CalendarType.End){
|
||||||
setEndDate(moment(date).format('YYYYMMDD'));
|
setEndDate(moment(date, 'YYYY.MM.DD').format('YYYYMMDD'));
|
||||||
setNewEndDate(moment(date).format('YYYY.MM.DD'));
|
setNewEndDate(moment(date, 'YYYY.MM.DD').format('YYYY.MM.DD'));
|
||||||
}
|
}
|
||||||
setCalendarOpen(false);
|
setCalendarOpen(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user