ZF-7833: Zend_Date doesn't take into account the options parameter format_type



Zend_Date::setOptions(array('format_type' => 'php')) is no more taken into account for date process.

Following the next exemple, the get method of Zend_Date send back result from ISO format when it should be PHP format as it is asking by the options settings:

Zend_Date::setOptions(array('format_type' => 'php')); Zend_Locale_Format::setOptions(array('locale' => 'en_US', 'fix_date' => true, 'format_type' => 'php')); $today = Zend_Date::now(); $today->setOptions(array('format_type' => 'php')); echo $today->get('m'); // Should send back the month with two digits (PHP format), but send back the minutes (ISO format) echo $today->get('MM'); // Should send back the month with 3 letters and this three times (PHP format), but send back the month with two digits (ISO format)

Seems a major bug as all project based on PHP date format using Zend_Date should break. This problem is not in ZF 1.7.8, but appears in 1.8.0 and is always in 1.9.2.

Actually, I work on a big project, but I cannot upgrade Zend Framework because of this problem.

I hope it will be corrected in next release. Someone get a patch to make it work ?

Best regards, Thomas.


Can not reproduce....

*) toString accepts php and iso format as expected *) get accepts only iso format as expected

Additionally the given example is not correct... gnu defines that "MM" returns 6 letters (2x3) and not 3 letters 3 times...

Feature added in trunk.

Hi !

Thanks a lot, it work great now ! I can go from 1.7.8 to 1.9.2 with the Date.php of the trunk version.

Just a question, what is the difference between toString() and get() method as both send part date in string format (or int) depending locale. In the manuel, it is not saying that PHP Format is not supported by the 'format' type options, should be more explicit maybe. And in Zend 1.7.8, get() method take into account 'php' for format type. But from the next minor release, all will be ok for everyone.

Thanks again. Cheers, Thomas.

p.s: yes, i write my message too fast, your are right, it is 6 letters (2x3)

As you can see by the methods API, toString accepts a type parameter which can be used to define the used format type. The get method does not have this parameter.

This means, that toString was intended to accept different types of inputs, whereas get is a method to get the actual representation by iso only.

Also the default formats for both methods differ for this reason. They have been intended for different purposes even if this is now no longer the case as people have requested features from one to be integrated in the other and reverse.

But in 1.7.8 and earlier version, the get method take into account the option format_type. So 1.78 and earlier was wrong. It is a strong change wich should be mentionned in documentation for migration. As all people working with zend_date in php format in 1.7.8 will have to migrate code for 1.8+ versions.

New problem: I find a new bug, wich appear only with the Date.php available in the trunk directory (version Id: Date.php 18093 2009-09-13 11:35:01Z thomas) with the patch you have done for my previous problem. With the original 1.9.2 Date.php, this bug in not here, so I guess it comes from your modifications.

IsLater and IsEarlier method for zend_date object send strange return value. Exemple:

Zend_Loader::loadClass('Zend_Date'); Zend_Date::setOptions(array('format_type' => 'php')); // This bug appears only when php format is actived, with the trunck Date.php version Id: Date.php 18093 2009-09-13 11:35:01Z thomas $date1 = new Zend_Date(); $date2 = clone $date1; $date2->add(1, Zend_Date::DAY);

echo "Is date1 earlier than date2:".$date1->isEarlier($date2, Zend_Date::DATES)."
"; // return false echo "Is date2 earlier than date1:".$date2->isEarlier($date1, Zend_Date::DATES)."
"; // return false echo "Is date1 later than date2:".$date1->isLater($date2, Zend_Date::DATES)."
"; // return true echo "Is date2 later than que date1:".$date2->isLater($date1, Zend_Date::DATES)."
"; // return true

Results are not possible. So maybe you need to check better the correction made previously as it impacts "isEarlier" and "isLater" method which rely on "compare" / "_calculate" methods.

Thanks again. Cheers, Thomas.