Skip to content

fix(common): handle locales with existing Unicode extension (e.g. ar-u-nu-arab)#84

Open
crossi-dev wants to merge 1 commit into
formkit:mainfrom
crossi-dev:fix/68-locale-unicode-extension-hc
Open

fix(common): handle locales with existing Unicode extension (e.g. ar-u-nu-arab)#84
crossi-dev wants to merge 1 commit into
formkit:mainfrom
crossi-dev:fix/68-locale-unicode-extension-hc

Conversation

@crossi-dev

Copy link
Copy Markdown

Fixes #68

Problem

format() throws RangeError: Invalid language tag when the locale already carries a Unicode extension block, e.g. ar-u-nu-arab (Arabic with Arabic-Indic numerals).

The cause is in createPartMap (src/common.ts): it pins the hour cycle by string-concatenating the extension onto the locale —

const preciseLocale = `${locale}-u-hc-${hour12 ? "h12" : "h23"}`

For ar-u-nu-arab this produces ar-u-nu-arab-u-hc-h23, which is invalid BCP 47 — a tag may only contain one -u- block. Intl.DateTimeFormat then throws.

Fix

Use Intl.Locale, which understands the BCP 47 grammar and merges extension subtags into a single, valid -u- block (preserving -nu-arab):

const preciseLocale = new Intl.Locale(locale, {
  hourCycle: hour12 ? "h12" : "h23",
}).toString()

One-line logic change, plus a regression test.

Verified

  • New test (does not throw when locale includes a numbering system) fails before the change with the exact RangeError, passes after.
  • Full suite: zero regressions — the same pre-existing failures on main (machine-local timezone-offset expectations), +1 net passing.

Came across Tempo and noticed #68 had been open a while, so I went ahead and fixed it. No strings attached — I'm with Choreless and we like contributing real fixes to projects we use. If it's useful and you ever want a hand with something larger, happy to help.

— Charles

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Formkit Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue : format function throw error when locale passed including numbering system ( ar-u-nu-arab )

1 participant