-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Fix incorrect date validation from dayjs #608
Conversation
ModificationsI've been analyzing it better and I realized that the best way to use localization is really using the localization string, but remembering that this only works if the localization file for the desired language is imported previously. |
The biggest question from me – will it require breaking change? If not - I will be happy to merge it and release right now |
Codecov Report
@@ Coverage Diff @@
## master mui/material-ui#608 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 1450 1450
Branches 191 191
=========================================
Hits 1450 1450
Continue to review full report at Codecov.
|
No, it does not require a breaking change. In fact, after this change, date-io/dayjs will have the same behavior as date-io/datefns, date-io/moment and others, as it will correctly deliver the validated dates and indicating if there are errors. |
I even noticed that the |
Yes, it was discussed in mui/material-ui#588. |
With your reverts, this PR is exactly the same as mui/material-ui#599. |
Can you guys merge either mui/material-ui#599 OR mui/material-ui#608 ? Changes are equal... but the fix would be great... 😃 @dmtrKovalenko |
❤️ @dmtrKovalenko awesome! 👍 thanks a lot! |
What is the problem?
As shown at mui/mui-x#6983 and mui/mui-x#6984, there is a problem validating dates using dayjs.
I noticed that the parse function uses dayjs parse without strict format, causing dayjs to convert any date, even if incorrect, e.g. "99/99/2000" to a correct date, and due to this, all other functions used later (date, isValid, etc) do not have ability to validade dates, as they will always receive a supposedly valid date.
This issue is the same as mui/material-ui#599
What did I do?
local
here and here from string toILocale
, because it's the type passed by dayjsthis.locale
was called as string tothis.locale?.name
, because it's the equivalentthis.dayjs(value, format, this.locale)
tothis.dayjs(value, format, this.locale?.name, true)
, enabling strict mode.Note
I'm working with material-ui DatePickers, and with my changes, pickers work perfectly