Clean up time diff code

This commit is contained in:
Ian Philips 2022-05-25 16:04:14 -06:00
parent f3be3b1f3c
commit f0d44be2f4

View File

@ -127,13 +127,10 @@ export default function Sidebar(props: { className?: string }) {
const currentPage = router.pathname const currentPage = router.pathname
const [countdown, setCountdown] = useState('...') const [countdown, setCountdown] = useState('...')
useEffect(() => { useEffect(() => {
const utcMidnightToLocalDate = new Date(getUtcFreeMarketResetTime(false)) const nextUtcResetTime = getUtcFreeMarketResetTime(false)
const interval = setInterval(() => { const interval = setInterval(() => {
const now = new Date().getTime() const now = new Date().getTime()
let timeUntil = Math.abs(utcMidnightToLocalDate.getTime() - now) let timeUntil = nextUtcResetTime - now
if (now > utcMidnightToLocalDate.getTime()) {
timeUntil = 24 * 60 * 60 * 1000 - timeUntil
}
const hoursUntil = timeUntil / 1000 / 60 / 60 const hoursUntil = timeUntil / 1000 / 60 / 60
const minutesUntil = Math.floor((hoursUntil * 60) % 60) const minutesUntil = Math.floor((hoursUntil * 60) % 60)
const secondsUntil = Math.floor((hoursUntil * 60 * 60) % 60) const secondsUntil = Math.floor((hoursUntil * 60 * 60) % 60)