ng-matero/extensions

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

fomin-grigorich opened this issue · 6 comments

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.

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

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) ?

@JelleBruisten Do you know this issue?

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

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

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.