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

Locale parsing with unmatched dash locale overrides global #2575

Open
joshualyon opened this issue Feb 12, 2024 · 0 comments
Open

Locale parsing with unmatched dash locale overrides global #2575

joshualyon opened this issue Feb 12, 2024 · 0 comments

Comments

@joshualyon
Copy link

When making an instance call to set a locale, if the locale is supplied including the country code, but dayjs only has the generic language code, the global instance locale ends up getting overwritten.

For example, dayjs has the locale nb but if the full language tag with the country code is supplied to an instance locale() update such as nb-no, the global instance locale will get changed.

[
   dayjs.locale(),          //en
   dayjs().locale('nb-no'), //nb
   dayjs.locale()           //nb  !!global locale is changed!!
]

I suspect it's related to this fallback scenario in parseLocale() where the supplied locale is split and just the first part is recursively passed into parseLocale(), but it does not pass forward the additional parameters, so isLocal is not passed forward which ultimately causes the recursive locale parsing to improperly set the global instance locale.

dayjs/src/index.js

Lines 26 to 29 in bdcc336

const presetSplit = preset.split('-')
if (!l && presetSplit.length > 1) {
return parseLocale(presetSplit[0])
}

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

No branches or pull requests

1 participant