Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use polyfill instead of polyfill-force for @formatjs/intl-datetimeformat #43158

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/TIMEZONES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,17 @@ const timezoneBackwardMap: Record<string, (typeof TIMEZONES)[number]> = {
'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};
Expand Down
2 changes: 0 additions & 2 deletions src/libs/IntlPolyfill/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import polyfillDateTimeFormat from './polyfillDateTimeFormat';
import polyfillNumberFormat from './polyfillNumberFormat';
import type IntlPolyfill from './types';

Expand All @@ -8,6 +7,5 @@ import type IntlPolyfill from './types';
*/
const intlPolyfill: IntlPolyfill = () => {
polyfillNumberFormat();
polyfillDateTimeFormat();
};
export default intlPolyfill;
27 changes: 5 additions & 22 deletions src/libs/IntlPolyfill/polyfillDateTimeFormat.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {
'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');
Expand Down
Loading