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

date-picker's format prop not localized when using date-fns localized date string (e.g. PP) #250

Closed
wc-matteo opened this issue Jun 22, 2021 · 9 comments
Assignees

Comments

@wc-matteo
Copy link

TuSimple/naive-ui version (版本)

2.13.0

Vue version (Vue 版本)

3.1.2

Browser and its version (浏览器及其版本)

Chrome 91.0.4472.106

System and its version (系统及其版本)

Windows 10

Node version (Node 版本)

Reappearance link (重现链接)

https://codesandbox.io/s/affectionate-browser-e13mu?file=/src/Demo.vue

Reappearance steps (重现步骤)

Select the chinese locale
Select a date
Observe the formatted value in the date-picker field

Expected results (期望的结果)

The format of the date matches the locale

Actual results (实际的结果)

The format of the date is always in the english locale

Remarks (补充说明)

@07akioni
Copy link
Collaborator

07akioni commented Jun 23, 2021

It seems to be the problem of date-fns.

Please see https://codesandbox.io/s/sleepy-ardinghelli-320ju?file=/src/index.js

image

@wc-matteo
Copy link
Author

wc-matteo commented Jun 23, 2021

https://codesandbox.io/s/confident-johnson-w6ky5?file=/src/index.js:35-72

with my locale (italian, it) it works correctly

it seems to work for spanish (es), french (fr) and german (de) as well

@wc-matteo
Copy link
Author

wc-matteo commented Jun 23, 2021

I'm not really that familiar with date-fns but as far as I can see you need to provide a locale option for every function call (e.g. format)

@07akioni
Copy link
Collaborator

I'm not really that familiar with date-fns but as far as I see you need to provide a locale option for every function call (e.g. format)

Yes, I use it because it's treeshakable. However I just expose a number interface outside, if you want use other libs it's not hard.

@07akioni
Copy link
Collaborator

07akioni commented Jun 23, 2021

If you need more locale please create a PR and add the locale you needed.

@wc-matteo
Copy link
Author

wc-matteo commented Jun 23, 2021

I created an italian locale for my project. I'll submit a pr once I'm sure it's all good 👍🏿

@wc-matteo
Copy link
Author

wc-matteo commented Jun 23, 2021

would you consider adding the locale parameter to format's date-fns function. Here for example: https://github.com/TuSimple/naive-ui/blob/main/src/date-picker/src/DatePicker.tsx#L336
?

@07akioni
Copy link
Collaborator

https://github.com/TuSimple/naive-ui/blob/main/src/date-picker/src/DatePicker.tsx#L336

Sure, it seems to be a bug.

@07akioni 07akioni reopened this Jun 23, 2021
@07akioni
Copy link
Collaborator

Some format hasn't been passed in with locale options.

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

3 participants