-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: useGetTimeAgo 훅 분리 & 드롭다운 스크롤바 제어
- Loading branch information
Showing
4 changed files
with
65 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default function getTimeAgoString(updatedAt: string): string { | ||
const updatedAtUTC = Date.parse(updatedAt); | ||
const now = new Date(); | ||
const diff = now.getTime() - updatedAtUTC; | ||
const seconds = Math.floor(diff / 1000); | ||
const minutes = Math.floor(seconds / 60); | ||
const hours = Math.floor(minutes / 60); | ||
const days = Math.floor(hours / 24); | ||
|
||
if (days > 0) { | ||
return `${days}일 전`; | ||
} else if (hours > 0) { | ||
return `${hours}시간 전`; | ||
} else if (minutes > 0) { | ||
return `${minutes}분 전`; | ||
} else { | ||
return `방금 전`; | ||
} | ||
} |