From 563fdec211454aead9629d20c73a487478f8546c Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 10 Nov 2023 17:12:48 -0700 Subject: [PATCH] Fix safari timezone (#8574) * Fix safari bad time format * Fix processing --- web/src/utils/dateUtil.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/src/utils/dateUtil.ts b/web/src/utils/dateUtil.ts index 32bccf39b..03d5de849 100644 --- a/web/src/utils/dateUtil.ts +++ b/web/src/utils/dateUtil.ts @@ -223,6 +223,13 @@ const getUTCOffset = (date: Date, timezone: string): number => { // locale of en-CA is required for proper locale format let iso = utcDate.toLocaleString('en-CA', { timeZone: timezone, hour12: false }).replace(', ', 'T'); iso += `.${utcDate.getMilliseconds().toString().padStart(3, '0')}`; - const target = new Date(`${iso}Z`); + let target = new Date(`${iso}Z`); + + // safari doesn't like the default format + if (isNaN(target.getTime())) { + iso = iso.replace("T", " ").split(".")[0]; + target = new Date(`${iso}+000`); + } + return (target.getTime() - utcDate.getTime()) / 60 / 1000; };