Ejemplo n.º 1
0
 public function testWarningViolations()
 {
     $one = new DateTime();
     $two = new DateTime();
     $this->assertFalse($one->isValid('0000-00-00 23:59:59'));
     $this->assertFalse($two->isValid('2016-06-06 99:88:77'));
     $this->assertEquals(['date'], $one->getViolations());
     $this->assertEquals(['time'], $two->getViolations());
 }
Ejemplo n.º 2
-1
 /**
  * Validates input.
  *
  * @param mixed $input
  *
  * @return bool
  */
 public function isValid($input = null)
 {
     if ($input === null || $input === '') {
         return false;
     }
     $input = (string) $input;
     PhpDateTime::createFromFormat(static::FORMAT, $input);
     $errors = PhpDateTime::getLastErrors();
     if ($errors['error_count'] > 0) {
         $this->violations[] = 'format';
         return false;
     }
     foreach ($errors['warnings'] as $warning) {
         if ($warning === 'The parsed date was invalid') {
             $this->violations[] = 'date';
         } else {
             if ($warning === 'The parsed time was invalid') {
                 $this->violations[] = 'time';
             } else {
                 $this->violations[] = 'format';
             }
         }
     }
     return !$this->hasViolations();
 }