Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseDate does not throw error for invalid dates when allowInput #2988

Open
tay1orjones opened this issue Feb 21, 2024 · 1 comment
Open

Comments

@tay1orjones
Copy link

Repro: https://jsfiddle.net/b9jtc1m6/1/

Steps to reproduce

  1. Enter date of 77/77/7777 and hit enter
  2. 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)
@tay1orjones
Copy link
Author

I figured out the issue. The formatting code doesn't guard against values greater than what's specified in the docs.

d: (dateObj: Date, day: string) => {
dateObj.setDate(parseFloat(day));
},

m: (dateObj: Date, month: string) => {
dateObj.setMonth(parseFloat(month) - 1);
},

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant