themesberg / flowbite-datepicker

A Tailwind CSS datepicker built with vanilla JavaScript
https://flowbite.com/docs/components/datepicker/
MIT License
139 stars 43 forks source link

Using unusual date formats cause strange datepicker behavior #40

Open stooczu opened 5 months ago

stooczu commented 5 months ago

Using wierd formats like DDD dd MM yyyy or DD • dd MM yyyy cause datepicker to select a date different to what user has selected when unfocused.

As long as datepicker is focused, everything works ok.

image

but the date will change when clicked outside the component:

image

Seems like unfocusing the component triggers processing datepicker value. When you click on the calendar cell, the value it holds is epoch which lets datepicker to process and format the value correctly. When unfocused, the value beeing processed is no longer the epoch value, but it processes the displayValue - in this case it's Thursday • 10 October 2024. Datepicker starts to process displayValue instead of value which causes it to bug.

Funny thing is the vanilla JS Date class is handles this wierd formatting correctly. >new Date('Thursday • 10 October 2024') Thu Oct 10 2024 00:00:00 GMT+0200