diff --git a/src/TIMEZONES.ts b/src/TIMEZONES.ts index 238563134872..b3d9c843aeba 100644 --- a/src/TIMEZONES.ts +++ b/src/TIMEZONES.ts @@ -549,6 +549,17 @@ const timezoneBackwardMap: Record = { 'US/Pacific': 'America/Los_Angeles', 'US/Samoa': 'Pacific/Pago_Pago', 'W-SU': 'Europe/Moscow', + CET: 'Europe/Paris', + CST6CDT: 'America/Chicago', + EET: 'Europe/Sofia', + EST: 'America/Cancun', + EST5EDT: 'America/New_York', + HST: 'Pacific/Honolulu', + MET: 'Europe/Paris', + MST: 'America/Phoenix', + MST7MDT: 'America/Denver', + PST8PDT: 'America/Los_Angeles', + WET: 'Europe/Lisbon', }; export {timezoneBackwardMap}; diff --git a/src/libs/IntlPolyfill/index.ts b/src/libs/IntlPolyfill/index.ts index 4f05fdbefd51..0828a6fc8d28 100644 --- a/src/libs/IntlPolyfill/index.ts +++ b/src/libs/IntlPolyfill/index.ts @@ -1,4 +1,3 @@ -import polyfillDateTimeFormat from './polyfillDateTimeFormat'; import polyfillNumberFormat from './polyfillNumberFormat'; import type IntlPolyfill from './types'; @@ -8,6 +7,5 @@ import type IntlPolyfill from './types'; */ const intlPolyfill: IntlPolyfill = () => { polyfillNumberFormat(); - polyfillDateTimeFormat(); }; export default intlPolyfill; diff --git a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts index 13eaaabbd8f4..52d8b68778f8 100644 --- a/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts +++ b/src/libs/IntlPolyfill/polyfillDateTimeFormat.ts @@ -1,36 +1,19 @@ import type {DateTimeFormatConstructor} from '@formatjs/intl-datetimeformat'; import DateUtils from '@libs/DateUtils'; +import {timezoneBackwardMap} from '@src/TIMEZONES'; -/* eslint-disable @typescript-eslint/naming-convention */ -const tzLinks: Record = { - 'Africa/Abidjan': 'Africa/Accra', - CET: 'Europe/Paris', - CST6CDT: 'America/Chicago', - EET: 'Europe/Sofia', - EST: 'America/Cancun', - EST5EDT: 'America/New_York', - 'Etc/GMT': 'UTC', - 'Etc/UTC': 'UTC', - Factory: 'UTC', - GMT: 'UTC', - HST: 'Pacific/Honolulu', - MET: 'Europe/Paris', - MST: 'America/Phoenix', - MST7MDT: 'America/Denver', - PST8PDT: 'America/Los_Angeles', - WET: 'Europe/Lisbon', -}; /* eslint-enable @typescript-eslint/naming-convention */ 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. let currentTimezone = DateUtils.getCurrentTimezone().selected as string; - if (currentTimezone in tzLinks) { - currentTimezone = tzLinks[currentTimezone]; + + if (currentTimezone in timezoneBackwardMap) { + currentTimezone = timezoneBackwardMap[currentTimezone]; } - require('@formatjs/intl-datetimeformat/polyfill-force'); + require('@formatjs/intl-datetimeformat/polyfill'); require('@formatjs/intl-datetimeformat/locale-data/en'); require('@formatjs/intl-datetimeformat/locale-data/es'); require('@formatjs/intl-datetimeformat/add-all-tz');