From ba702e94ccf7bdceed28bdc884da60ed63dd7655 Mon Sep 17 00:00:00 2001 From: rwaeng Date: Wed, 22 Jan 2025 23:26:57 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20eslint=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=82=AD=EC=A0=9C=20=ED=9B=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20(#255)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/formatters.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils/formatters.ts b/src/utils/formatters.ts index 9587ef6..3a36d97 100644 --- a/src/utils/formatters.ts +++ b/src/utils/formatters.ts @@ -80,8 +80,17 @@ export const formatChatItemTime = (date: string) => { const hour = Number(hourStr); const period = hour < 12 ? '오전' : '오후'; - // eslint-disable-next-line no-nested-ternary - const formattedHour = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour; + + let formattedHour; + + if (hour === 0) { + formattedHour = 12; + } else if (hour > 12) { + formattedHour = hour - 12; + } else { + formattedHour = hour; + } + return `${period} ${formattedHour}:${minute}`; }; @@ -90,21 +99,14 @@ export const formatChatListItemTime = (date: string) => { const today = new Date(); const targetDate = new Date(datePart); - if ( - targetDate.getFullYear() === today.getFullYear() && - targetDate.getMonth() === today.getMonth() && - targetDate.getDate() === today.getDate() - ) { + + if (targetDate.toDateString() === today.toDateString()) { return formatChatItemTime(timePart); } const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); - if ( - targetDate.getFullYear() === yesterday.getFullYear() && - targetDate.getMonth() === yesterday.getMonth() && - targetDate.getDate() === yesterday.getDate() - ) { + if (targetDate.toDateString() === yesterday.toDateString()) { return '어제'; }