Skip to content

Commit 3e408fe

Browse files
committed
countdown timer updated
1 parent 416709f commit 3e408fe

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

components/Countdown.jsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState, useEffect } from "react";
44

5-
export default function Countdown() {
5+
export default function Countdown({ targetDate }) {
66
const [timeLeft, setTimeLeft] = useState({
77
Days: "00",
88
Hours: "00",
@@ -11,8 +11,14 @@ export default function Countdown() {
1111
});
1212

1313
useEffect(() => {
14-
// Set countdown to 1 hour from now ON THE CLIENT
15-
const target = Date.now() + 60 * 60 * 1000;
14+
if (!targetDate) return;
15+
16+
const target = new Date(targetDate).getTime();
17+
18+
if (isNaN(target)) {
19+
console.error("Invalid targetDate:", targetDate);
20+
return;
21+
}
1622

1723
const timer = setInterval(() => {
1824
const now = Date.now();
@@ -33,19 +39,21 @@ export default function Countdown() {
3339
const hours = Math.floor(
3440
(diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
3541
);
36-
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
42+
const minutes = Math.floor(
43+
(diff % (1000 * 60 * 60)) / (1000 * 60)
44+
);
3745
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
3846

3947
setTimeLeft({
40-
Days: days.toString().padStart(2, "0"),
41-
Hours: hours.toString().padStart(2, "0"),
42-
Minutes: minutes.toString().padStart(2, "0"),
43-
Seconds: seconds.toString().padStart(2, "0"),
48+
Days: String(days).padStart(2, "0"),
49+
Hours: String(hours).padStart(2, "0"),
50+
Minutes: String(minutes).padStart(2, "0"),
51+
Seconds: String(seconds).padStart(2, "0"),
4452
});
4553
}, 1000);
4654

4755
return () => clearInterval(timer);
48-
}, []);
56+
}, [targetDate]);
4957

5058
return (
5159
<div className="mb-8 text-center">
@@ -57,7 +65,7 @@ export default function Countdown() {
5765
{Object.entries(timeLeft).map(([label, value]) => (
5866
<div
5967
key={label}
60-
className="bg-gray-800 w-40 h-40 md:w-24 md:h-24 rounded-lg flex flex-col items-center justify-center"
68+
className="bg-gray-800 w-20 h-20 md:w-24 md:h-24 rounded-lg flex flex-col items-center justify-center"
6169
>
6270
<span className="text-2xl md:text-3xl font-bold text-blue-500">
6371
{value}

components/Hero.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ export default function Hero() {
5656
</div>
5757

5858
{/* Countdown */}
59-
<div className="mb-3">
60-
<Countdown targetDate="2025-01-15T00:00:00" />
59+
<div className="mb-08">
60+
<Countdown targetDate="2025-12-20T09:00:00+05:30" />
6161
</div>
62-
6362
{/* CTA */}
6463
<div className="flex justify-center">
6564
<button

0 commit comments

Comments
 (0)