This commit is contained in:
focp212@naver.com
2025-11-12 18:16:19 +09:00
parent bfcb63681f
commit 2abf0ebab4
2 changed files with 31 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ interface NiceCalendarProps {
endMonth?: string;
singleMonth?: string;
calendarType: CalendarType;
setNewMonth: (month: string) => void;
setNewMonth: (month: string, calendarType: CalendarType) => void;
searchPeriod?: number;
periodType?: 'year' | 'month';
};
@@ -37,8 +37,28 @@ const NiceCalendarMonth = ({
const [valueMonth, setValueMonth] = useState<Date | undefined>();
const [minMonth, setMinMonth] = useState<Date | undefined>();
const [maxMonth, setMaxMonth] = useState<Date | undefined>();
const [calendarSearchPeriod, setCalendatSearchPeriod] = useState<number>(searchPeriod || 2);
const [calendarPeriodType, setCalendarPeriodType] = useState<'year' | 'month'>(periodType || 'year');
const onChangeToMonth = (selectedMonth: any) => {
setNewMonth(moment(selectedMonth).format('YYYY.MM'));
if(calendarType === CalendarType.Start){
if(endMonth){
let newEndDateLimit = moment(selectedMonth).add(calendarSearchPeriod, calendarPeriodType).format('YYYYMM');
if(moment(endMonth).format('YYYYMM') > newEndDateLimit){
setNewMonth(moment(newEndDateLimit).format('YYYY.MM'), CalendarType.End);
}
}
}
else if(calendarType === CalendarType.End){
if(startMonth){
let newStartDateLimit = moment(selectedMonth).subtract(calendarSearchPeriod, calendarPeriodType).format('YYYYMM');
if(moment(startMonth).format('YYYYMM') < newStartDateLimit){
setNewMonth(moment(newStartDateLimit).format('YYYY.MM'), CalendarType.Start);
}
}
}
setNewMonth(moment(selectedMonth).format('YYYY.MM'), calendarType);
setCalendarOpen(false);
};
@@ -47,19 +67,8 @@ const NiceCalendarMonth = ({
};
const setMinMaxValueDate = () => {
if(calendarType === CalendarType.Start){
if(!searchPeriod){
searchPeriod = 3;
}
if(!periodType){
periodType = 'year';
}
if(periodType && searchPeriod && searchPeriod > 0){
const endDate = moment(endMonth, ['YYYY.MM', 'YYYYMM'], true);
setMinMonth(moment(endDate, 'YYYY.MM.DD').subtract(searchPeriod, periodType).toDate());
}
// setMinMonth(undefined);
setMinMonth(undefined);
if(!!endMonth){
// 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());
@@ -70,7 +79,8 @@ const NiceCalendarMonth = ({
if (startDate.isValid()) {
setValueMonth(startDate.toDate());
}
} else {
}
else{
setValueMonth(undefined);
}
}
@@ -88,7 +98,8 @@ const NiceCalendarMonth = ({
if(endDate.isValid()){
setValueMonth(endDate.toDate());
}
} else {
}
else{
setValueMonth(undefined);
}
}

View File

@@ -65,9 +65,7 @@ export const FilterCalendarMonth = ({
}
};
const setNewMonth = (month: string) => {
console.log(month)
// month is already in 'YYYY.MM' format from NiceCalendarMonth
const setNewMonth = (month: string, calendarType: CalendarType) => {
const parsedMonth = moment(month, 'YYYY.MM', true);
if (parsedMonth.isValid()) {
if(calendarType === CalendarType.Start){