From 3c3a97fb8e454d814f6f2d370a5050d6a5437e4c Mon Sep 17 00:00:00 2001 From: ekzyis <27162016+ekzyis@users.noreply.github.com> Date: Fri, 7 Jul 2023 03:55:18 +0200 Subject: [PATCH] Fix reward countdown for other time zones (#347) Co-authored-by: ekzyis --- pages/rewards.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pages/rewards.js b/pages/rewards.js index cd621901..d0037c76 100644 --- a/pages/rewards.js +++ b/pages/rewards.js @@ -29,10 +29,13 @@ export function RewardLine ({ total }) { const [threshold, setThreshold] = useState(0) useEffect(() => { - const dateStr = new Date().toLocaleString('en-US', { timeZone: 'America/Chicago' }) - const date = new Date(dateStr) + const date = new Date() date.setHours(24, 0, 0, 0) - setThreshold(date.getTime()) + // Central Daylight Saving Time UTC offset in minutes + const targetOffset = -5 * 60 + const localOffset = -date.getTimezoneOffset() + const ts = date.getTime() + ((localOffset - targetOffset) * 60 * 1000) + setThreshold(ts) }, []) return (