/** * Ensures that the validator can handle different dateformats from locale * * @see http://framework.zend.com/issues/browse/ZF-2003 * @return void */ public function testUseLocaleFormat() { $valuesExpected = array('10.01.2008' => true, '32.02.2008' => false, '20 April 2008' => true, '1 Jul 2008' => true, '2008/20/03' => false, '99/99/2000' => false, 0 => false, 999999999999 => false, 'Jan 1 2007' => false); foreach ($valuesExpected as $input => $result) { $this->assertEquals($result, $this->_validator->setLocale('de_AT')->isValid($input), "'{$input}' expected to be " . ($result ? '' : 'in') . 'valid'); } }
/** * Ensures that the validator can handle different dateformats from locale * * @see http://framework.zend.com/issues/browse/ZF-2003 * @return void */ public function testUseLocaleFormat() { $errorOccurredLocal = false; set_error_handler(array($this, 'errorHandlerIgnore')); $valuesExpected = array('10.01.2008' => true, '32.02.2008' => false, '20 April 2008' => true, '1 Jul 2008' => true, '2008/20/03' => false, '99/99/2000' => false, 0 => false, 999999999999 => false, 'Jan 1 2007' => false); foreach ($valuesExpected as $input => $resultExpected) { $resultActual = $this->_validator->setLocale('de_AT')->isValid($input); if (!$this->_errorOccurred) { $this->assertEquals($resultExpected, $resultActual, "'{$input}' expected to be " . ($resultExpected ? '' : 'in') . 'valid'); } else { $errorOccurredLocal = true; } $this->_errorOccurred = false; } restore_error_handler(); if ($errorOccurredLocal) { $this->markTestSkipped('Affected by bug described in ZF-2789'); } }
/** * Sets locale and updated input format automatically. * @param Zend_Locale $locale */ public function setLocale($locale = null) { parent::setLocale($locale); if ($locale instanceof Zend_Locale) { $dateFormat = $this->getDateFormat($locale->getLanguage()); $inputPattern = $this->getDatePattern($locale->getLanguage()); } else { $dateFormat = $this->getDateFormat($locale); $inputPattern = $this->getDatePattern($locale); } $this->setFormat($dateFormat); $this->setInputPattern($inputPattern); }