Skip to content

Commit

Permalink
feat(@formatjs/intl-relativetimeformat): update shouldPolyfill for In…
Browse files Browse the repository at this point in the history
…tl.RelativeTimeFormat (#3139)

Co-authored-by: Romain Menke <romainmenke@gmail.com>
  • Loading branch information
romainmenke and romainmenke authored Sep 6, 2021
1 parent 852e7c8 commit 0435ad1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/intl-relativetimeformat/should-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ function supportedLocalesOf(locale?: string | string[]) {
)
}

function hasResolvedOptionsNumberingSystem(locale?: string | string[]) {
try {
return (
'numberingSystem' in
new Intl.RelativeTimeFormat(locale || 'en', {
numeric: 'auto',
}).resolvedOptions()
)
} catch (_) {
return false
}
}

export function shouldPolyfill(locale?: string | string[]) {
return !('RelativeTimeFormat' in Intl) || !supportedLocalesOf(locale)
return (
!('RelativeTimeFormat' in Intl) ||
!supportedLocalesOf(locale) ||
!hasResolvedOptionsNumberingSystem(locale)
)
}

0 comments on commit 0435ad1

Please sign in to comment.