Skip to content

Commit

Permalink
Don't go into -ve numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
m-salmankhan committed Sep 14, 2023
1 parent 30dcd5e commit 5d6725d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const tick = (setTimeLeft, eventDate, currentTime) => {
diffHours = Math.floor(diffMins / 60),
diffDays = Math.floor(diffHours / 24);

const days = diffDays;
const hours = diffHours - (days * 24);
const minutes = diffMins - (days * 24 * 60) - (hours * 60);
const seconds = diffSecs - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
const days = Math.min(diffDays, 0);
const hours = Math.min(diffHours - (days * 24), 0);
const minutes = Math.min(diffMins - (days * 24 * 60) - (hours * 60), 0);
const seconds = Math.min(diffSecs - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60), 0);

setTimeLeft({
days,
Expand Down Expand Up @@ -41,4 +41,4 @@ export const Clock = () => {
<div className="secs" data-label="Seconds">{`${timeLeft.seconds}`}</div>
</div>
)
}
}

0 comments on commit 5d6725d

Please sign in to comment.