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
  1. PHPScriptor

    Sunday, February 22, 2009 - 18:42:03

    looks interesting, I’ll have a look at it. Always much trouble with those dates format.

  2. Jason

    Monday, February 23, 2009 - 01:50:20

    Great work Thomas,
    As always, another great contribution.

    Thanks for your effort and expertise.

  3. eol TZ

    Sunday, February 12, 2012 - 07:09:40

    Wow, this post is fastidious, my younger sister is analyzing these things, therefore I am going to tell her.

  4. The Business Card Shop - Online business card store

    Monday, April 2, 2012 - 17:44:00

    Its not my first time to pay a visit this web site, i am browsing this website dailly and
    take good data from here everyday.

Add comment

Fill out the form below to add your own comments

User data




Add your comment