Skip to content

Commit

Permalink
Fix safari timezone (blakeblackshear#8574)
Browse files Browse the repository at this point in the history
* Fix safari bad time format

* Fix processing
  • Loading branch information
NickM-27 committed Nov 11, 2023
1 parent 3457dcd commit 563fdec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion web/src/utils/dateUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 563fdec

Please sign in to comment.