Bug: selected value handling in react-date-picker causes getMonth() errors
Description:
When using react-date-picker in modes like range or multiple, selecting a month by tapping on the month caption causes an error. This happens because the selected value can be a string, an object (from and to in range mode), or an array (multiple dates). Directly treating selected as a Date leads to errors when trying to call getMonth().
Steps to Reproduce:
- Use
react-date-picker in range or multiple mode.
- Tap on the month caption to select a month.
- Select any month.
- The error
TypeError: selected.getMonth is not a function occurs.
Expected Behavior:
getMonth() should only be called on valid Date objects, with proper checks for selected being a string, object, or array.
Actual Behavior:
TypeError: selected.getMonth is not a function occurs when selected is not a Date.
Suggested Solution:
Implement proper type-checking for the selected value based on its type (string, object, array) before attempting to call getMonth().
Bug:
selectedvalue handling inreact-date-pickercausesgetMonth()errorsDescription:
When using
react-date-pickerin modes likerangeormultiple, selecting a month by tapping on the month caption causes an error. This happens because theselectedvalue can be a string, an object (fromandtoin range mode), or an array (multiple dates). Directly treatingselectedas aDateleads to errors when trying to callgetMonth().Steps to Reproduce:
react-date-pickerinrangeormultiplemode.TypeError: selected.getMonth is not a functionoccurs.Expected Behavior:
getMonth()should only be called on validDateobjects, with proper checks forselectedbeing a string, object, or array.Actual Behavior:
TypeError: selected.getMonth is not a functionoccurs whenselectedis not aDate.Suggested Solution:
Implement proper type-checking for the
selectedvalue based on its type (string,object,array) before attempting to callgetMonth().