Visitar URL original
feat(@formatjs/intl-datetimeformat): add supported locales check to s… · formatjs/formatjs@59d297e · GitHub
Skip to content

Commit 59d297e

Browse files
committed
feat(@formatjs/intl-datetimeformat): add supported locales check to should-polyfill, fix #3066
1 parent c9dad00 commit 59d297e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎packages/intl-datetimeformat/should-polyfill.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ function hasUnthrownDateTimeStyleBug(): boolean {
4242
}
4343
}
4444

45-
export function shouldPolyfill() {
45+
function supportedLocalesOf(locale?: string | string[]) {
46+
if (!locale) {
47+
return true
48+
}
49+
const locales = Array.isArray(locale) ? locale : [locale]
50+
return (
51+
Intl.DateTimeFormat.supportedLocalesOf(locales).length === locales.length
52+
)
53+
}
54+
55+
export function shouldPolyfill(locale?: string | string[]) {
4656
return (
4757
!('DateTimeFormat' in Intl) ||
4858
!('formatToParts' in Intl.DateTimeFormat.prototype) ||
4959
!('formatRange' in Intl.DateTimeFormat.prototype) ||
5060
hasChromeLt71Bug() ||
5161
hasUnthrownDateTimeStyleBug() ||
52-
!supportsDateStyle()
62+
!supportsDateStyle() ||
63+
!supportedLocalesOf(locale)
5364
)
5465
}

0 commit comments

Comments
 (0)