Skip to content

Commit f047ddd

Browse files
committed
[#146] feat: 시간 경과 계산 함수 생성
1 parent 7049fc1 commit f047ddd

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

frontend/src/utils/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
export { fetchDummyData } from './fetchDummyData';
2-
export {
3-
validateType,
4-
fontSize,
5-
placeHolder,
6-
listComponent,
7-
} from './blockContent';
2+
export * from './blockContent';
83
export * from './debounce';
94
export * from './fetchApi';
105
export * from './blockApis';
116
export * from './pageApis';
7+
export * from './time';

frontend/src/utils/time.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const timeSince = (date: Date) => {
2+
const seconds = Math.floor((+new Date() - +date) / 1000);
3+
4+
let interval = seconds / 31536000;
5+
6+
if (interval > 1) {
7+
return `${Math.floor(interval)} years`;
8+
}
9+
interval = seconds / 2592000;
10+
if (interval > 1) {
11+
return `${Math.floor(interval)} months`;
12+
}
13+
interval = seconds / 86400;
14+
if (interval > 1) {
15+
return `${Math.floor(interval)} days`;
16+
}
17+
interval = seconds / 3600;
18+
if (interval > 1) {
19+
return `${Math.floor(interval)} hours`;
20+
}
21+
interval = seconds / 60;
22+
if (interval > 1) {
23+
return `${Math.floor(interval)} minutes`;
24+
}
25+
return `${Math.floor(seconds)} seconds`;
26+
};

0 commit comments

Comments
 (0)