Wednesday
8
July
2009

Zend_Date support for complete localized dates

Today I added a new feature within Zend_Date which allows to use complete localized dates.

Until Zend Framework 1.8 you had eighter to create your own format manually, or to concat the output manually to get a string like “13.April.2009 10:20:10”.

Actually this formats are very common and as with Zend Framework 1.9 they are supported.
In sum there are 5 variants of this format.

*) Zend_Date::DATETIME
*) Zend_Date::DATETIME_FULL
*) Zend_Date::DATETIME_LONG
*) Zend_Date::DATETIME_MEDIUM
*) Zend_Date::DATETIME_SHORT

As you may have mentioned these new formats are nearly equal to existing ones.
For a date we have Zend_Date::DATE_FULL and for a time representation Zend_Date::TIME_FULL.

In the background DATETIME is defined as a concation of Date and Time. But as we are in a localized environment you have to note that it depends on the locale of the date or the time part is written first and the other part afterwards.

Let’s take a look into a short example:

$date = new Zend_Date();
print $date->toString(Zend_Date::DATETIME_MEDIUM);

This will output 08.07.2009 20:30:33 within the german locale.
But you have to note that the output you will get is still dependent on your locale.

Other new features are on the road and are only waiting for response to be integrated into core.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Friday
20
February
2009

Validation and formatting of Dates

Hy fellows,

when you are validating Input with Zend_Validate_Date then you can now use the Date constants as validation format. This allows you to validate against localized formats even when you don’t know how the format looks like.

As example:
In past you had to know the format or evaluate it from Zend_Locale like shown:

$locale = 'de';
$format = Zend_Locale::getTranslation('date', array('gregorian', 'medium'), $locale);
$valid = new Zend_Validate_Date($format, $locale);

Now you can simply use the constants from Zend_Date to simplify the validation:

$valid = new Zend_Validate_Date(Zend_Date::DATE_MEDIUM, 'de');

This works with all available date constants.

Also Zend_Date itself can now handle the format constants within the methods which did not support it. You can use them within isDate() which, until now, only accepted fixed ISO format. And you can use them also within the toString() method.

$date = new Zend_Date($myinput);
print $date->toString(Zend_Date::RSS);

While adding this new features I also did some rework of Zend_Date itself. It is now about 200 lines reduced without change to the functionallity. And the parsing is faster than in past.

As always, this new feature is available with the next minor release which will be 1.8.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top