From 81f517bfb62fa197c42d2a596e7ec71dfb2f7f09 Mon Sep 17 00:00:00 2001 From: MaoriSL Date: Thu, 9 Oct 2025 13:49:20 +0200 Subject: [PATCH] fix timer --- app/Models/Timer.php | 4 ++-- resources/js/components/Timer.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Models/Timer.php b/app/Models/Timer.php index 28be59c..2da3523 100644 --- a/app/Models/Timer.php +++ b/app/Models/Timer.php @@ -32,10 +32,10 @@ public function start(): void Message::truncate(); $this->update([ - 'startTime' => now(), + 'startTime' => now()->addHours(2), 'isStarted' => true, 'isExpired' => false, - 'shouldEnd' => now()->addMinutes($this->duration / 60), + 'shouldEnd' => now()->addHours(2)->addMinutes($this->duration / 60), ]); } diff --git a/resources/js/components/Timer.tsx b/resources/js/components/Timer.tsx index 1384c83..c108c13 100644 --- a/resources/js/components/Timer.tsx +++ b/resources/js/components/Timer.tsx @@ -16,9 +16,10 @@ export default function Timer() { const [isStarted, setIsStarted] = useState(timer?.isStarted || false); const calculateTimeRemaining = (shouldEnd: string): number => { - const endTime = new Date(shouldEnd).getTime(); + const endTime = new Date(shouldEnd); + endTime.setHours(endTime.getHours() - 2); // Soustraire 2 heures const currentTime = new Date().getTime(); - const remaining = Math.max(0, Math.floor((endTime - currentTime) / 1000)); + const remaining = Math.max(0, Math.floor((endTime.getTime() - currentTime) / 1000)); return remaining; }; @@ -30,8 +31,7 @@ export default function Timer() { setTimer(timerData); if (timerData && timerData.shouldEnd) { - // ✅ Calculer le temps restant basé sur shouldEnd - const remaining = calculateTimeRemaining(timerData.shouldEnd); + const remaining = calculateTimeRemaining(timerData); setTimeRemaining(remaining); setIsStarted(timerData.isStarted && remaining > 0); }