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

FormatDistance doesn't work the same way for all locales #3805

Open
rezof opened this issue May 16, 2024 · 2 comments
Open

FormatDistance doesn't work the same way for all locales #3805

rezof opened this issue May 16, 2024 · 2 comments

Comments

@rezof
Copy link

rezof commented May 16, 2024

The issue:

formatDistance returns words instead of numbers in certain locales & formatDuration has the issue as well since it uses the locale function formatDuration.

for Example:

sv

const duration =  {years: 1, days: 25, months: 3};
formatDuration(duration, { format, zero, delimiter, locale }); // =>  "ett år, tre månader, 25 dagar"

en :

const duration =  {years: 1, days: 25, months: 3};
formatDuration(duration, { format, zero, delimiter, locale }); // =>  "1 year, 3 months, 25 days"

i believe the correct behavior is the second since the majority of the locales return numbers & not words.
The sv locale has a wordMapping array (word for numbers < 13) which does not exist in other locales, maybe a leftover from old API

@rezof
Copy link
Author

rezof commented May 16, 2024

Am up to create a PR to fix this issue.

@cupofjoakim
Copy link

+1 on this issue. We support a multitude of languages and really enjoy having date-fns here, but right now we have to monkey patch sv and nn due to this behaviour.

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

2 participants