Skip to content

Commit

Permalink
fix : fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
moana16 committed May 17, 2023
1 parent c961470 commit ad73bd2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"autoprefixer": "^10.4.14",
"axios": "^1.4.0",
"date-fns": "^2.30.0",
"qs": "^6.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
28 changes: 27 additions & 1 deletion src/popup/components/VideoList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from 'react';
import { sampleVideoList } from './sample';
import { formatDistanceToNow,isToday } from 'date-fns';
import ko from 'date-fns/locale/ko';
export interface VideoListDto {
videoId: string
title: string
Expand Down Expand Up @@ -51,6 +53,30 @@ const VideoComponent = ({
}
setIsHovered(false);
};

const targetDate = Date.parse(publishedAt);
const distanceInWords = formatDistanceToNow(targetDate,{locale : ko});
const now = new Date();

// if (isToday(targetDate)) {
// const hours = Math.floor((now.getTime() - targetDate.getTime()) / (1000 * 60 * 60));
// if (hours > 0) {
// distanceInWords = `${hours}시간 전`;
// }
// }

let formattedTime = distanceInWords + ' 전';

if (distanceInWords.includes('일')) {
const days = parseInt(distanceInWords, 10);
if (days >= 30) {
const months = Math.floor(days / 30);
formattedTime = `${months}개월 전`;
}

}



return (
<div
Expand Down Expand Up @@ -91,7 +117,7 @@ const VideoComponent = ({
<div>
<p className="text-[14px] cursor-pointer leading-6 mb-2">{channelTitle}</p>
<p className="text-[14px] cursor-pointer leading-5">
조회수 {/*{views}*/} · {publishedAt}
조회수 {/*{views}*/} · {formattedTime}
</p>
</div>
</div>
Expand Down

0 comments on commit ad73bd2

Please sign in to comment.