question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Make DatePicker/TimePicker/Calendar date-library-agnostic

See original GitHub issue

Previous 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:closed
  • Created 6 years ago
  • Reactions:27
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

15reactions
hk-ngcommented, Oct 28, 2018

#10437 is closed. Should we reconsider date-library-agnostic solution here?

1reaction
otakustaycommented, Mar 6, 2018

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 a defaultProps value as official rc-date-utils

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date and Time Pickers for All - React Spectrum Libraries
When a user doesn't know what date they will select, it can be useful to offer a browsing experience using a calendar component....
Read more >
jQuery UI DatePicker date convert to RFC 3339 format
Currently working on the Google Calendar API and basically my end will provide Start and End date for user to pick the date...
Read more >
Dates And Times in a Razor Pages Form
These include options for managing the date and time, just the date or time, and for working with the month or week of...
Read more >
Top React date pickers for 2021 - LogRocket Blog
Top React date pickers for 2021 ; Follows Material UI design; Date/time picker; Date library agnostic; Localizable ; Date range picker; Calendar ......
Read more >
Top 10 Date Pickers in React (2021) Part 1 - YouTube
In this video tutorial, I will show you how to install and implement 10 different date pickers in React JS.I broke this video...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found