Closed jackdpeterson closed 7 years ago
Looks like the unit tests need to be updated now to expect the element to barf when it gets garbage rather than allowing junk in that magically and mysteriously fails.
I suppose there's also a broader conversation to be had about the changes that I'm implementing here. In the case of the setFormat() bits, I'm assuming that the min and max validation are to be ran off of the same format as the actual input format. This may be an incorrect approach. Rather, I think I'm going to modify this a little bit where the min and max MUST follow the convention for self::DATETIME_FORMAT = 'Y-m-d\TH:iP'; as was the case with my first pass prior to squashing in various other changes. The benefit of this approach would be that the date is always specified in a consistent manner rather than evaluated based on the then-current format.
Either way, the current implementation has problems and I think the above should be discussed. Locking down to one format for the min / max seems to be the most appropriate choice. Either way, unit tests must be modified.
Branch updated w/ additional unit tests to reflect which scenarios fail. Also fixed one unit test related to the DateTimeLocalElement where an invalid specification was provided that was inconsistent w/ the documentation.
Are there other comments on this PR or can we move this into the next minor release of Zend-Form?
@jackdpeterson Throw an exception is a new behaviour. Can we cover the old and the new behaviour with unit tests to prevent any problems in existing applications / forms?
@froschdesign -- see the changes for the tests folder. I also added a unit tests for specific areas where invalid specifications are provided.
Btw. if the documentation is wrong or a bug is included, then we must fix this. See:
$dateTimeLocal->setAttributes([
'min' => '2010-01-01T00:00:00',
'max' => '2020-01-01T00:00:00',
'step' => '1', // minutes; default step interval is 1 min
]);
$dateTimeLocal->setOptions([
'format' => 'Y-m-d\TH:i',
]);
https://docs.zendframework.com/zend-form/element/date-time-local/#basic-usage
Thanks, @jackdpeterson
Throws an InvalidArgumentException when one attempts to create a DateTime element with a string for min or max that does not conform to the expected \DateTime format.