RFC: Make DatePicker/TimePicker/Calendar date-library-agnostic
See original GitHub issuePrevious discussions https://github.com/ant-design/ant-design/issues/5677, https://github.com/ant-design/ant-design-mobile/issues/1217.
Motivation
moment
do have some downsides like it’s mutable value and un-modular. And it’s road to modular seems very slow. I also found that the moment team is writing another date library called luxon. It would be a big improvement if we can make our date related components date-library-agnostic.
Detailed design
Create a rc-date-util
package. It only contains one line:
export default from 'rc-moment-adapter';
rc-moment-adapter
wraps all APIs which date components used.
All date related components use rc-date-util
instead of using moment
directly.
People can change date library through webpack’s alias:
// webpack.config.js
module.exports = {
resolve: {
alias: {
'rc-date-util': 'rc-date-fns-adapter',
}
}
}
Browserify users can use aliasify:
{
"aliasify": {
"aliases": {
"rc-date-util": "rc-date-fns-adapter",
}
}
}
After aliasing rc-moment-adapter
to rc-date-fns-adapter
, all dates pass to callbacks should change to native date object as well.
const onChange = (date) => {
console.log(date); // Native date object.
}
<DatePicker onChange={onChange} />
This change won’t effects any users who don’t want to change moment to other date library.
Drawbacks
Rely on build tool config.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:27
- Comments:10 (7 by maintainers)
Top GitHub Comments
#10437 is closed. Should we reconsider date-library-agnostic solution here?
Depending on build tools to implement type adapters is not a good solution, why don’t we just make
dateUtil
as a prop of date pickers with adefaultProps
value as officialrc-date-utils