From 42feb5475adc7d8c1cab44248d9938aaba0adf7b Mon Sep 17 00:00:00 2001 From: Viktor Fomin Date: Thu, 2 Feb 2023 13:22:16 +0300 Subject: [PATCH] Client: Wizard: fix timezone select --- packages/client/package.json | 3 ++- packages/client/src/pages/Wizard/index.js | 10 +++------ .../src/pages/Wizard/timezonesHelper.js | 22 +++++++++++++++++++ yarn.lock | 8 +++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 packages/client/src/pages/Wizard/timezonesHelper.js diff --git a/packages/client/package.json b/packages/client/package.json index 65984ba828..edc8151e85 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -50,7 +50,8 @@ "react-hotkeys-hook": "^3.4.4", "react-markdown": "^7.0.1", "react-smartbanner": "^5.1.4", - "react-string-format": "^0.1.4" + "react-string-format": "^0.1.4", + "windows-iana": "^5.1.0" }, "devDependencies": { "@babel/core": "^7.15.5", diff --git a/packages/client/src/pages/Wizard/index.js b/packages/client/src/pages/Wizard/index.js index 9a92a1a708..df4c99e8ad 100644 --- a/packages/client/src/pages/Wizard/index.js +++ b/packages/client/src/pages/Wizard/index.js @@ -34,6 +34,8 @@ import { StyledInfo, StyledAcceptTerms, } from "./StyledWizard"; +import { getUserTimezone, getSelectZone } from "./timezonesHelper"; + import DocspaceLogo from "SRC_DIR/DocspaceLogo"; import RefreshReactSvgUrl from "PUBLIC_DIR/images/refresh.react.svg?url"; @@ -92,10 +94,6 @@ const Wizard = (props) => { }); }; - const getUserTimezone = () => { - return Intl.DateTimeFormat().resolvedOptions().timeZone || timezone; - }; - const fetchData = async () => { await axios .all([ @@ -105,9 +103,7 @@ const Wizard = (props) => { getPortalTimezones(wizardToken).then((data) => { const userTimezone = getUserTimezone(); const zones = mapTimezonesToArray(data); - const select = - zones.filter((zone) => zone.key === userTimezone) || - zones.filter((zone) => zone.key === timezone); + const select = getSelectZone(zones, userTimezone); setTimezones(zones); setSelectedTimezone({ diff --git a/packages/client/src/pages/Wizard/timezonesHelper.js b/packages/client/src/pages/Wizard/timezonesHelper.js new file mode 100644 index 0000000000..f679abf2e8 --- /dev/null +++ b/packages/client/src/pages/Wizard/timezonesHelper.js @@ -0,0 +1,22 @@ +import { findWindows } from "windows-iana"; + +export const getUserTimezone = () => { + return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC"; +}; + +export const getSelectZone = (zones, userTimezone) => { + const defaultTimezone = "UTC"; + const isWindowsZones = zones[0].key === "Dateline Standard Time"; //TODO: get from server + + if (isWindowsZones) { + const windowsZoneKey = findWindows(userTimezone); + return ( + zones.filter((zone) => zone.key === windowsZoneKey) || + zones.filter((zone) => zone.key === defaultTimezone) + ); + } + return ( + zones.filter((zone) => zone.key === userTimezone) || + zones.filter((zone) => zone.key === defaultTimezone) + ); +}; diff --git a/yarn.lock b/yarn.lock index 9aca23e2e0..dbcef7550f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2815,6 +2815,7 @@ __metadata: webpack: 5.52.1 webpack-cli: 4.10.0 webpack-dev-server: 4.3.1 + windows-iana: ^5.1.0 languageName: unknown linkType: soft @@ -26168,6 +26169,13 @@ __metadata: languageName: node linkType: hard +"windows-iana@npm:^5.1.0": + version: 5.1.0 + resolution: "windows-iana@npm:5.1.0" + checksum: 0dc9ababde5f839e83a4bcd448347d8da563efd9e23ce61ac777e9992774ff85de2a9f343f87b80b37b181742fe4d783cff3ba39191cfedb6357ae7d5f58aadc + languageName: node + linkType: hard + "winston-cloudwatch@npm:^6.1.1": version: 6.1.1 resolution: "winston-cloudwatch@npm:6.1.1"