Skip to content

Commit

Permalink
fix times
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorrn committed Oct 10, 2024
1 parent 606ff2c commit 4df4035
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ export function Countdown() {
const interval = setInterval(() =>{
const now = new Date();
const difference = target.getTime() - now.getTime();

const d = Math.floor(difference / (1000 * 60 * 60 * 24)) +1 ;


const d_diff = difference / (1000 * 60 * 60 * 24);
const d = difference < 0 ? Math.ceil(d_diff) : Math.floor(d_diff);
setDays(d)

const h = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const h_diff = (difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
const h = difference < 0 ? Math.ceil(h_diff) : Math.floor(h_diff);
setHours(h)

const m = Math.floor((difference % (1000 * 60 * 60))/(1000*60))
const m_diff = (difference % (1000 * 60 * 60))/(1000*60)
const m = difference < 0 ? Math.ceil(m_diff) : Math.floor(m_diff)
setMinutes(m)

const s = Math.floor((difference % (1000 * 60))/1000)
const s_diff = (difference % (1000 * 60))/1000
const s = difference < 0 ? Math.ceil(s_diff) : Math.floor(s_diff)
setSeconds(s)
},1000)
return () => clearInterval(interval)
Expand Down

0 comments on commit 4df4035

Please sign in to comment.