Fix dst offset calculation (#10357)

This commit is contained in:
Nicolas Mowen 2024-03-10 07:17:48 -06:00 committed by GitHub
parent b910db4f05
commit efaa95b742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) {