Skip to content

Commit

Permalink
feat(@formatjs/intl-datetimeformat): add supported locales check to s…
Browse files Browse the repository at this point in the history
…hould-polyfill, fix #3066
  • Loading branch information
longlho committed Jul 24, 2021
1 parent c9dad00 commit 59d297e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/intl-datetimeformat/should-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ function hasUnthrownDateTimeStyleBug(): boolean {
}
}

export function shouldPolyfill() {
function supportedLocalesOf(locale?: string | string[]) {
if (!locale) {
return true
}
const locales = Array.isArray(locale) ? locale : [locale]
return (
Intl.DateTimeFormat.supportedLocalesOf(locales).length === locales.length
)
}

export function shouldPolyfill(locale?: string | string[]) {
return (
!('DateTimeFormat' in Intl) ||
!('formatToParts' in Intl.DateTimeFormat.prototype) ||
!('formatRange' in Intl.DateTimeFormat.prototype) ||
hasChromeLt71Bug() ||
hasUnthrownDateTimeStyleBug() ||
!supportsDateStyle()
!supportsDateStyle() ||
!supportedLocalesOf(locale)
)
}

0 comments on commit 59d297e

Please sign in to comment.