parseDate does not throw error for invalid dates when allowInput
tay1orjones opened this issue · comments
Repro: https://jsfiddle.net/b9jtc1m6/1/
Steps to reproduce
- Enter date of
77/77/7777
and hit enter - Observe the date is parsed to
07/16/7783
I'm not sure if this is an error in createDateParser
or createDateFormatter
, but this date should result in an "Invalid date provided" because the month m
is not 01-12, and the day d
is not 01 to 31 as specified in the docs.
Your Environment
- flatpickr version used: 4.6.13
- Browser name and version: Chrome 121.0.6167.184 (Official Build) (arm64)
- OS and version: MacOS 13.6 (22G120)
I figured out the issue. The formatting code doesn't guard against values greater than what's specified in the docs.
flatpickr/src/utils/formatting.ts
Lines 92 to 94 in 548330e
flatpickr/src/utils/formatting.ts
Lines 105 to 107 in 548330e
This is due to the behavior of the native date methods:
If a parameter you specify is outside of the expected range, other parameters and the date information in the Date object are updated accordingly. For example, if you specify 15 for
monthValue
, the year is incremented by 1, and 3 is used for month.