From 2cc7e9ebe140bfd764ff9b84a16f87825aee95c3 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Fri, 23 Aug 2024 15:13:44 -0500 Subject: [PATCH] CE-1643 Add a timezone conversion to the formatDate function for the case where it took a string rather than a Date as input, in which case, the new Date() call would be appying a timezone, and making us off-by-one (for some side of the prime merdian i think) --- src/qqq/utils/qqq/ValueUtils.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qqq/utils/qqq/ValueUtils.tsx b/src/qqq/utils/qqq/ValueUtils.tsx index e5a9c55..7d29f63 100644 --- a/src/qqq/utils/qqq/ValueUtils.tsx +++ b/src/qqq/utils/qqq/ValueUtils.tsx @@ -268,7 +268,15 @@ class ValueUtils { if (!(date instanceof Date)) { + //////////////////////////////////////////////////////////////////////////////////// + // so, a new Date here will interpret the string as being at midnight UTC, but // + // the data object will be in the user/browser timezone. // + // so "2024-08-22", for a user in US/Central, will be "2024-08-21T19:00:00-0500". // + // correct for that by adding the date's timezone offset (converted from minutes // + // to millis) back to it // + //////////////////////////////////////////////////////////////////////////////////// date = new Date(date); + date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000) } // @ts-ignore return (`${date.toString("yyyy-MM-dd")}`);