Issues

ZF-2524: Zend_Date::isDate returns false with valid date

Description

I just noticed a strange Zend_Date::isDate behavior that didn't occur before. Have a look at the following code:


if (Zend_Date::isDate('2007-11-14 21:06:36 GMT')) {
    echo 'true';
} else {
    echo 'false';
}

It prints false. What makes everything strange, is that the following piece of code works well.


$x = new Zend_Date('2007-11-14 21:06:36 GMT');
echo $x; // Nov 14, 2007 9:06:36 PM

As I told before, this is a new issue. The last time I tested Zend_Date /trunk (02/Jan/08) it worked without any problem.

Comments

This is not an issue...

API for isDate() says:


     * Checks if the given date is a real date or datepart.
     * Returns false if a expected datepart is missing or a datepart exceeds its possible border.
     * But the check will only be done for the expected dateparts which are given by format.
     * If no format is given the standard dateformat for the actual locale is used.
     * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'

You did not define a format in your example so the standard format from your locale is used. This means the used format differs on the browser or environment settings.

And the input you gave follows no known default format in any locale so the returned "false" is correct.

As wether the class nor the function has been changed in past (since 1.0.2) it must be related to different browser or server settings.

Thanks Thomas for your explanation.

At this point I'm going to ask you an additional information. What about if I don't know input date format and I just want to validate input?

For example, strtotime() is able to accept whatever kind of input that can be mapped as a datetime. Is there any way to achieve this with Zend_Date?

Thanks Thomas for your explanation.

At this point I'm going to ask you an additional information. What about if I don't know input date format and I just want to validate input?

For example, strtotime() is able to accept whatever kind of input that can be mapped as a datetime. Is there any way to achieve this with Zend_Date?

Sorry for the double comment, network problem! :| If you need more details, please have a look at the latest two comments for ZF-2524

Tonight my brain is definitely unlinked! This is the right issue id: ZF-2334

Then you really have a problem...

Because a date in RSS Format is not valid if you need ISO... and an ISO date on the other hand is not valid if you expect ATOM date...

You see where the problem is ? You can't say all dates are valid, because this is not true...

Even dates like "1234-99-55 354:99:99" could be seen as valid in some environments but most people will say that's no date.

If you do not know how the date is formatted then Zend_Date is not the right class for you. You can use Zend_Date_Format and parse the date with it.. but then you will have to decide yourself if the returned date parts are an valid date in your eyes or not.

And related to strtotime... this is the same thing what Zend_Date also does on initiation... You said yourself that you can initiate Zend_Date and the date is accepted like use it with strtotime. But strtotime does not validate the input like Zend_Date::isValid(), it generates a timestamp from the date, exactly like Zend_Date.

Thanks for your answer, Thomas. I'm Sorry, I have one more question.

I had a more deep look at Zend_Date and Zend_Locale and I made a few tests. I basically changed the following line in Zend_Locale



to

as it was when I first tested the class after your default locale fix, and it did the trick! I can use Zend_Date::isDate() to validate against any format... or at least it seems to work. All my tests passed.

I can't understand why you decided to change $_Default default value in a second time, in r7357. I do apologize if you find this question too idiot. I don't have high level "locale" skills. :|

Many environments seem not to have a locale set.

This makes problems when using classes where the locale is detected automatically. In such cases an exception was raised in past, saying that the locale can not be detected.

This made users angry because they were not able to fetch this exception. Don't ask me why... So we decided to add a default locale 'en' as fallback so that no exception is raised anymore in such environments.

So the question is what $format and $locale is before line 4625 in both cases... this is the real difference. And the question why the locale of your environment can not be detected.