From 81f517bfb62fa197c42d2a596e7ec71dfb2f7f09 Mon Sep 17 00:00:00 2001 From: MaoriSL Date: Thu, 9 Oct 2025 13:49:20 +0200 Subject: [PATCH 1/2] 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); } From cbd3b515f452c28e8e42e4d82554ee623f53ff03 Mon Sep 17 00:00:00 2001 From: MaoriSL Date: Thu, 9 Oct 2025 14:03:34 +0200 Subject: [PATCH 2/2] fix timer --- app/Models/Timer.php | 4 ++-- resources/js/components/Timer.tsx | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/Models/Timer.php b/app/Models/Timer.php index 2da3523..28be59c 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()->addHours(2), + 'startTime' => now(), 'isStarted' => true, 'isExpired' => false, - 'shouldEnd' => now()->addHours(2)->addMinutes($this->duration / 60), + 'shouldEnd' => now()->addMinutes($this->duration / 60), ]); } diff --git a/resources/js/components/Timer.tsx b/resources/js/components/Timer.tsx index c108c13..af76469 100644 --- a/resources/js/components/Timer.tsx +++ b/resources/js/components/Timer.tsx @@ -16,10 +16,9 @@ export default function Timer() { const [isStarted, setIsStarted] = useState(timer?.isStarted || false); const calculateTimeRemaining = (shouldEnd: string): number => { - const endTime = new Date(shouldEnd); - endTime.setHours(endTime.getHours() - 2); // Soustraire 2 heures + const endTime = new Date(shouldEnd).getTime(); const currentTime = new Date().getTime(); - const remaining = Math.max(0, Math.floor((endTime.getTime() - currentTime) / 1000)); + const remaining = Math.max(0, Math.floor((endTime - currentTime) / 1000)); return remaining; }; @@ -31,7 +30,7 @@ export default function Timer() { setTimer(timerData); if (timerData && timerData.shouldEnd) { - const remaining = calculateTimeRemaining(timerData); + const remaining = calculateTimeRemaining(timerData.shouldEnd); setTimeRemaining(remaining); setIsStarted(timerData.isStarted && remaining > 0); }