diff --git a/src/common/util/date.tsx b/src/common/util/date.tsx index 9980acb..d88e37a 100644 --- a/src/common/util/date.tsx +++ b/src/common/util/date.tsx @@ -14,6 +14,25 @@ export const dateToKorean = (date: Date) => { + outputDate.getDate() + '일'; } +export const relativeDateToKorean = (date: Date) => { + const outputDate = new Date(date); + const now = new Date(); + + const diffHours = now.getHours() - outputDate.getHours(); + + if (diffHours < 0) { + return dateToKorean(date); + } else if (diffHours < 1) { + return `방금 전`; + } else if (diffHours < 24) { + return `${diffHours}시간 전`; + } else if (diffHours < 24 * 7) { + return `${diffHours / 24}일 전`; + } else { + return dateToKorean(date); + } +} + export const shortDateToKorean = (date: Date) => { const outputDate = new Date(date); return (outputDate.getMonth() + 1) + '월 ' diff --git a/src/components/blog/BlogSideBar.tsx b/src/components/blog/BlogSideBar.tsx index be55dd6..e847b7f 100644 --- a/src/components/blog/BlogSideBar.tsx +++ b/src/components/blog/BlogSideBar.tsx @@ -23,12 +23,12 @@ function BlogSideBar({folders, tags, username, profileUrl, selectedFolder, setSe return (
- - "{selectedFolder?.title}" 폴더를 이동할 곳을 골라주세요. -
- - {folders.map(folder => ( - - ))} -+
{comment.member.username}
-- {fullDateToKorean(comment.createdAt)} +
+ {relativeDateToKorean(comment.createdAt)}