import { Box, Flex, Grid, Image, Link, Text } from 'theme-ui' import { useEffect, useState } from 'react' import Buttons from './button' import CardModel from './card-model' export default function Epoch() { const calculateTimeLeft = () => { const difference = +new Date(`2022-12-30T12:30:00.000Z`) - +new Date() let timeLeft = {} if (difference > 0) { timeLeft = { days: Math.floor(difference / (1000 * 60 * 60 * 24)), hours: Math.floor((difference / (1000 * 60 * 60)) % 24), min: Math.floor((difference / 1000 / 60) % 60), sec: Math.floor((difference / 1000) % 60) } } return timeLeft } const [timeLeft, setTimeLeft] = useState(calculateTimeLeft()) useEffect(() => { const timer = setTimeout(() => { setTimeLeft(calculateTimeLeft()) }, 1000) return () => clearTimeout(timer) }) const timer = [] Object.keys(timeLeft).forEach(e => { if (!timeLeft[e]) { if (e === 'days') { return } else if (e === 'hours') { if (!timeLeft['days']) { return } } else if (e === 'min') { if (!timeLeft['days'] && !timeLeft['hours']) { return } } else { if (!timeLeft['days'] && !timeLeft['hours'] && !timeLeft['min']) { return } } } var name = '' if (e === 'days') { if (timeLeft[e] === 1 || timeLeft[e] === 0) { name = 'day' } else { name = 'days' } } else if (e === 'hours') { if (timeLeft[e] === 1 || timeLeft[e] === 0) { name = 'hour' } else { name = 'hours' } } else if (e === 'min') { name = 'min' } else { name = 'sec' } timer.push( ({ color: '#FF4794', position: 'relative', width: [null, '85%', '80%'], height: [null, '50%', '85%'], border: 'none', borderColor: '#FF4794', fontSize: [3, 4], display: 'flex', justifyContent: 'center', alignItems: 'center', textAlign: 'center', opacity: 0.7 })} > {timeLeft[e]}{' '} {name} ) }) return ( Hack Club Presents Epoch background Hack Club Presents Epoch header {timer.length ? ( {timer} ) : ( <> )} Join us this winter as 150+ teenage hackers from all around the world travel to Delhi, India for Epoch! Together, we’ll build the unexpected, share what we’ve learnt in 2022, and experience the thrill of being in-person together. In{' '} Austin ,{' '} Bay Area , or{' '} Vermont ? Join a regional Epoch event! Sign up and attend Epoch Help plan the hackathon ) }