코드 정리 - 게시물 시간.

이재근·2022년 8월 18일
0

-코멘트의 경우.
for (let i = 0; i < commentInfo.length; i++) {
let comment = commentInfo[i];
const writtenTime = Date.parse(comment.createdAt);
const timeNow = Date.parse(Date());
const diff = timeNow - writtenTime;

if (diff > 1123200000) {
} else {
const times = [
{ time: "분", milliSeconds: 1000 60 },
{ time: "시간", milliSeconds: 1000
60 60 },
{ time: "일", milliSeconds: 1000
60 60 24 },
{ time: "주", milliSeconds: 1000 60 60 24 7 },
].reverse();

for (const value of times) {
  const betweenTime = Math.floor(diff / value.milliSeconds);
  if (betweenTime > 0) {
    comment = {
      userId: comment.userId,
      commentId: comment.commentId,
      comment: comment.comment,
      userImageURL: comment.user.userImageURL,
      nickname: comment.user.nickname,
      createdAt: betweenTime + value.time + "전",
    };
    commentInfo[i] = comment;
    break;
  } else {
    Review = {
      userId: comment.userId,
      commentId: comment.commentId,
      comment: comment.comment,
      userImageURL: comment.user.userImageURL,
      nickname: comment.user.nickname,
      createdAt: "방금 전",
    };
    commentInfo[i] = comment;
  }
  
  -
profile
하루 고생하면 코드가 나 대신 일해준다.

0개의 댓글