zendframework / zf1

This project reached its end-of-life on 2016-09-28. Contains conversion of ZF1 subversion repo to git, from version 15234 forward, and only containing master and release-1.12 branches and 1.12 tags.
https://framework.zend.com/blog/2016-06-28-zf1-eol.html
BSD 3-Clause "New" or "Revised" License
357 stars 801 forks source link

Unexpected behavior of Zend_Validate_Date #508

Open tomasfejfar opened 9 years ago

tomasfejfar commented 9 years ago
$validator = new \Zend_Validate_Date('Y-m-d');
var_dump($validator->isValid('2015-05-01|DEFAULT'));
$validator = new \Zend_Validate_Date();
var_dump($validator->isValid('2015-05-01|DEFAULT'));

Expected: false, false Actual: true, false

Problem seem to lie in \Zend_Date::isDate('2015-05-01|DEFAULT', 'Y-m-d', null); // true being called inside the validator. And the call https://github.com/zendframework/zf1/blob/master/library/Zend/Locale/Format.php#L908 called inside there. That ignores everything except numbers (meaning it strips the |DEFAULT).

Is that feature or bug? In my opinion it's a bug.

froschdesign commented 9 years ago

Is that feature or bug?

It's not supported. :wink:

In my opinion, Zend_Date is deprecated. The extraction of the date parts is ugly. (For more information please see #207.)

tomasfejfar commented 9 years ago

Can it be properly marked as deprecated? It is not ATM AFAIK https://github.com/zendframework/zf1/blob/master/library/Zend/Date.php - there is no "deprecated" string in the whole class.

tomasfejfar commented 9 years ago

Or better it should not work with unsupported params. Validation passing is the worst way to deal with it, because it's really hard to find what is the actual problem.

froschdesign commented 9 years ago

there is no "deprecated" string in the whole class.

I wrote: "In my opinion…"

it's really hard to find what is the actual problem

This is true for all Zend_Date and Zend_Locale classes.

tomasfejfar commented 9 years ago

So the resolution is practically "Known issue" -> "Won't fix"? Or can I do something to make this more developer friendly?

froschdesign commented 9 years ago

So the resolution is practically "Known issue" -> "Won't fix"?

The issue is still open!

Or can I do something to make this more developer friendly?

Any suggestion or idea is welcome.

tomasfejfar commented 9 years ago

What about having it properly deprecated? There is no point in trying to fix it for currently outdated PHP version (5.2). Everywhere else you can use \DateTime. I would even go so far as to rewrite the internals to use DateTime where possible. A project I'm working on is bound to stay on ZF1 for some time so it still makes sense to future-proof ZF1. I am not sure whether new ZF releases have to support <5.3 PHP versions now that 5.2 is outdated and discouraged.

froschdesign commented 9 years ago

I would even go so far as to rewrite the internals to use DateTime where possible.

The idea is not new, but this would result in different behaviours, date outputs and validation results.

My advice to you: Don't do that, it's too many work and a very very hard way. (I have tried it.)

We need a solution/migration path from Zend_Date to DateTime or ZF2.

froschdesign commented 9 years ago

@akrabat Any comments or ideas?

froschdesign commented 9 years ago

Another problem: we can not upgrade to a newer CLDR version.