react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Manually entering an invalid date causes some completely different date to be used

Open Suppen opened this issue 3 years ago • 4 comments

Describe the bug In my company, we use the Norwegian date format dd.MM.yyyy. The problem may or may not exist in other date formats.

Let's say someone fatty-fingers when manually inputting a date (as opposed to picking one from the calendar) and writes 29.02.2023. This is an invalid date; 2023 is not a leap year. This turns into the date 2020-02-29, which is a valid date (2020 was a leap year).

Why does this happen? By testing, I have concluded that DatePicker uses the last date it saw and understood. That means that while the user was typing, the input at some point read 29.02.20. DatePicker saw 20 as the short version of 2020, giving the date 2020-02-29.

Note: This is not limited to the leap day. Typing 31.04.2023 becomes 2023-02-03 for some reason. Exactly what it becomes appears to be dependent on the current month.

To Reproduce Steps to reproduce the behavior:

  1. Create a datepicker with format dd.MM.yyyy
  2. Manually enter the date 29.02.2023
  3. Blur the input. The date changes to 29.02.2020. It requires a watchful eye to catch this.

Expected behavior The date should be recognized as invalid. I'm not sure how this should be displayed to the user, but the value should be an invalid date object. At least not one representing a completely different date than what is shown.

Suppen avatar Feb 06 '23 13:02 Suppen

Hey , do you got any solution to this problem ?

tanishq1502 avatar Mar 28 '23 07:03 tanishq1502

I don't have a solution (this would be a PR fixing the bug), let's say a temporary workaround

HynekS avatar Apr 21 '23 06:04 HynekS

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Jun 04 '24 01:06 github-actions[bot]

I have just seen similar error. If you use startDate parameter, as far as I understand you sould send the value of startDate parameter with new Date().

Look at that: <ReactDatePicker startDate={new Date(date)}/>

I have not seen any error about invalid date for "selected or minDate"

I hope I could help

muhatas avatar Nov 27 '24 12:11 muhatas

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Oct 07 '25 02:10 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Nov 14 '25 02:11 github-actions[bot]