Skip to content

Commit b44f566

Browse files
committed
localized utils
1 parent b1a5840 commit b44f566

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

web/src/common/utils/elapsed-time.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
export const elapsedTime = (time: string | number | Date) => {
1+
export const elapsedTime = (time: string | number | Date, localizedSuffixes: string) => {
22
const timePassed = new Date().getTime() - new Date(time).getTime();
33
const years = Math.floor(timePassed / 31536000000);
44
const months = Math.floor((timePassed - years * 31536000000) / 2628000000);
55
const days = Math.floor((timePassed - months * 2628000000) / 86400000);
66
const hours = Math.floor((timePassed - days * 86400000) / 3600000);
77
const minutes = Math.floor((timePassed - hours * 3600000) / 60000);
8+
const [year, month, day, hour, minute, now] = localizedSuffixes.split("|");
89

910
return `${
1011
years > 0
11-
? `${years}y`
12+
? `${years}${year}`
1213
: `${
1314
months > 0
14-
? `${months}mo`
15+
? `${months}${month}`
1516
: `${
1617
days > 0
17-
? `${days}d`
18-
: `${hours > 0 ? `${hours}h` : `${minutes > 0 ? `${minutes}min` : "just now"}`}`
18+
? `${days}${day}`
19+
: `${
20+
hours > 0 ? `${hours}${hour}` : `${minutes > 0 ? `${minutes}${minute}` : now}`
21+
}`
1922
}`
2023
}`
2124
}`;

0 commit comments

Comments
 (0)