ng-matero / extensions

Angular Material Extensions Library.
https://ng-matero.github.io/extensions/
MIT License
400 stars 50 forks source link

Time-Parsing with `provideLuxonDatetimeAdapter` #308

Closed angelaki closed 2 weeks ago

angelaki commented 2 weeks ago

In your demo (https://ng-matero.github.io/extensions/components/datetimepicker/overview) I can put quite simple formats and the component / the adapter tries it's best to find the correct value (e.g. time-input 7 gets pared to 07:00. But using your LuxonDatetimeAdapter it seams like I need to put in the absolute correct format.

Is this an issue of this adapter? Or am I configuring something wrong?

nzbin commented 2 weeks ago

Can you provide an online example?

angelaki commented 2 weeks ago

Just cloned your repo and just needed to change that single line:

https://github.com/ng-matero/extensions/blob/18cf6d5a53240af533bd7447e28666bf1c6b3bcc/projects/dev-app/src/app/datetimepicker/datetimepicker-demo.component.ts#L54

Replace it with provideLuxonDatetimeAdapter and you'll notice that from now on you need to pass the exact format on input while with the provideMomentDatetimeAdapter the input gets parsed / auto-corrected.

nzbin commented 2 weeks ago

The date formats of moment and luxon are different. You can't just replace the provide* API. Please check the issue #141 https://github.com/ng-matero/extensions/blob/18cf6d5a53240af533bd7447e28666bf1c6b3bcc/projects/extensions-luxon-adapter/adapter/luxon-datetime-formats.ts#L3-L22

angelaki commented 2 weeks ago

@nzbin yeah, sorry. Should have noted that format doesn't make a difference. If you just put provideMomentDatetimeAdapter() (falling back to default settings) vs. provideLuxonDatetimeAdapter() (same) Moment works but Luxon doesn't.