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 => {
const now = new Date();
const month = now.getMonth(); // 0-indexed
const monthNumber = now.getMonth() + 1; // 1-indexed
return `${MONTHS_KR[month]} ${monthNumber}`;
return `${MONTHS_KR[month]}`;
};
/**
* 이전 월 가져오기
*/
export const getPrevMonth = (currentMonth: string): string => {
const parts = currentMonth.split(' ');
const currentMonthIdx = MONTHS_KR.findIndex(m => m === parts[0]);
const currentMonthIdx = MONTHS_KR.findIndex(m => m === currentMonth);
if (currentMonthIdx === 0) {
// 1월인 경우 12월로 변경
return `${MONTHS_KR[11]} 12`;
return `${MONTHS_KR[11]}`;
} else {
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 => {
const parts = currentMonth.split(' ');
const currentMonthIdx = MONTHS_KR.findIndex(m => m === parts[0]);
const currentMonthIdx = MONTHS_KR.findIndex(m => m === currentMonth);
if (currentMonthIdx === 11) {
// 12월인 경우 1월로 변경
return `${MONTHS_KR[0]} 1`;
return `${MONTHS_KR[0]}`;
} else {
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 { Transaction } from '@/components/TransactionCard';
import { FilteringProps } from './types';
import { MONTHS_KR } from '../dateUtils';
/**
* 거래 필터링 로직
@@ -21,8 +22,8 @@ export const useFilterApplication = ({
console.log('선택된 월:', selectedMonth);
// 선택된 월 정보 파싱
const monthInfo = selectedMonth.split(' ');
const selectedMonthName = monthInfo[0];
const selectedMonthName = selectedMonth;
const monthNumber = MONTHS_KR.findIndex(month => month === selectedMonthName) + 1;
// 월별 필터링
let filtered = transactions.filter(transaction => {
@@ -39,7 +40,6 @@ export const useFilterApplication = ({
// 오늘 날짜가 해당 월인지 확인
const today = new Date();
const currentMonth = today.getMonth() + 1; // 0부터 시작하므로 +1
const monthNumber = parseInt(monthInfo[1] || '0');
return currentMonth === monthNumber;
}
@@ -54,7 +54,6 @@ export const useFilterApplication = ({
const date = new Date(transaction.date);
if (!isNaN(date.getTime())) {
const transactionMonth = date.getMonth() + 1;
const monthNumber = parseInt(monthInfo[1] || '0');
return transactionMonth === monthNumber;
}
} catch (e) {