fix(date-picker): fix invalid date due to mismatch between date and format #2789
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Background and context
问题:日期选择器中当传入的值与format不一致的时候会出现Invalid Date 导致组件无法正常运作。
由于范围选择器就算不设置
format
但开启showTime
时内部会默认给YYYY-MM-DD HH:mm:ss
所以表现尤为明显原因:
追溯到全局组件通用
date.ts
函数文件中dayjs扩展的
customParseFormat
插件使用条件如它文档第一句也就是传入的字符串格式需要和format
尽可能一致(特性bug👀)官网表现如图:
https://day.js.org/docs/zh-CN/parse/string-format
Solution
添加了有效日期校验 不满足时返回正常对象,进行输出兜底以保证组件正常运作。
How is the change tested?
Changelog
Checklist:
npm run test
)feature
branch and othersshould be submitted to
main
branch)Other information