Skip to content

Commit

Permalink
refactor: getDayInfo 함수의 인자를 객체 형태로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hwinkr committed Jul 24, 2024
1 parent e7e3d9f commit b29ca25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/hooks/useCalendarInfo/useCalendarInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function useCalendarInfo() {
const { firstDayIndex, daySlotCount } = getYearMonthInfo(year, month);

const handleGetDayInfo = (index: number) => {
return getDayInfo(year, month, firstDayIndex, index, currentDate);
return getDayInfo({ year, month, firstDayIndex, index, currentDate });
};

const handlePrevMonth = () => {
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/hooks/useCalendarInfo/useCalendarInfo.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function getYearMonthInfo(year: number, month: number) {
/*
로직 설명(@해리)
- 월요일을 index 0으로 변경하기 위해서 나머지 연산자를 활용한다.
- 자바스크립트 데이트 객체는 기본적으로 일요일이 인덱스가 0인데, 모모 달력은 월요일을 인덱스를 0으로 만들어줘야 한다.
- 자바스크립트 Date 객체는 기본적으로 일요일이 인덱스가 0인데, 모모 달력은 월요일을 인덱스를 0으로 만들어줘야 한다.
- 따라서, 특정 달의 시작 날짜에 대한 인덱스에 6을 더해주고 7로 나눈 나머지를 사용하는 것으로 구현했다.
*/
const firstDayIndex = (startDate.getDay() + 6) % 7;
Expand All @@ -17,13 +17,19 @@ export function getYearMonthInfo(year: number, month: number) {
return { year, month, firstDayIndex, daySlotCount } as const;
}

export function getDayInfo(
year: number,
month: number,
firstDayIndex: number,
index: number,
currentDate: Date,
) {
export function getDayInfo({
year,
month,
firstDayIndex,
index,
currentDate,
}: {
year: number;
month: number;
firstDayIndex: number;
index: number;
currentDate: Date;
}) {
const date = index - firstDayIndex + 1;
const isDate = index >= firstDayIndex;

Expand Down

0 comments on commit b29ca25

Please sign in to comment.