From 13bf5ac2536f13bc81f9d23070b12b0fc98b11f5 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 24 May 2022 07:31:44 -0600 Subject: [PATCH] Free daily market bugfix --- web/components/nav/sidebar.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/components/nav/sidebar.tsx b/web/components/nav/sidebar.tsx index 91ebb404..10eda9cf 100644 --- a/web/components/nav/sidebar.tsx +++ b/web/components/nav/sidebar.tsx @@ -129,8 +129,12 @@ export default function Sidebar(props: { className?: string }) { useEffect(() => { const utcMidnightToLocalDate = new Date(getUtcFreeMarketResetTime(false)) const interval = setInterval(() => { - const timeUntil = utcMidnightToLocalDate.getTime() - new Date().getTime() - const hoursUntil = 24 + timeUntil / 1000 / 60 / 60 + const now = new Date().getTime() + let timeUntil = Math.abs(utcMidnightToLocalDate.getTime() - now) + if (now > utcMidnightToLocalDate.getTime()) { + timeUntil = 24 * 60 * 60 * 1000 - timeUntil + } + const hoursUntil = timeUntil / 1000 / 60 / 60 const minutesUntil = Math.floor((hoursUntil * 60) % 60) const secondsUntil = Math.floor((hoursUntil * 60 * 60) % 60) const hoursUntilFloor = Math.floor(hoursUntil)