mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.16k stars 1.3k forks source link

[pickers] dateFormats doesn't work on weekday #5222

Closed Mae623 closed 2 years ago

Mae623 commented 2 years ago

Duplicates

Latest version

Current behavior 😯

This is the current weekdays text in Chinese on date picker. 1971655362607_ pic I try to use dateFormats, but it doesn't work. 1981655362657_ pic

Expected behavior 🤔

I want the weekdays text can be displayed as “ 日 一 二 三 四 五 六" or “ 一 二 三 四 五 六 日" , depending on the start day of the week. In fact, most of my users want the latter pattern. Thank you very much!

Steps to reproduce 🕹

Codesandbox : https://codesandbox.io/s/nervous-lalande-uj9h5s?file=/src/App.js

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo ``` Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here. ```

Order ID 💳 (optional)

No response

alexfauquette commented 2 years ago

I'm sorry, I've no notion about Chinese so I may not fully understand your question

Displayed character

For the day header, we use getWeekdays() from the 'date-io' adapter and we display the first character in upper case

For moment.js this corresponds to moment.weekdaysShort(true)

From the returned value ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] I bet means "day" and the second character is the week number 🕵

Since you only whant one character, you can get it with the folowing customization of moment.js

moment.updateLocale("zh-cn", {
  weekdaysShort: ["一", "二", "三", "四", "五", "六", "日"]
});

On our side, we should remove the 1 character limitation to be more flexible

Start date

The definition of what is a week is under the responsibility of your date library. For moment, you can have a look to dow (day of week) property: https://momentjs.com/docs/#/customization/dow-doy/

Example

https://codesandbox.io/s/eloquent-hill-0j5d86?file=/src/App.js

Mae623 commented 2 years ago

moment.updateLocale("zh-cn", { weekdaysShort: ["一", "二", "三", "四", "五", "六", "日"] });

By using this way, my problem solved. Thank you very much!

From the returned value ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] I bet 周 means "day" and the second character is the week number 🕵

The second character is the week number , but "周" means "week".

On our side, we should remove the 1 character limitation to be more flexible

This change will be wisdom. For example, the Monday in Chinese not only can be translated to "周一", but also could be "星期一”. "星期" means "week" too.

alexfauquette commented 2 years ago

I just reopen the issue such that we can track improvements to do

flaviendelangle commented 2 years ago

Related to https://github.com/mui/mui-x/pull/4472

flaviendelangle commented 2 years ago

@alexfauquette is this fixed by the new dayOfWeekFormatter prop ?

alexfauquette commented 2 years ago

Yes it is 🎉

HoAnhVan commented 3 months ago

For dayjs:

<DesktopDatePicker label="Date" dayOfWeekFormatter={(_, weekday:any)=> { return dayjs(weekday).format('dd'); }}/>