Skip to content
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

Add DateAdapter for date-fns #10278

Closed
victornoel opened this issue Mar 6, 2018 · 10 comments
Closed

Add DateAdapter for date-fns #10278

victornoel opened this issue Mar 6, 2018 · 10 comments
Assignees
Labels
area: material/datepicker feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue P4 A relatively minor issue that is not relevant to core functions

Comments

@victornoel
Copy link

Bug, feature request, or proposal:

Feature Request

What is the use-case or motivation for changing an existing behavior?

It would be great to be able to use date-fns instead of javascript Date or moment.js with the date picker.
The feature was refused in the past because date-fns didn't support parsing but nowadays it does: https://date-fns.org/v1.29.0/docs/parse

@djleonskennedy
Copy link

@victornoel we've done by ourselves, you've got all that you need, Just implement and provide
https://github.com/angular/material2/blob/535dcf1782806510f70e9f0888396327c3a36d59/src/lib/core/datetime/date-adapter.ts

material's team should not waste time to implement adapters for each date library

@josephperrott josephperrott added feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue P4 A relatively minor issue that is not relevant to core functions labels Mar 7, 2018
@jleufven
Copy link

Isn't date-fns just operations on native Date? We're using date-fns and use the NativeDateAdapter, we haven't fixed the parsing yet though, but it should be easy to base it on NativeDateAdapter and add the parsing.

@victornoel
Copy link
Author

@jleufven you are right, in the end that's what I do too, I use NativeDateAdapter + date-fns in the rest of my code.
Maybe I should close this, @josephperrott?

@mmalerba
Copy link
Contributor

mmalerba commented Apr 9, 2018

I think this may still be worth doing. There's some weird time zone corner cases that people sometimes run into with NativeDateAdapter. Making one that uses date-fns under the hood might fix some of those issues for people that choose to use it

@pfeigl
Copy link
Contributor

pfeigl commented Apr 30, 2018

I have been looking into this today and created some test code, but would currently wait with a final implementation:

When doing the actual implementation, we need to figure out the best API for setting the locale, as there is no equivalent to moment.locale(). Instead the locale has to be passed to any date-fns call (see https://date-fns.org/docs/I18n), but the API of DateAdapter is based on LOCALE_ID.

So we might end up in a situation, where the consumer has to populate the loaded locales into a mapping structure which is provided to the DateFnsDateAdapter.

Question regarding package-names: we currently have @angular/material-moment-adapter, should we just blindly add @angular/material-date-fns-adapter or should we consider merging into something like @angular/material-date-adapters/(material|date-fns|etc)

@JoniJnm
Copy link

JoniJnm commented Jan 4, 2019

I use this one:

https://gist.github.com/JoniJnm/412325c073805437c68430b11407e11b

@Goldman90
Copy link

is there chance this will be implemented?

@vincentpalita
Copy link

@JoniJnm I used the gist you gave and this was working fine but never setting the value at first.
It was missing the method deserialize that is used by DateAdapter.

@jelbourn
Copy link
Member

Tracking this in #20599 going forward

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/datepicker feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests