Skip to content

Commit

Permalink
fix: date updated
Browse files Browse the repository at this point in the history
  • Loading branch information
saramontagud committed Sep 19, 2024
1 parent 9b49781 commit 27d8b16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/components/WelcomeHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const WelcomeHero: FC<Props> = ({ variant, children }) => {
</div>

{/* Wrapper was moved to countdown because its component logic, could be override by className prop */}
<Countdown startFrom={new Date("2024-09-20")} />
<Countdown />

<div className="flex gap-6 pb-12">
{variant === "home" && (
Expand Down
35 changes: 12 additions & 23 deletions app/components/common/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@ interface CountDownProps {

export const Countdown = ({ className, startFrom }: CountDownProps) => {
const time = [
{
key: "days",
label: "Días",
},
{
key: "hours",
label: "Horas",
},
{
key: "minutes",
label: "Minutos",
},
{
key: "seconds",
label: "Segundos",
},
{ key: "days", label: "Días" },
{ key: "hours", label: "Horas" },
{ key: "minutes", label: "Minutos" },
{ key: "seconds", label: "Segundos" },
];

const [timeLeft, setTimeLeft] = useState({
Expand All @@ -34,7 +22,9 @@ export const Countdown = ({ className, startFrom }: CountDownProps) => {
});

const updateCountdown = () => {
const countdownDate = startFrom || new Date();
// Establecer la fecha y hora de finalización (20 Septiembre 2024, 20:00 en UTC+2)
const countdownDate = startFrom || new Date("2024-09-20T18:00:00Z"); // UTC+2 es dos horas menos que UTC

const now = new Date();

const timeDifference = countdownDate.getTime() - now.getTime();
Expand All @@ -52,9 +42,11 @@ export const Countdown = ({ className, startFrom }: CountDownProps) => {
}, []);

useEffect(() => {
setInterval(() => {
const intervalId = setInterval(() => {
updateCountdown();
}, 1000);

return () => clearInterval(intervalId); // Limpiar el intervalo al desmontar el componente
}, []);

const formatNumber = (number: number) => {
Expand All @@ -67,16 +59,13 @@ export const Countdown = ({ className, startFrom }: CountDownProps) => {
{time.map(({ key, label }, index) => (
<section key={index} className="text-center text-shadow-sm">
<span className="font-bold text-3xl xl:text-6xl">
{formatNumber(timeLeft[key])}
{formatNumber(timeLeft[key as keyof typeof timeLeft])}
</span>
<p className="text-lg xl:text-2xl">{label}</p>
</section>
))}

</div>
<p className="font-semibold">
20 de Septiembre de 2024
</p>
<p className="font-semibold">20 de Septiembre de 2024 a las 20:00</p>
</div>
);
};

0 comments on commit 27d8b16

Please sign in to comment.