-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
CustomParseFormat doesn't parse double digit days and months properly in strict mode #902
Comments
The question comes to is "01.02.2020" an invalid date string to "D.M.YYYY" format? Since |
Thanks for the fast reacton. I would tend to agree as well, if this wasn't supported in moment.js. And since there isn't support for multiple formats #817 the only solution i could come up with is try to parse date with each of the possible formats and find the first that is valid. |
We can have this, a nice enhancement, right? |
dayjs('01.02.2020', ['D.M.YYYY', 'DD.MM.YYYY'], true) |
Thanks, this will help. |
Could this be added for "YY" as well? |
you can pass your formats to the second parameter as an array. |
Thank you @iamkun. I know, but the question was if YY could also accept values having YYYY - same as for D and DD. |
@geri777 what I mean is |
@iamkun Hi passing formats in array does not seem to work. But passing single format as string is working Am I missing anything? |
Tried it today with dayjs v1.11.2: in both examples I get Day=5 and Month=1. Which version did you use? |
Describe the bug
When in strict mode, format "D.M.YYYY" should parse both "1.1.2020" and "01.01.2020", but it fails with Invalid date for the second.
https://runkit.com/embed/w5jkq082wagg
moment.js works this way moment/moment#2554
there even seems to be code for this https://github.com/iamkun/dayjs/blob/dev/src/plugin/customParseFormat/index.js (regexes match1to2) but probably doesn't work.
Expected behavior
dayjs("01.02.2020", "D.M.YYYY", true) should be parsed correctly
Information
The text was updated successfully, but these errors were encountered: