Skip to content

Commit

Permalink
feat(new-hope): edit calendar range logic and fix name
Browse files Browse the repository at this point in the history
feat(new-hope): calender utils startDay check
  • Loading branch information
iljs committed Mar 6, 2024
1 parent 09c34c7 commit 7bc0c67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getOffsetDayInWeek,
getPrevDate,
IsCurrentDay,
isDayInRage,
isDayInRange,
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
10 changes: 3 additions & 7 deletions packages/plasma-new-hope/src/components/Calendar/utils/index.ts
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

0 comments on commit 7bc0c67

Please sign in to comment.