From 32c88f232229ec62f080145d3d800f915c3b2550 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 6 Oct 2023 18:00:46 +0700 Subject: [PATCH 1/6] add DateTimeFormat polyfills --- src/libs/IntlPolyfill/index.native.ts | 3 ++- src/libs/IntlPolyfill/index.ts | 1 - src/libs/IntlPolyfill/polyfillDateTimeFormat.ts | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/libs/IntlPolyfill/polyfillDateTimeFormat.ts diff --git a/src/libs/IntlPolyfill/index.native.ts b/src/libs/IntlPolyfill/index.native.ts index 9e578558fae..d81b9d90cbe 100644 --- a/src/libs/IntlPolyfill/index.native.ts +++ b/src/libs/IntlPolyfill/index.native.ts @@ -1,6 +1,7 @@ import polyfillNumberFormat from './polyfillNumberFormat'; import polyfillListFormat from './polyfillListFormat'; import IntlPolyfill from './types'; +import polyfillDateTimeFormat from './polyfillDateTimeFormat'; /** * Polyfill the Intl API, always performed for native devices. @@ -10,8 +11,8 @@ const intlPolyfill: IntlPolyfill = () => { require('@formatjs/intl-getcanonicallocales/polyfill'); require('@formatjs/intl-locale/polyfill'); require('@formatjs/intl-pluralrules/polyfill'); - require('@formatjs/intl-datetimeformat'); polyfillNumberFormat(); + polyfillDateTimeFormat(); polyfillListFormat(); }; diff --git a/src/libs/IntlPolyfill/index.ts b/src/libs/IntlPolyfill/index.ts index bef12ef093e..982dc5130d7 100644 --- a/src/libs/IntlPolyfill/index.ts +++ b/src/libs/IntlPolyfill/index.ts @@ -8,6 +8,5 @@ import IntlPolyfill from './types'; const intlPolyfill: IntlPolyfill = () => { // Just need to polyfill Intl.NumberFormat for web based platforms polyfillNumberFormat(); - require('@formatjs/intl-datetimeformat'); }; export default intlPolyfill; diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts new file mode 100644 index 00000000000..460f65c8f63 --- /dev/null +++ b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts @@ -0,0 +1,6 @@ +export default function () { + require('@formatjs/intl-datetimeformat/polyfill-force'); + require('@formatjs/intl-datetimeformat/add-all-tz'); + require('@formatjs/intl-datetimeformat/locale-data/en'); + require('@formatjs/intl-datetimeformat/locale-data/es'); +} From 919714362d1d0fbaab9dd22d9908e3317e4e84a9 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 9 Oct 2023 10:00:02 +0700 Subject: [PATCH 2/6] fix: 29060 --- src/libs/actions/Report.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index ab2ac7fb0ca..dbf6be43415 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -26,7 +26,7 @@ import * as UserUtils from '../UserUtils'; import * as Welcome from './Welcome'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; import * as Environment from '../Environment/Environment'; -import * as Session from './Session'; +import SidebarUtils from '../../libs/SidebarUtils'; let currentUserAccountID; Onyx.connect({ @@ -1882,7 +1882,7 @@ function openReportFromDeepLink(url, isAuthenticated) { // Navigate to the report after sign-in/sign-up. InteractionManager.runAfterInteractions(() => { - Session.waitForUserSignIn().then(() => { + SidebarUtils.isSidebarLoadedReady().then(() => { if (route === ROUTES.CONCIERGE) { navigateToConciergeChat(); return; From c4543843f62ac5e828698d7f9a83369906b9538e Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 9 Oct 2023 12:24:56 +0700 Subject: [PATCH 3/6] set default timezone --- src/libs/IntlPolyfill/index.ts | 3 +- .../IntlPolyfill/polyfillDateTimeFormat.ts | 48 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/libs/IntlPolyfill/index.ts b/src/libs/IntlPolyfill/index.ts index 982dc5130d7..185f292c396 100644 --- a/src/libs/IntlPolyfill/index.ts +++ b/src/libs/IntlPolyfill/index.ts @@ -1,12 +1,13 @@ import polyfillNumberFormat from './polyfillNumberFormat'; import IntlPolyfill from './types'; +import polyfillDateTimeFormat from "./polyfillDateTimeFormat"; /** * Polyfill the Intl API if the ICU version is old. * This ensures that the currency data is consistent across platforms and browsers. */ const intlPolyfill: IntlPolyfill = () => { - // Just need to polyfill Intl.NumberFormat for web based platforms polyfillNumberFormat(); + polyfillDateTimeFormat(); }; export default intlPolyfill; diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts index 460f65c8f63..cce78f58d4a 100644 --- a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts +++ b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts @@ -1,6 +1,52 @@ +import Onyx from "react-native-onyx"; +import ONYXKEYS from "../../ONYXKEYS"; +import {Timezone} from "../../types/onyx/PersonalDetails"; +import CONST from "../../CONST"; + +let currentUserAccountID: number | undefined; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (val) => { + // When signed out, val is undefined + if (!val) { + return; + } + + currentUserAccountID = val.accountID; + }, +}); + +let timezone: Required = CONST.DEFAULT_TIME_ZONE; +Onyx.connect({ + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + callback: (value) => { + if (!currentUserAccountID) { + return; + } + + const personalDetailsTimezone = value?.[currentUserAccountID]?.timezone; + + timezone = { + selected: personalDetailsTimezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected, + automatic: personalDetailsTimezone?.automatic ?? CONST.DEFAULT_TIME_ZONE.automatic, + }; + }, +}); + export default function () { + // Because JS Engines do not expose default timezone, the polyfill cannot detect local timezone that a browser is in + // We must manually do this by getting the local timezone before adding polyfill + const currentTimezone = timezone.automatic ? Intl.DateTimeFormat().resolvedOptions().timeZone : timezone.selected; + require('@formatjs/intl-datetimeformat/polyfill-force'); - require('@formatjs/intl-datetimeformat/add-all-tz'); require('@formatjs/intl-datetimeformat/locale-data/en'); require('@formatjs/intl-datetimeformat/locale-data/es'); + require('@formatjs/intl-datetimeformat/add-all-tz'); + + if ('__setDefaultTimeZone' in Intl.DateTimeFormat) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line no-underscore-dangle + Intl.DateTimeFormat.__setDefaultTimeZone(currentTimezone); + } } From 2dd92d30f3b4b7cc77a0b57aac1a1fcccce6eb38 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 9 Oct 2023 13:29:39 +0700 Subject: [PATCH 4/6] Revert "fix: 29060" This reverts commit 919714362d1d0fbaab9dd22d9908e3317e4e84a9. --- src/libs/actions/Report.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index dbf6be43415..ab2ac7fb0ca 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -26,7 +26,7 @@ import * as UserUtils from '../UserUtils'; import * as Welcome from './Welcome'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; import * as Environment from '../Environment/Environment'; -import SidebarUtils from '../../libs/SidebarUtils'; +import * as Session from './Session'; let currentUserAccountID; Onyx.connect({ @@ -1882,7 +1882,7 @@ function openReportFromDeepLink(url, isAuthenticated) { // Navigate to the report after sign-in/sign-up. InteractionManager.runAfterInteractions(() => { - SidebarUtils.isSidebarLoadedReady().then(() => { + Session.waitForUserSignIn().then(() => { if (route === ROUTES.CONCIERGE) { navigateToConciergeChat(); return; From 07d4e0a60be1577ec29c00970e6d855cb6f4741c Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 10 Oct 2023 01:31:15 +0700 Subject: [PATCH 5/6] pretteir --- src/libs/IntlPolyfill/index.ts | 2 +- src/libs/IntlPolyfill/polyfillDateTimeFormat.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/IntlPolyfill/index.ts b/src/libs/IntlPolyfill/index.ts index 185f292c396..be3e392b35c 100644 --- a/src/libs/IntlPolyfill/index.ts +++ b/src/libs/IntlPolyfill/index.ts @@ -1,6 +1,6 @@ import polyfillNumberFormat from './polyfillNumberFormat'; import IntlPolyfill from './types'; -import polyfillDateTimeFormat from "./polyfillDateTimeFormat"; +import polyfillDateTimeFormat from './polyfillDateTimeFormat'; /** * Polyfill the Intl API if the ICU version is old. diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts index cce78f58d4a..37460114352 100644 --- a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts +++ b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts @@ -1,7 +1,7 @@ -import Onyx from "react-native-onyx"; -import ONYXKEYS from "../../ONYXKEYS"; -import {Timezone} from "../../types/onyx/PersonalDetails"; -import CONST from "../../CONST"; +import Onyx from 'react-native-onyx'; +import ONYXKEYS from '../../ONYXKEYS'; +import {Timezone} from '../../types/onyx/PersonalDetails'; +import CONST from '../../CONST'; let currentUserAccountID: number | undefined; Onyx.connect({ From a38d264ea34cfd19f11d47ce62b0dd46fc2a3cda Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 13 Oct 2023 10:36:12 +0700 Subject: [PATCH 6/6] modified comment --- src/libs/IntlPolyfill/polyfillDateTimeFormat.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts index 37460114352..25983aa71f5 100644 --- a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts +++ b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts @@ -34,8 +34,8 @@ Onyx.connect({ }); export default function () { - // Because JS Engines do not expose default timezone, the polyfill cannot detect local timezone that a browser is in - // We must manually do this by getting the local timezone before adding polyfill + // Because JS Engines do not expose default timezone, the polyfill cannot detect local timezone that a browser is in. + // We must manually do this by getting the local timezone before adding polyfill. const currentTimezone = timezone.automatic ? Intl.DateTimeFormat().resolvedOptions().timeZone : timezone.selected; require('@formatjs/intl-datetimeformat/polyfill-force');