Fix safari timezone (#8574)

* Fix safari bad time format

* Fix processing
This commit is contained in:
Nicolas Mowen 2023-11-10 17:12:48 -07:00 committed by GitHub
parent 3457dcddfe
commit 563fdec211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -223,6 +223,13 @@ const getUTCOffset = (date: Date, timezone: string): number => {
// locale of en-CA is required for proper locale format // locale of en-CA is required for proper locale format
let iso = utcDate.toLocaleString('en-CA', { timeZone: timezone, hour12: false }).replace(', ', 'T'); let iso = utcDate.toLocaleString('en-CA', { timeZone: timezone, hour12: false }).replace(', ', 'T');
iso += `.${utcDate.getMilliseconds().toString().padStart(3, '0')}`; 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; return (target.getTime() - utcDate.getTime()) / 60 / 1000;
}; };