-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Just got the first letter of the days in dayOfWeekFormatter using Luxon Adapter on Date Calendar #9984
Comments
The docs API is outdated, we do not use the Now, it's the adapter For Luxon, it's public getWeekdays = () => {
return Info.weekdaysFormat('narrow', { locale: this.locale });
}; We could add a second parameter to provide the day index such that you could do whatever you want knowing it's the 5th day of the week |
So we can't no longer have the complete days ? |
Except if your date library allows you to define how a short date are rendered. For example, moment has the
Providing the week-day index to Do you want to open a PR for that? |
I did investigate this a bit more in depth and as it seems we do have 2 different functions that contradict each other a bit:
A fix for this is to just change the parameter for the --- a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts
+++ b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts
@@ -524,7 +524,7 @@ export class AdapterLuxon implements MuiPickersAdapter<DateTime, string> {
};
public getWeekdays = () => {
- return Info.weekdaysFormat('narrow', { locale: this.locale });
+ return Info.weekdaysFormat('long', { locale: this.locale });
};
public getWeekArray = (value: DateTime) => { applying the fix locally and using a custom
@flaviendelangle (tagging you, since @alexfauquette is still on PTO): do you see any problem with that fix? |
That is a really nice observation and suggestion! 👍 |
@flaviendelangle I just checked and the only place mui-x/packages/x-date-pickers/src/DateCalendar/DayCalendar.tsx Lines 556 to 566 in a071e54
I just noticed the current return value of DateFnsmui-x/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.ts Lines 545 to 551 in a071e54
returnValue: Luxonmui-x/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts Lines 526 to 528 in a071e54
returnValue: DayJSmui-x/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.ts Lines 682 to 687 in a071e54
returnValue: MomentJS
returnValue: this in itself is a problem, right? |
If we have some formats in the date libraries that would help us have a more consistent behaviors across adapters, we should clearly go for it. But I would not be surprised if not all date libraries support exactly the same formats for this topic. If you want to have a look 👌 |
@flaviendelangle should we maybe add a parameter (with it defaulting to the current return value) to the - getWeekdays(): string[];
+ getWeekdays(format: 'full'|'narrow'|'short'): string[]; Where ...
defaulting to WDYT? |
What would that accomplish? |
Strictly speaking the adapters are public API, but for this kind of BC, I prefer to create a new method and replace on the next major. I'm not a fan of the current API to format the day of the week. I would prefer if For me that's more flexible that passing a string and more coherent with the rest of our API. |
Agreed, I've also always felt that exposing date objects instead of strings to the formatter would end up being more flexible. 💯 |
That's what I was thinking. If anyone uses it we would potentially break that.
Yes... that would be ideal... I thought the same: having the restriction of passing a pure string to the formatter did seem a bit unflexible. I will come up with something. I do have enough info now to create a solution for that. Thanks y'all 🙇🏼 |
To give a little context |
By the way, we don't even need an adapter method, we have everything we need in the adapter without it, we just need to do what we are doing on the export const getWeekDays = <TDate>(utils: MuiPickersAdapter<TDate>, date: TDate) => {
const start = utils.startOfWeek(date);
return [0, 1, 2, 3, 4, 5, 6].map((diff) => utils.addDays(start, diff));
} And in |
But we would potentially break (even if just a few) applications that rely on this method, right? As mentioned this is pretty unlikely, but still possible, since it is technically an open API |
We can stop using the method and then remove the method during the next alpha. |
As far as I can tell, this breaks a solution people (including me) have been using for a few years to force Luxon to use Sunday as the first day of the week. #12821 Pretty niche use case but there are people out there that use custom adapters that depend on extending this method. I'm not really sure what the best way to solve this would be - perhaps adding a way to the LocalizationProvider for passing in a custom weekday array? |
@alexplumb Since 2021, I've been using the workaround noted in mui/material-ui-pickers#1270 to force Luxon to use Sunday as the first day of the week and just noticed that it no longer works. I was able to fix it by adding an override for the
Do you see any issue with this fix? |
Hi, Sorry for the broken behavior, we are discussing a potential cleaner solution in mui/material-ui#10805 |
Duplicates
Latest version
Steps to reproduce 🕹
Just a simple case of the Date Calendar
Current behavior 😯
In my console.log, i got
M, T, W, T, F, S, S
Expected behavior 🤔
I would like to get the complete day (as i think it is describe in the doc)
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
Context 🔦
I want to render the 3 first letter avec the day, like
Mon, Tue, Wed
....Your environment 🌎
npx @mui/envinfo
System:
OS: macOS 13.5
Binaries:
Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
Yarn: Not Found
npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
Browsers:
Chrome: 115.0.5790.170
Edge: Not Found
Safari: 16.6
npmPackages:
@emotion/react: ^11.11.1 => 11.11.1
@emotion/styled: ^11.11.0 => 11.11.0
@mui/base: 5.0.0-beta.8
@mui/core-downloads-tracker: 5.14.2
@mui/icons-material: ^5.14.0 => 5.14.1
@mui/lab: 5.0.0-alpha.137
@mui/material: ^5.14.0 => 5.14.2
@mui/private-theming: 5.13.7
@mui/styled-engine: 5.13.2
@mui/system: 5.14.1
@mui/types: 7.2.4
@mui/utils: 5.14.1
@mui/x-date-pickers: ^6.11.0 => 6.11.0
@types/react: ^18.0.14 => 18.2.16
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: ^5.1.6 => 5.1.6
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: