/** * test checkDateFormat -> time * expected boolean */ public function testCheckTime() { $this->assertTrue(Format::checkDateFormat('13:10:55', array('date_format' => 'HH:mm:ss', 'locale' => 'de_AT'))); $this->assertTrue(Format::checkDateFormat('11:10:55 am', array('date_format' => 'HH:mm:ss', 'locale' => 'ar_EG'))); $this->assertFalse(Format::checkDateFormat('notime')); $this->assertFalse(Format::checkDateFormat('13:10', array('date_format' => 'HH:mm:ss', 'locale' => 'de_AT'))); $this->assertTrue(Format::checkDateFormat('13', array('date_format' => 'HH:mm', 'locale' => 'de_AT'))); $this->assertFalse(Format::checkDateFormat('00:13', array('date_format' => 'ss:mm:HH', 'locale' => 'de_AT'))); }
/** * 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 (Format::isNumber($value, $this->_options)) { return 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 Format::getTime($value, $this->_options); } else { if (Format::checkDateFormat($value, $this->_options)) { // Detect date or time input return Format::getDate($value, $this->_options); } } } return $value; }
/** * @group ZF-11837 */ public function testCheckDateFormatDoesNotEmitNoticeWhenNoOptionsAreNotProvided() { try { setlocale(LC_ALL, 'en_US'); // test setup Format::setOptions(array('date_format' => 'yyyy-MM-dd')); $this->assertTrue(Format::checkDateFormat('2011-10-21', array())); } catch (\PHPUnit_Framework_Error_Notice $ex) { $this->fail('Zend_Locale_Format::checkDateFormat emitted unexpected E_NOTICE'); } }