Fix timer

fixes #66
This commit is contained in:
2023-08-28 12:17:24 +01:00
parent 8509f08dd6
commit 9bbbd513c2

View File

@ -9,9 +9,13 @@ export function StreamTimer({ ev }: { ev?: NostrEvent }) {
function updateTime() { function updateTime() {
const starts = Number(findTag(ev, "starts") ?? unixNow()); const starts = Number(findTag(ev, "starts") ?? unixNow());
const diff = unixNow() - starts; const diff = unixNow() - starts;
const hours = Number(diff / 60.0 / 60.0); const min = 60;
const mins = Number((diff / 60) % 60); const hour = min * 60;
setTime(`${hours.toFixed(0).padStart(2, "0")}:${mins.toFixed(0).padStart(2, "0")}`);
const hours = Math.floor(diff / hour);
const mins = Math.floor((diff % hour) / min);
const secs = Math.floor(diff % min);
setTime(`${hours.toFixed(0).padStart(2, "0")}:${mins.toFixed(0).padStart(2, "0")}:${secs.toFixed(0).padStart(2, "0")}`);
} }
useEffect(() => { useEffect(() => {