Skip to content

Commit

Permalink
fix: resolve invalid date error in validateDate function
Browse files Browse the repository at this point in the history
  • Loading branch information
KumJungMin committed Jan 8, 2025
1 parent fe6ef36 commit 10dfcb4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,21 +1020,28 @@ export const Calendar = React.memo(

const validateDate = (value) => {
if (props.yearNavigator) {
let viewYear = value.getFullYear();
const [minRangeYear, maxRangeYear] = props.yearRange ? props.yearRange.split(':').map((year) => parseInt(year, 10)) : [null, null];

const minRangeYear = props.yearRange ? parseInt(props.yearRange.split(':')[0], 10) : null;
const maxRangeYear = props.yearRange ? parseInt(props.yearRange.split(':')[1], 10) : null;
const minYear = props.minDate && minRangeYear != null ? Math.max(props.minDate.getFullYear(), minRangeYear) : props.minDate || minRangeYear;
const maxYear = props.maxDate && maxRangeYear != null ? Math.min(props.maxDate.getFullYear(), maxRangeYear) : props.maxDate || maxRangeYear;
let viewYear = value.getFullYear();
let minYear = null;
let maxYear = null;

if (minYear && minYear > viewYear) {
viewYear = minYear;
if (minRangeYear !== null) {
minYear = props.minDate ? Math.max(props.minDate.getFullYear(), minRangeYear) : minRangeYear;
} else {
minYear = props.minDate?.getFullYear() || minRangeYear;
}

if (maxYear && maxYear < viewYear) {
viewYear = maxYear;
if (maxRangeYear !== null) {
maxYear = props.maxDate ? Math.min(props.maxDate.getFullYear(), maxRangeYear) : maxRangeYear;
} else {
maxYear = props.maxDate?.getFullYear() || maxRangeYear;
}

if (minYear && minYear > viewYear) viewYear = minYear;

if (maxYear && maxYear < viewYear) viewYear = maxYear;

value.setFullYear(viewYear);
}

Expand Down

0 comments on commit 10dfcb4

Please sign in to comment.