4.x
DateField has options for setMinDate() and setMaxDate(). Whether a date is valid or not is tested by comparing dates using strtotime(). However, almost all the other date logic in the class uses IntlDateFormatter to parse dates which results in inconsistent behaviour.
Create an input:
DateField::create('DateOfBirth', 'Date of birth')
->setHTML5(false)
->setDateFormat('dd/MM/yyyy')
->setMinDate('01-01-1900')
Enter a date like 01-01-70. DateField::validate() doesn鈥檛 think this is an invalid date, as PHP鈥檚 strtotime() (incorrectly) treats 70 as 1970.
Enter a date like 01-01-70. DateField::validate() doesn鈥檛 think this is an invalid date, as PHP鈥檚 strtotime() (incorrectly) treats 70 as 1970.
Am I missing something? That seems legitimate to me
I can see an argument for assuming that 2-digit years are 19xx, but it鈥檚 fairly ambiguous behaviour: https://3v4l.org/CbW8Z.
Running with the example of 01-01-70, the logic in frontendToInternal() which normalises the submitted value is all based around IntlDateFormatter, which treats it as the year 70. It then passes it to strtotime() to check min/max date which treats it as 1970 instead.
Most helpful comment
I can see an argument for assuming that 2-digit years are 19xx, but it鈥檚 fairly ambiguous behaviour: https://3v4l.org/CbW8Z.
Running with the example of
01-01-70, the logic infrontendToInternal()which normalises the submitted value is all based aroundIntlDateFormatter, which treats it as the year 70. It then passes it tostrtotime()to check min/max date which treats it as 1970 instead.