-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[AdapterLuxon]: Getting error when using pt-BR
locale and macro token DD
#10177
Comments
The expanded format of @alexfauquette for me the problem is that The only solution I see to support it would be to totally stop throwing when we have a an unknown token and instead add it as a separator. The following diff works and does not cause any test to fail: --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts
+++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts
@@ -20,16 +20,11 @@ import { getMonthsInYear } from '../../utils/date-utils';
export const getDateSectionConfigFromFormatToken = <TDate>(
utils: MuiPickersAdapter<TDate>,
formatToken: string,
-): Pick<FieldSection, 'type' | 'contentType'> & { maxLength: number | undefined } => {
+): Pick<FieldSection, 'type' | 'contentType'> & { maxLength: number | undefined } | null => {
const config = utils.formatTokenMap[formatToken];
if (config == null) {
- throw new Error(
- [
- `MUI: The token "${formatToken}" is not supported by the Date and Time Pickers.`,
- 'Please try using another token or open an issue on https://github.com/mui/mui-x/issues/new/choose if you think it should be supported.',
- ].join('\n'),
- );
+ return null
}
if (typeof config === 'string') {
@@ -413,7 +408,7 @@ export const changeSectionValueFormat = <TDate>(
newFormat: string,
) => {
if (process.env.NODE_ENV !== 'production') {
- if (getDateSectionConfigFromFormatToken(utils, currentFormat).type === 'weekDay') {
+ if (getDateSectionConfigFromFormatToken(utils, currentFormat)?.type === 'weekDay') {
throw new Error("changeSectionValueFormat doesn't support week day formats");
}
}
@@ -512,10 +507,13 @@ export const splitFormatIntoSections = <TDate>(
const commitToken = (token: string) => {
if (token === '') {
- return null;
+ return true;
}
const sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
+ if (sectionConfig == null) {
+ return false
+ }
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(
utils,
@@ -566,7 +564,7 @@ export const splitFormatIntoSections = <TDate>(
modified: false,
});
- return null;
+ return true;
};
// Expand the provided format
@@ -611,7 +609,14 @@ export const splitFormatIntoSections = <TDate>(
escapedPartOfCurrentChar?.end === i;
if (!isEscapeBoundary) {
- commitToken(currentTokenValue);
+ const success = commitToken(currentTokenValue);
+ if (!success) {
+ if (sections.length === 0) {
+ startSeparator += currentTokenValue;
+ } else {
+ sections[sections.length - 1].endSeparator += currentTokenValue;
+ }
+ }
currentTokenValue = '';
if (sections.length === 0) { |
The
Their are two issue with
|
@flaviendelangle Your solution is to test if the token exist, and if no, put it into the separator. For now, it works without problem. If we solve #10007 it will fail, because the parser will be able to detect the |
That's true... |
Just opened an issue in luxon to see how we can fix it: moment/luxon#1511 |
https://github.com/moment/luxon/blob/5ea19fb0cc80cddd03c6af21588b5ad7dcecaa35/src/datetime.js#L937 I fear that this is intented and that they won't be able to do anything about it dues to the nature of the parsing that relis on the |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/s/stoic-thunder-6sx5k3
Steps:
pt-BR
format
on any component toDD
or another macro tokenCurrent behavior 😯
As mentioned above, when using the
AdapterLuxon
, the macro tokenDD
does not appear to work. I get the following error:If I use other locales, like
fr-FR
ores-MX
, it seems to work. I've only been able to reproduce this withpt
orpt-BR
. Interestingly,pt-PT
appears to work.Expected behavior 🤔
Not to bomb? I'd love for it to work, but at least it should maybe fallback to a default locale/format.
Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: