From efaa95b742a990fa3cf3dafa1a5796de7b651a0b Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 10 Mar 2024 07:17:48 -0600 Subject: [PATCH] Fix dst offset calculation (#10357) --- web/src/utils/dateUtil.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/src/utils/dateUtil.ts b/web/src/utils/dateUtil.ts index 4a3f7158e..b3814057b 100644 --- a/web/src/utils/dateUtil.ts +++ b/web/src/utils/dateUtil.ts @@ -258,9 +258,7 @@ const getUTCOffset = (date: Date, timezone: string): number => { } // Otherwise, calculate offset using provided timezone - const utcDate = new Date( - date.getTime() - date.getTimezoneOffset() * 60 * 1000, - ); + const utcDate = new Date(date.getTime()); // locale of en-CA is required for proper locale format let iso = utcDate .toLocaleString("en-CA", { timeZone: timezone, hour12: false }) @@ -274,7 +272,11 @@ const getUTCOffset = (date: Date, timezone: string): number => { target = new Date(`${iso}+000`); } - return (target.getTime() - utcDate.getTime()) / 60 / 1000; + return ( + (target.getTime() - utcDate.getTime() - date.getTimezoneOffset()) / + 60 / + 1000 + ); }; export function getRangeForTimestamp(timestamp: number) {