Support timezones (#11434)

* Handle offset timezones

* Fix previews loading

* Cleanup

* remove unused
This commit is contained in:
Nicolas Mowen
2024-05-19 17:08:32 -06:00
committed by GitHub
parent bca01cb43c
commit 4c87ef56c7
5 changed files with 46 additions and 17 deletions
+7 -4
View File
@@ -235,7 +235,10 @@ export const getDurationFromTimestamps = (
* @param timezone string representation of the timezone the user is requesting
* @returns number of minutes offset from UTC
*/
export const getUTCOffset = (date: Date, timezone: string): number => {
export const getUTCOffset = (
date: Date,
timezone: string = getResolvedTimeZone(),
): number => {
// If timezone is in UTC±HH:MM format, parse it to get offset
const utcOffsetMatch = timezone.match(/^UTC([+-])(\d{2}):(\d{2})$/);
if (utcOffsetMatch) {
@@ -259,10 +262,10 @@ export const getUTCOffset = (date: Date, timezone: string): number => {
target = new Date(`${iso}+000`);
}
return (
return Math.round(
(target.getTime() - utcDate.getTime() - date.getTimezoneOffset()) /
60 /
1000
60 /
1000,
);
};