The date format of form elements are not taken into account when a form is validated with min and max attribute. This is because the LessThan and GreaterThan validators compare strings.
When I set the format for my Date element to 'd-m-Y' and set max attribute to "01-01-2001"
my input "10-01-2000" will return an error:
10-01-2000 < 01-01-2001 returns false
Those validators are not meant for date comparisons.
Exactly. But they are used inside /Zend/Form/Element/DateTime as validators:
Oh, that is clearly a bug then.
This is a hard one, as the return value of getValue() is what is passed to the validator chain. Since by default, that's the formatted string, comparisons will likely not work as expected; ideally, we should be comparing the timestamps.
The only way I can think of to manage this is to create a custom Input type for date and/or time types which will ensure the timestamp is used. However, this will also likely require changes to the various date and time elements so that getValue() returns a DateTime object.
As such, I'm postponing the issue to 2.3.0, as we need time to work out a reasonable solution.
Possibly related to #4510 (comment).
Doing a little more investigation today. More problematic than expected:
About the only way I see this working at this point is if you do one of the following:
Eventually, we will want to make GreaterThan and LessThan work with DateTime and other built-ins. However, I think the crux of the problem, as reported here, has more to do with the DateTime form element, and requires a different approach, as outlined above.
@maxnuf @localheinz @ThaDafinser @DASPRiD -- thoughts?
Using the DateTimeFormatter does help, but only for the date formats that the \DateTime parser understands. mm-dd-yyyy won't work.
I think an EarlierThan and LaterThan Validator that cast values to DateTime based on a specified format is a more clear approach.
Postponing to 2.4.0, as this will require a fair number of additions and changes to accomplish.
Removing milestone, as nobody provided a PR for this issue so far.
This issue has been closed as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html