feat: format play time in hours

This commit is contained in:
Zamitto 2024-05-01 17:38:46 -03:00
parent f38f574d04
commit 1569c3eb73

View file

@ -62,12 +62,22 @@ export function HeroPanel({
const interval = setInterval(() => { const interval = setInterval(() => {
updateLastTimePlayed(); updateLastTimePlayed();
}, 1000); }, 1000);
const formatPlayTime = (milliseconds: number) => {
const seconds = milliseconds / 1000
const minutes = seconds / 60
return () => { return () => {
clearInterval(interval); clearInterval(interval);
}; };
} }
}, [game?.lastTimePlayed, updateLastTimePlayed]); }, [game?.lastTimePlayed, updateLastTimePlayed]);
if (minutes < 120) {
return minutes.toFixed(0) + " " + t("minutes")
}
const hours = minutes / 60
return hours.toFixed(0) + " " + t("hours")
}
const finalDownloadSize = useMemo(() => { const finalDownloadSize = useMemo(() => {
if (!game) return "N/A"; if (!game) return "N/A";
@ -136,7 +146,7 @@ export function HeroPanel({
<> <>
<p> <p>
{t("play_time", { {t("play_time", {
amount: formatDistance(0, game.playTimeInMilliseconds), amount: formatPlayTime(game.playTimeInMilliseconds),
})} })}
</p> </p>