Skip to content

Commit 281a905

Browse files
committed
Fix: timeAgo 함수 타입오류 수정
1 parent dc189f4 commit 281a905

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

util/timAgo.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
function timeAgo(createdAt: string) {
1+
function timeAgo(createdAt: string): string {
22
const createdDate = new Date(createdAt);
33
const currentDate = new Date();
44

5-
const secondsDiff = Math.floor((currentDate - createdDate) / 1000); // 초 단위 차이
6-
const minutesDiff = Math.floor(secondsDiff / 60); // 분 단위 차이
7-
const hoursDiff = Math.floor(minutesDiff / 60); // 시간 단위 차이
8-
const daysDiff = Math.floor(hoursDiff / 24); // 일 단위 차이
5+
const secondsDiff = Math.floor(
6+
(currentDate.getTime() - createdDate.getTime()) / 1000
7+
);
8+
const minutesDiff = Math.floor(secondsDiff / 60);
9+
const hoursDiff = Math.floor(minutesDiff / 60);
10+
const daysDiff = Math.floor(hoursDiff / 24); //
911

1012
if (hoursDiff < 1) {
11-
return `${secondsDiff}초 전`; // 1시간 미만
13+
return `${secondsDiff}초 전`;
1214
} else if (hoursDiff < 24) {
13-
return `${hoursDiff}시간 전`; // 1일 미만
15+
return `${hoursDiff}시간 전`;
1416
} else {
15-
return `${daysDiff}일 전`; // 1일 이상
17+
return `${daysDiff}일 전`;
1618
}
1719
}
1820

0 commit comments

Comments
 (0)