Skip to content

Commit ebc8223

Browse files
wip
1 parent 826e291 commit ebc8223

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

frontend/src/hooks/useElapsedTime.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
import { useMemo } from "react";
2-
32
import { useTranslation } from "react-i18next";
43

5-
const NOW = new Date();
6-
7-
const formatTooltip = (date: Date) =>
8-
date
9-
.toLocaleString("fr-FR", {
10-
day: "2-digit",
11-
month: "2-digit",
12-
year: "2-digit",
13-
hour: "2-digit",
14-
minute: "2-digit",
15-
second: "2-digit",
16-
})
17-
.replace(",", "");
18-
19-
const formatDate = (date: Date) =>
20-
date.toLocaleString("fr-FR", {
21-
day: "2-digit",
22-
month: "2-digit",
23-
year: "2-digit",
24-
});
25-
264
export const useElapsedTime = (dateString: string) => {
275
const { t } = useTranslation("magneto");
286

297
return useMemo(() => {
308
const date = new Date(dateString);
31-
const diffInSeconds = Math.floor((NOW.getTime() - date.getTime()) / 1000);
32-
const tooltip = formatTooltip(date);
9+
const now = new Date();
10+
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
11+
12+
if (dateString) {
13+
console.log("outside===============");
14+
console.log("date");
15+
console.log(dateString);
16+
console.log(date);
17+
console.log("getTime", date.getTime());
18+
console.log("now");
19+
console.log(now);
20+
console.log("toLocaleString", now.toLocaleString());
21+
console.log("valueOf", now.valueOf());
22+
console.log("getTime", now.getTime());
23+
}
3324

25+
const tooltip = date
26+
.toLocaleString("fr-FR", {
27+
day: "2-digit",
28+
month: "2-digit",
29+
year: "2-digit",
30+
hour: "2-digit",
31+
minute: "2-digit",
32+
second: "2-digit",
33+
})
34+
.replace(",", "");
3435
if (diffInSeconds < 60) {
3536
return {
3637
label:
@@ -40,7 +41,6 @@ export const useElapsedTime = (dateString: string) => {
4041
tooltip,
4142
};
4243
}
43-
4444
if (diffInSeconds < 3600) {
4545
const diffInMinutes = Math.floor(diffInSeconds / 60);
4646
return {
@@ -51,7 +51,6 @@ export const useElapsedTime = (dateString: string) => {
5151
tooltip,
5252
};
5353
}
54-
5554
if (diffInSeconds < 86400) {
5655
const diffInHours = Math.floor(diffInSeconds / 3600);
5756
return {
@@ -62,16 +61,18 @@ export const useElapsedTime = (dateString: string) => {
6261
tooltip,
6362
};
6463
}
65-
6664
if (diffInSeconds < 172800) {
6765
return {
6866
label: t("magneto.card.time.yesterday"),
6967
tooltip,
7068
};
7169
}
72-
7370
return {
74-
label: formatDate(date),
71+
label: date.toLocaleString("fr-FR", {
72+
day: "2-digit",
73+
month: "2-digit",
74+
year: "2-digit",
75+
}),
7576
tooltip,
7677
};
7778
}, [dateString]);

0 commit comments

Comments
 (0)