Fix task timer showing negative values
Ensure running seconds never go negative by using Math.max(0, ...) This prevents the timer from showing negative values when there's a clock skew between client and server. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e37cf06634
commit
814bc51b86
1 changed files with 2 additions and 2 deletions
|
|
@ -49,7 +49,7 @@ export function TaskTimer({ task, onUpdate, canControl = true }: TaskTimerProps)
|
||||||
|
|
||||||
if (runningItem) {
|
if (runningItem) {
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
const runningSeconds = differenceInSeconds(new Date(), parseISO(runningItem.startAt))
|
const runningSeconds = Math.max(0, differenceInSeconds(new Date(), parseISO(runningItem.startAt)))
|
||||||
setDisplaySeconds(accumulatedSeconds + runningSeconds)
|
setDisplaySeconds(accumulatedSeconds + runningSeconds)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -64,7 +64,7 @@ export function TaskTimer({ task, onUpdate, canControl = true }: TaskTimerProps)
|
||||||
// Initial calculation
|
// Initial calculation
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (runningItem) {
|
if (runningItem) {
|
||||||
const runningSeconds = differenceInSeconds(new Date(), parseISO(runningItem.startAt))
|
const runningSeconds = Math.max(0, differenceInSeconds(new Date(), parseISO(runningItem.startAt)))
|
||||||
setDisplaySeconds(accumulatedSeconds + runningSeconds)
|
setDisplaySeconds(accumulatedSeconds + runningSeconds)
|
||||||
} else {
|
} else {
|
||||||
setDisplaySeconds(accumulatedSeconds)
|
setDisplaySeconds(accumulatedSeconds)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue