Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ssshojaei committed Feb 25, 2024
1 parent 7ac3581 commit ad0caa9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
File renamed without changes.
24 changes: 5 additions & 19 deletions src/app/components/CountDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import WaveMobile from "@/assets/images/home/count-down-wave-mobile.svg";
import Wave from "@/assets/images/home/count-down-wave.svg";
import { conferenceDateTime } from "@/data/timing";
import { calculateTimeRemaining } from "@/utils/countDown";
import Image from "next/image";
import React, { Fragment, useState } from "react";
import { HiOutlineClock } from "react-icons/hi";
Expand Down Expand Up @@ -35,28 +36,13 @@ export default function CountDown() {
}

const CountDownTimer = () => {
const calculateTimeRemaining = () => {
const now = new Date().getTime();
const target = conferenceDateTime.getTime();
const timeRemaining = target - now;

const days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));
const hours = Math.floor(
(timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
);
const minutes = Math.floor(
(timeRemaining % (1000 * 60 * 60)) / (1000 * 60),
);
const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);

return { days, hours, minutes, seconds };
};

const [timeRemaining, setTimeRemaining] = useState(calculateTimeRemaining());
const [timeRemaining, setTimeRemaining] = useState(
calculateTimeRemaining(conferenceDateTime),
);

React.useEffect(() => {
const interval = setInterval(() => {
setTimeRemaining(calculateTimeRemaining());
setTimeRemaining(calculateTimeRemaining(conferenceDateTime));
}, 1000);

return () => clearInterval(interval);
Expand Down
4 changes: 4 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
html {
scroll-behavior: smooth;
}
body {
max-width: 100vw;
overflow-x: hidden;
}
15 changes: 15 additions & 0 deletions src/utils/countDown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client";

export const calculateTimeRemaining = (conferenceDateTime: Date) => {
const now = new Date().getTime();
const timeLeft = conferenceDateTime.getTime() - now;

const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor(
(timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
);
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);

return { days, hours, minutes, seconds };
};

0 comments on commit ad0caa9

Please sign in to comment.