extensions icon indicating copy to clipboard operation
extensions copied to clipboard

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

Open fomin-grigorich opened this issue 1 year ago • 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.

fomin-grigorich avatar Jun 05 '24 09:06 fomin-grigorich

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

nzbin avatar Jun 07 '24 16:06 nzbin

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

fomin-grigorich avatar Jun 10 '24 08:06 fomin-grigorich

@JelleBruisten Do you know this issue?

nzbin avatar Jun 11 '24 14:06 nzbin

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

JelleBruisten avatar Jun 11 '24 20:06 JelleBruisten

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

fomin-grigorich avatar Jun 11 '24 20:06 fomin-grigorich

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.

JelleBruisten avatar Jun 12 '24 07:06 JelleBruisten