Skip to content

Commit

Permalink
[fix] 시간 표시 수정 완료 #54
Browse files Browse the repository at this point in the history
  • Loading branch information
HyeongwooIM committed Apr 23, 2023
1 parent c9b2ad3 commit b9e5692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/components/RecentComment/RecentComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export default function RecentComment() {
</div>
<div className={styles.comment}>{data.comment}</div>
<div className={styles.dateTime}>
<>
{getTime(data.time)}
{data.time}</></div>
</div>
</div>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/db/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"subject": "libft",
"star_rating": "5",
"comment": "꾸르르르르르ㅡㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋzㅋ ㅇㄴㅇ ㅁㄴㅇ ㅋㅋㅋㅋㅋㅋ ㅋ ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ ㅋ ㅋㅋㅋㅋㅋㅋㅋ ㅋ ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ르르르잼",
"time": "2023-04-21T06:52:50.622+0000"
"time": "2023-04-10T06:28:50.622+0000"
},
{
"subject": "get_next_line",
Expand Down
34 changes: 20 additions & 14 deletions src/hooks/ConvertTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ import moment from "moment";
import { useEffect } from "react";

interface Time {
title: string;
time: string;
title: string;
time: string;
}

export function ConvertTime(isoTime: Time) {
const now = moment();
const time = moment(isoTime.time);
const diffMinutes = now.diff(time, "minutes");

// useEffect(()=>{
// if (diffMinutes)
// console.log(diffMinutes);
// },[diffMinutes])
console.log(diffMinutes, isoTime.time);

if (diffMinutes < 1) {
return '방금 전';
} else if (diffMinutes < 10) {
let diffMinutes = now.diff(time, "minutes");

// useEffect(()=>{
// if (diffMinutes)
// console.log(diffMinutes);
// },[diffMinutes])
if (isoTime.title === "myPage") {
return time.format("YYYY. MM. DD.");
} else if (diffMinutes < 3) {
return "방금 전";
} else if (diffMinutes < 60) {
return `${diffMinutes}분 전`;
} else if (diffMinutes < 1440) {
diffMinutes = now.diff(time, "hour");
return `${diffMinutes}시간 전`;
} else if (diffMinutes < 10080) {
diffMinutes = now.diff(time, "day");
return `${diffMinutes}일 전`;
} else {
return time.format('YYYY년 MM월 DD일 HH:mm:ss');
return time.format("YYYY. MM. DD.");
}
}

Expand Down

0 comments on commit b9e5692

Please sign in to comment.