public static function checkDate($date, $format = '') { if (empty($format)) { if (Zend_Registry::isRegistered('date_format')) { $format = Zend_Registry::get('date_format'); } else { $format = self::MYSQL_DATE_FORMAT; } } return Zend_Locale_Format::checkDateFormat($date, array('date_format' => $format)); }
/** * Defined by Zend_Filter_Interface * * Normalizes the given input * * @param string $value Value to normalized * @return string|array The normalized value */ public function filter($value) { if (Zend_Locale_Format::isNumber($value, $this->_options)) { return Zend_Locale_Format::getNumber($value, $this->_options); } else { if ($this->_options['date_format'] === null && strpos($value, ':') !== false) { // Special case, no date format specified, detect time input return Zend_Locale_Format::getTime($value, $this->_options); } else { if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) { // Detect date or time input return Zend_Locale_Format::getDate($value, $this->_options); } } } return $value; }
/** * test checkDateFormat -> time * expected boolean */ public function testCheckTime() { $this->assertTrue( Zend_Locale_Format::checkDateFormat('13:10:55', array('date_format' => 'HH:mm:ss', 'locale' => 'de_AT'))); $this->assertTrue( Zend_Locale_Format::checkDateFormat('11:10:55 am', array('date_format' => 'HH:mm:ss', 'locale' => 'ar_EG'))); $this->assertFalse(Zend_Locale_Format::checkDateFormat('notime')); $this->assertFalse(Zend_Locale_Format::checkDateFormat('13:10', array('date_format' => 'HH:mm:ss', 'locale' => 'de_AT'))); $this->assertFalse(Zend_Locale_Format::checkDateFormat('13', array('date_format' => 'HH:mm', 'locale' => 'de_AT'))); $this->assertFalse(Zend_Locale_Format::checkDateFormat('00:13', array('date_format' => 'ss:mm:HH', 'locale' => 'de_AT'))); }
/** * @group ZF-11837 */ public function testCheckDateFormatDoesNotEmitNoticeWhenNoOptionsAreNotProvided() { try { setlocale(LC_ALL, 'en_US'); // test setup Zend_Locale_Format::setOptions(array('date_format' => 'yyyy-MM-dd')); $this->assertTrue(Zend_Locale_Format::checkDateFormat('2011-10-21', array())); } catch (PHPUnit_Framework_Error_Notice $ex) { $this->fail('Zend_Locale_Format::checkDateFormat emitted unexpected E_NOTICE'); } }
/** * test checkDateFormat -> time * expected boolean */ public function testCheckTime() { $this->assertTrue(Zend_Locale_Format::checkDateFormat('13:10:55', array('date_format' => 'HH:mm:ss', 'locale' => 'de_AT')), "true expected"); $this->assertTrue(Zend_Locale_Format::checkDateFormat('11:10:55 am', array('date_format' => 'HH:mm:ss', 'locale' => 'ar_EG')), "true expected"); $this->assertFalse(Zend_Locale_Format::checkDateFormat('notime'), "false expected"); }
/** * Defined by Zend_Filter_Interface * * Normalizes the given input * * @param string $value Value to normalized * @return string|array The normalized value */ public function filter($value) { if (Zend_Locale_Format::isNumber($value, $this->_options)) { return Zend_Locale_Format::getNumber($value, $this->_options); // if (($this->_options['precision'] === 0) && Zend_Locale_Format::isInteger($value, $this->_options)) { // Detect integer // return Zend_Locale_Format::getInteger($value, $this->_options); // } else if (($this->_options['precision'] === null) && Zend_Locale_Format::isFloat($value, $this->_options)) { // Detect float // return Zend_Locale_Format::getFloat($value, $this->_options); // } else if (Zend_Locale_Format::isNumber($value, $this->_options)) { // Detect all other numbers // return Zend_Locale_Format::getNumber($value, $this->_options); } else { if ($this->_options['date_format'] === null && strpos($value, ':') !== false) { // Special case, no date format specified, detect time input return Zend_Locale_Format::getTime($value, $this->_options); } else { if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) { // Detect date or time input return Zend_Locale_Format::getDate($value, $this->_options); } } } return $value; }