Skip to content

Commit

Permalink
feat/BibimMandu-IssueTacker#146: 시간 차이를 구하는 함수 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
qkdflrgs committed Aug 10, 2023
1 parent 051561c commit cf23a41
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions FE/src/utils/calculateTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function calculateTime(createdAt: string): string {
const createdTime = new Date(Date.parse(createdAt));
const currentTime = new Date();
const timeDifference = currentTime.getTime() - createdTime.getTime();
const minutes = Math.floor(timeDifference / (1000 * 60));

if (minutes < 1) {
return "방금 전";
} else if (minutes < 60) {
return `${minutes}분 전`;
} else if (minutes < 1440) {
const hours = Math.floor(minutes / 60);
return `${hours}시간 전`;
} else {
const days = Math.floor(minutes / 1440);
return `${days}일 전`;
}
}

0 comments on commit cf23a41

Please sign in to comment.