Skip to content

Commit

Permalink
feat: 지난 시간을 텍스트로 반환하는 유틸함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
happyGyu committed Jun 29, 2024
1 parent b8acde3 commit dea334b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@tanstack/react-router": "^1.38.1",
"axios": "^1.7.2",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"jotai": "^2.8.3",
"js-cookie": "^3.0.5",
"react": "19.0.0-beta-26f2496093-20240514",
Expand Down
63 changes: 39 additions & 24 deletions pnpm-lock.yaml

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

19 changes: 19 additions & 0 deletions src/utils/getPassedTimeText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import dayjs from "dayjs";

export const getPassedTimeText = (date: string): string => {
const now = dayjs();
const inputDate = dayjs(date);

const diff = now.diff(inputDate, "minute");

if (diff < 1) {
return "방금 전";
}
if (diff < 60) {
return `${diff}분 전`;
}
if (diff < 60 * 24) {
return `${Math.round(diff / 60)}시간 전`;
}
return `${Math.round(diff / 60 / 24)}일 전`;
};

0 comments on commit dea334b

Please # to comment.