Пример #1
0
 /**
  * Returns true if $value is a valid date of the format YYYY-MM-DD
  * If optional $format or $locale is set the date format is checked
  * according to Zend_Date, see Zend_Date::isDate()
  *
  * @param  string|array|\Zend\Date\Date $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value) && !is_array($value) && !$value instanceof ZendDate\Date) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     if ($this->_format !== null || $this->_locale !== null || is_array($value) || $value instanceof Date\Date) {
         if (!ZendDate\Date::isDate($value, $this->_format, $this->_locale)) {
             if ($this->_checkFormat($value) === false) {
                 $this->error(self::FALSEFORMAT);
             } else {
                 $this->error(self::INVALID_DATE);
             }
             return false;
         }
     } else {
         if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value)) {
             $this->_format = 'yyyy-MM-dd';
             $this->error(self::FALSEFORMAT);
             $this->_format = null;
             return false;
         }
         list($year, $month, $day) = sscanf($value, '%d-%d-%d');
         if (!checkdate($month, $day, $year)) {
             $this->error(self::INVALID_DATE);
             return false;
         }
     }
     return true;
 }
Пример #2
0
 /**
  * @ZF-7454
  */
 public function testSetWithoutHourAtDSTChange()
 {
     $this->assertTrue(Date::isDate("23/05/2010", "dd/MM/yyyy", "it_IT"));
     $this->assertTrue(Date::isDate("24/05/2010", "dd/MM/yyyy", "it_IT"));
 }