react-component / picker

📅 All Date Pickers you need.
https://picker.react-component.now.sh/
MIT License
273 stars 315 forks source link

DayJs time picker strange behavior #346

Open Vincz opened 2 years ago

Vincz commented 2 years ago

Following ant design directive to generate picker from DayJs, here is a sandbox: https://codesandbox.io/s/sparkling-silence-i430q

Try to type 10:10:1 in the input field and it is replaced by 10:10:01. So we cannot input 10:10:10 using the text input. I think it is something related to the fact that 10:10:0 is considered valide from DayJs perspective and the corresponding time is 10:10:00. Maybe rc-picker should wait for the final input before parsing with dayjs?

After further investigation, dayjs has an open for strict parsing that should be used:

dayjs("10:10:1", "HH:mm:ss", null, true) // Invalid date
dayjs("10:10:1", "HH:mm:ss") // Valid but false as it resolved to 10:10:01

We could get rid of this problem at this line https://github.com/react-component/picker/blob/234dd2a2659effad08a8e65bfd15f3c8d8bdfbd5/src/generate/dayjs.ts#L118

munepom commented 2 years ago

I also thought this behavior is strange...