ng-matero / extensions

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

Strange input behaviour with NativeDateAdapter and 'no' MAT_DATE_LOCALE (Datetimepicker) #314

Open fomin-grigorich opened 1 month ago

fomin-grigorich commented 1 month ago

When I use a pair of providers with next module

providers: [provideNativeDatetimeAdapter(), {provide: MAT_DATE_LOCALE, useValue: 'no'}], imports: [MtxDatetimepickerModule]

and try to change date/time directly in input the result date is switching day and month places. Example: I try to change time (directly in input) to 13:00 in 01.02.2024 12:00 and get result date as 02.01.2024 13:00 (day and month changed places).

This is not happening when I don't use MAT_DATE_LOCALE.

nzbin commented 1 month ago

I hope you can use other adapters instead of NativeDateAdapter. Checkout #141

fomin-grigorich commented 4 weeks ago

Sure, I can use provideMomentAdapter() but MAT_DATE_LOCALE: 'no' is not working with it. Maybe you know how to provide MAT_DATE_LOCALE with 'no' (Norwegian) ?

nzbin commented 3 weeks ago

@JelleBruisten Do you know this issue?

JelleBruisten commented 3 weeks ago

Not sure, but isn't norwegian locale no-NO?

fomin-grigorich commented 3 weeks ago

MAT_DATE_LOCALE works the same for both: no and no-No

JelleBruisten commented 3 weeks ago

I checked the sourceCode and the native datatime adapter doesn't really do much with locale, and our dataAdapters extend the angular one which likely uses the LOCALE_ID or MAT_LOCALE_ID. With adding support for time since the lack off a datetime picker from angular itself.

Quote:

Please note: provideNativeDateAdapter is based off the functionality available in JavaScript's native Date object. Thus it is not suitable for many locales. One of the biggest shortcomings of the native Date object is the inability to set the parse format. We strongly recommend using an adapter based on a more robust formatting and parsing library. You can use provideMomentDateAdapter or a custom DateAdapter that works with the library of your choice.

https://material.angular.io/components/datepicker/overview#setting-the-locale-code

Few things you could try is setting the LOCALE_ID within your angular application doubt it will work but worth a try, else I would recommend using a different strategy.