Fix month display in transactions

Corrected the month display in the transactions list to remove the duplicate month number.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-17 23:33:46 +00:00
parent 042965461e
commit d48b866b3a
2 changed files with 11 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
/** /**
* 한글 월 이름 배열 * 한글 월 이름 배열
*/ */
@@ -12,23 +13,21 @@ export const MONTHS_KR = [
export const getCurrentMonth = (): string => { export const getCurrentMonth = (): string => {
const now = new Date(); const now = new Date();
const month = now.getMonth(); // 0-indexed const month = now.getMonth(); // 0-indexed
const monthNumber = now.getMonth() + 1; // 1-indexed return `${MONTHS_KR[month]}`;
return `${MONTHS_KR[month]} ${monthNumber}`;
}; };
/** /**
* 이전 월 가져오기 * 이전 월 가져오기
*/ */
export const getPrevMonth = (currentMonth: string): string => { export const getPrevMonth = (currentMonth: string): string => {
const parts = currentMonth.split(' '); const currentMonthIdx = MONTHS_KR.findIndex(m => m === currentMonth);
const currentMonthIdx = MONTHS_KR.findIndex(m => m === parts[0]);
if (currentMonthIdx === 0) { if (currentMonthIdx === 0) {
// 1월인 경우 12월로 변경 // 1월인 경우 12월로 변경
return `${MONTHS_KR[11]} 12`; return `${MONTHS_KR[11]}`;
} else { } else {
const prevMonthIdx = currentMonthIdx - 1; const prevMonthIdx = currentMonthIdx - 1;
return `${MONTHS_KR[prevMonthIdx]} ${prevMonthIdx + 1}`; return `${MONTHS_KR[prevMonthIdx]}`;
} }
}; };
@@ -36,14 +35,13 @@ export const getPrevMonth = (currentMonth: string): string => {
* 다음 월 가져오기 * 다음 월 가져오기
*/ */
export const getNextMonth = (currentMonth: string): string => { export const getNextMonth = (currentMonth: string): string => {
const parts = currentMonth.split(' '); const currentMonthIdx = MONTHS_KR.findIndex(m => m === currentMonth);
const currentMonthIdx = MONTHS_KR.findIndex(m => m === parts[0]);
if (currentMonthIdx === 11) { if (currentMonthIdx === 11) {
// 12월인 경우 1월로 변경 // 12월인 경우 1월로 변경
return `${MONTHS_KR[0]} 1`; return `${MONTHS_KR[0]}`;
} else { } else {
const nextMonthIdx = currentMonthIdx + 1; const nextMonthIdx = currentMonthIdx + 1;
return `${MONTHS_KR[nextMonthIdx]} ${nextMonthIdx + 1}`; return `${MONTHS_KR[nextMonthIdx]}`;
} }
}; };

View File

@@ -2,6 +2,7 @@
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect } from 'react';
import { Transaction } from '@/components/TransactionCard'; import { Transaction } from '@/components/TransactionCard';
import { FilteringProps } from './types'; import { FilteringProps } from './types';
import { MONTHS_KR } from '../dateUtils';
/** /**
* 거래 필터링 로직 * 거래 필터링 로직
@@ -21,8 +22,8 @@ export const useFilterApplication = ({
console.log('선택된 월:', selectedMonth); console.log('선택된 월:', selectedMonth);
// 선택된 월 정보 파싱 // 선택된 월 정보 파싱
const monthInfo = selectedMonth.split(' '); const selectedMonthName = selectedMonth;
const selectedMonthName = monthInfo[0]; const monthNumber = MONTHS_KR.findIndex(month => month === selectedMonthName) + 1;
// 월별 필터링 // 월별 필터링
let filtered = transactions.filter(transaction => { let filtered = transactions.filter(transaction => {
@@ -39,7 +40,6 @@ export const useFilterApplication = ({
// 오늘 날짜가 해당 월인지 확인 // 오늘 날짜가 해당 월인지 확인
const today = new Date(); const today = new Date();
const currentMonth = today.getMonth() + 1; // 0부터 시작하므로 +1 const currentMonth = today.getMonth() + 1; // 0부터 시작하므로 +1
const monthNumber = parseInt(monthInfo[1] || '0');
return currentMonth === monthNumber; return currentMonth === monthNumber;
} }
@@ -54,7 +54,6 @@ export const useFilterApplication = ({
const date = new Date(transaction.date); const date = new Date(transaction.date);
if (!isNaN(date.getTime())) { if (!isNaN(date.getTime())) {
const transactionMonth = date.getMonth() + 1; const transactionMonth = date.getMonth() + 1;
const monthNumber = parseInt(monthInfo[1] || '0');
return transactionMonth === monthNumber; return transactionMonth === monthNumber;
} }
} catch (e) { } catch (e) {