From f1c82828bf12103a6eb8216b0f44fd75b96f2430 Mon Sep 17 00:00:00 2001 From: Situ Chandra Shil <108292595+situchan@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:19:41 +0600 Subject: [PATCH] Revert "Add `DateTimeFormat` polyfill" --- src/libs/IntlPolyfill/index.native.ts | 3 +- src/libs/IntlPolyfill/index.ts | 4 +- .../IntlPolyfill/polyfillDateTimeFormat.ts | 52 ------------------- 3 files changed, 3 insertions(+), 56 deletions(-) delete mode 100644 src/libs/IntlPolyfill/polyfillDateTimeFormat.ts diff --git a/src/libs/IntlPolyfill/index.native.ts b/src/libs/IntlPolyfill/index.native.ts index d81b9d90cbe8..9e578558faed 100644 --- a/src/libs/IntlPolyfill/index.native.ts +++ b/src/libs/IntlPolyfill/index.native.ts @@ -1,7 +1,6 @@ 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. @@ -11,8 +10,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 be3e392b35cd..bef12ef093e2 100644 --- a/src/libs/IntlPolyfill/index.ts +++ b/src/libs/IntlPolyfill/index.ts @@ -1,13 +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(); + require('@formatjs/intl-datetimeformat'); }; export default intlPolyfill; diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts deleted file mode 100644 index 25983aa71f5a..000000000000 --- a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts +++ /dev/null @@ -1,52 +0,0 @@ -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/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); - } -}