Comments (6)
The expanded format of DD
for the locale pt-BR
is d de MMM de yyyy
Where de
is not a format token but is not escaped either.
@alexfauquette for me the problem is that de
looks a lot like a format, so it matches isTokenStartRegExp
.
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) {
from mui-x.
The DD
format is expended as
d de MMM de yyyy
forpt-BR
d/MMM/yyyy
forpt-PT
Their are two issue with d de MMM de yyyy
format:
- On our side: we do not consider that
de
could be a token just because their is a tokend
(related to the issue about supporting formatddMMMYYYYY
) - On luxon side with
DateTime.expandFormat('DD', { locale: 'pt-BR' })}
returningd de MMM de yyyy
because thede
should be'de'
.
For example,DateTime.fromISO('2014-08-06T13:07:04.054').toFormat('d de MMM de yyyy', { locale: 'pt-PT', })
returns6 6e 08 6e 2014
from mui-x.
@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 d
as a token and we will get the 6 6e 08 6e 2014
.
from mui-x.
That's true...
And if we only do it if the character after is a space?
The amount of use cases not covered would get smaller and smaller.
from mui-x.
Just opened an issue in luxon to see how we can fix it: moment/luxon#1511
from mui-x.
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 Intl
API.
from mui-x.
Related Issues (20)
- [DataGrid] Use of `isCellEditable` causes entire row to toggle its editability, rather than single cell HOT 14
- [DatePicker] Opening a DatePicker throws an error and month change icon doesn't work HOT 5
- [DataGrid] Can a custom filtering implementation make use of MUI's filter state? HOT 8
- [pickers] The DatePicker 'onAccept' event fires both when clicking on the Ok button and also when clicking outside the Picker (or pressing ESC), if the date has changed HOT 2
- Line chart legend overlap with the rest of the chart HOT 3
- [charts] Line chart highlight mark customisation HOT 4
- [charts] How to display given time as local time in a LineChart HOT 9
- How can I have a select element with search when inline edit? HOT 1
- [DataGrid] Please upgrade `reselect` to `^5.0.1` to be the same as in `@reduxjs/toolkit` HOT 3
- [DataGrid] Filterpanel resets state after every fetch HOT 5
- [charts] Wrong proptypes generated
- [DataGrid] Grouping by a column of type "singleSelect" results in filtering not working for that column (rowGroupingMode="multiple") HOT 2
- [DateTimePicker] closeOnSelect={true} not working properly HOT 1
- [DataGrid] GridColDef - Add a metadata property or allow a type override to extend the type HOT 1
- [DataGrid] DataGridPro type check fails at build with themeAugmentation HOT 5
- [DataGrid] Consider bringing back the error overlay HOT 4
- [DataGrid] `onRowsScrollEnd` triggered when applying filters HOT 8
- [DataGrid] How can I see the full row when I reorder the row HOT 4
- [DatePicker] `openPickerIcon` outside of the field with standard variant HOT 2
- [data grid] `onCellEditStop` is called when cell has error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.