Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Models/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}

Expand Down
7 changes: 3 additions & 4 deletions resources/js/components/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ export default function Timer() {
const [isStarted, setIsStarted] = useState<boolean>(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;
};

Expand All @@ -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);
}
Expand Down
Loading