Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-hope): edit calendar range logic and fix name #1084

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getOffsetDayInWeek,
getPrevDate,
IsCurrentDay,
isDayInRage,
isDayInRange,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

isSelectedDay,
} from '../utils';
import type { CalendarValueType, DateItem, DateObject, DisabledDay, EventDay } from '../Calendar.types';
Expand All @@ -25,7 +25,7 @@ const getDaysInPrevMonth = (date: DateObject, offsetDayInWeek: number, value: Ca
isSelected: false,
isDayInCurrentMonth: false,
inRange: Array.isArray(value)
? isDayInRage(prevYear, prevMonth, daysInPrevMonth - (offsetDayInWeek - i) + 1, value)
? isDayInRange(prevYear, prevMonth, daysInPrevMonth - (offsetDayInWeek - i) + 1, value)
: false,
date: {
day: daysInPrevMonth - (offsetDayInWeek - i) + 1,
Expand All @@ -45,7 +45,7 @@ const getDaysInCurrentMonth = (date: DateObject, daysInMonth: number, value: Cal
? Boolean(value.find((v) => isSelectedDay(date, i + 1, v)))
: isSelectedDay(date, i + 1, value),
isDayInCurrentMonth: true,
inRange: Array.isArray(value) ? isDayInRage(date.year, date.monthIndex, i + 1, value) : false,
inRange: Array.isArray(value) ? isDayInRange(date.year, date.monthIndex, i + 1, value) : false,
date: {
day: i + 1,
monthIndex: date.monthIndex,
Expand All @@ -71,7 +71,7 @@ const getDaysInNextMonth = (
isCurrent: false,
isSelected: false,
isDayInCurrentMonth: false,
inRange: Array.isArray(value) ? isDayInRage(nextYear, nextMonthIndex, i + 1, value) : false,
inRange: Array.isArray(value) ? isDayInRange(nextYear, nextMonthIndex, i + 1, value) : false,
date: {
day: i + 1,
monthIndex: nextMonthIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ export const getSortedValues = (values: [Date | undefined, (Date | undefined)?])
return start.getTime() - end.getTime();
});

export const isDayInRage = (
export const isDayInRange = (
year: number,
monthIndex: number,
currentDay: number,
values: [Date | undefined, Date?],
) => {
const [startValue, endValue] = getSortedValues(values);

if (!endValue) {
if (!endValue || !startValue) {
return false;
}

const day = new Date(year, monthIndex, currentDay);
return startValue && startValue <= day && day <= endValue;
return startValue < day && day <= endValue;
};

export const isSameDay = (firstDate: DateObject, secondDate?: DateObject) =>
Expand Down Expand Up @@ -243,10 +243,6 @@ export const canSelectDate = (
const hoverDate = new Date(year, monthIndex, day);
const [startDate] = value;

if (hoverDate?.getTime() === startDate?.getTime()) {
return false;
}

if (!disabledList?.length) {
return true;
}
Expand Down
Loading