You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to wrap my head around what's the best approach, I still think it's missing a proper concept of parsers / formatters.
Data coming from the API is going to be in the ISO format 2017-05-24T10:38:28.434Z, now I have <input /> with formControl, if I implemented custom parse function, which would take the dateFormats.parse.dateInput, which should (I assume) be the format of the localized date my consumer actually write in the input and pass it to, in my case date-fns', parse function. Now the question is, what do I do with the format I receive from the API? Do I have to actually format it to the localized format beforepatchValueing it to my formControl, because otherwise the initial value, which would be in ISO format, would be different from subsequent edit by the user (those will be in the localized format).
I would recommend creating a date object from the API's response and patching that directly into the formControl (no need to reformat it in a new format).
I'll also mention that part of the reason for having separate parse and display formats is so you can support multiple parse formats, for example, you might have:
@mmalerba I'm not sure that would work.. setting of the initial value, which happens here uses the same parse format as the function that is called on inputchange.
Or you are saying that my custom parse function should handle both native Date as well as my localized input?
Yes, the NativeDateAdapter works with string, Date, and number. In general I think all implementations should at least support string and an instance of whatever date implementation that adapter operates on. It would probably be good to call this out in the method docs, would you mind creating a PR?
I'm using date-fns version that is not even public yet (the current version doesn't support parse with custom format) and I'm also using a custom copy of all datepicker / date-formats / adapter stuff, all variously modified since I needed to extend the datepicker with a datetimepicker mode.. it's not really easily sharable.
I made it. By extending the current datepicker. It also means I have to maintain my own version and manually apply all of the PRs, which sucks. But I simply couldn't proceed without a datetimepicker.
Nah, it's pretty crude. There's probably a private material design spec for a datetimepicker that the official version will be based on one day, so I'd be waste of time.
Activity
mmalerba commentedon May 24, 2017
I would recommend creating a date object from the API's response and patching that directly into the
formControl(no need to reformat it in a new format).I'll also mention that part of the reason for having separate parse and display formats is so you can support multiple parse formats, for example, you might have:
(with an appropriate
DateAdapterthat knows how to handle that).fxck commentedon May 24, 2017
@mmalerba I'm not sure that would work.. setting of the initial value, which happens here uses the same
parseformat as the function that is called oninputchange.Or you are saying that my custom parse function should handle both native Date as well as my localized input?
mmalerba commentedon May 24, 2017
Yes, the
NativeDateAdapterworks withstring,Date, andnumber. In general I think all implementations should at least supportstringand an instance of whatever date implementation that adapter operates on. It would probably be good to call this out in the method docs, would you mind creating a PR?fxck commentedon May 24, 2017
Sure. I'll just finish this date-fns adapter first.
areijngoudt commentedon May 25, 2017
@fxck can you share your date-fns based implementation when you finished it? I would like to use it :)
fxck commentedon May 25, 2017
I'm using date-fns version that is not even public yet (the current version doesn't support parse with custom format) and I'm also using a custom copy of all datepicker / date-formats / adapter stuff, all variously modified since I needed to extend the datepicker with a datetimepicker mode.. it's not really easily sharable.
But you can try and mess with it if you want, here's the build of the 2.0.0 of date-fns https://github.com/fxck/dfns-builds and here's the adapter https://gist.github.com/fxck/efe4ccff13d99ee9a2dcf82365909168 you'll have to remove the extra time related methods and fix some imports.
robindijkhof commentedon May 27, 2017
@fxck, how did you managed the get the timepicker? Is it a matter of writing your own dataAdapter or is it an undocumented feature?
fxck commentedon May 27, 2017
I made it. By extending the current datepicker. It also means I have to maintain my own version and manually apply all of the PRs, which sucks. But I simply couldn't proceed without a datetimepicker.
robindijkhof commentedon May 27, 2017
Is it published somewhere and may I use it? Or is it supposed to be a PR someday?
fxck commentedon May 27, 2017
Nah, it's pretty crude. There's probably a private material design spec for a datetimepicker that the official version will be based on one day, so I'd be waste of time.
angular-automatic-lock-bot commentedon Sep 5, 2019
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.